Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81158 views
1
/**
2
* Copyright 2013-2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule TouchEventUtils
10
*/
11
12
var TouchEventUtils = {
13
/**
14
* Utility function for common case of extracting out the primary touch from a
15
* touch event.
16
* - `touchEnd` events usually do not have the `touches` property.
17
* http://stackoverflow.com/questions/3666929/
18
* mobile-sarai-touchend-event-not-firing-when-last-touch-is-removed
19
*
20
* @param {Event} nativeEvent Native event that may or may not be a touch.
21
* @return {TouchesObject?} an object with pageX and pageY or null.
22
*/
23
extractSingleTouch: function(nativeEvent) {
24
var touches = nativeEvent.touches;
25
var changedTouches = nativeEvent.changedTouches;
26
var hasTouches = touches && touches.length > 0;
27
var hasChangedTouches = changedTouches && changedTouches.length > 0;
28
29
return !hasTouches && hasChangedTouches ? changedTouches[0] :
30
hasTouches ? touches[0] :
31
nativeEvent;
32
}
33
};
34
35
module.exports = TouchEventUtils;
36
37