7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule TapEventPlugin
10
+ * @flow
11
*/
12
13
'use strict';
21
var isStartish = EventPluginUtils.isStartish;
22
var isEndish = EventPluginUtils.isEndish;
23
24
+import type {DispatchConfig} from 'ReactSyntheticEventType';
25
+import type {PluginModule} from 'PluginModuleType';
26
+import type {ReactInstance} from 'ReactInstanceType';
27
+import type {TopLevelTypes} from 'EventConstants';
28
+
29
+/**
30
+ * We are extending the Flow 'Touch' declaration to enable using bracket
31
+ * notation to access properties.
32
+ * Without this adjustment Flow throws
33
+ * "Indexable signature not found in Touch".
34
+ * See https://github.com/facebook/flow/issues/1323
35
+ */
36
+type TouchPropertyKey =
37
+ 'clientX' |
38
+ 'clientY' |
39
+ 'pageX' |
40
+ 'pageY';
41
+
42
+declare class _Touch extends Touch {
43
+ [key: TouchPropertyKey]: number;
44
+}
45
+
46
+type AxisCoordinateData = {
47
+ page: TouchPropertyKey,
48
+ client: TouchPropertyKey,
49
+ envScroll: 'currentPageScrollLeft' | 'currentPageScrollTop',
50
+};
51
+
52
+type AxisType = {
53
+ x: AxisCoordinateData,
54
+ y: AxisCoordinateData,
55
+};
56
+
57
+type CoordinatesType = {
58
+ x: number,
59
+ y: number,
60
+};
61
+
62
/**
63
* Number of pixels that are tolerated in between a `touchStart` and `touchEnd`
64
* in order to still be considered a 'tap' event.
65
*/
66
var tapMoveThreshold = 10;
28
-var startCoords = {x: null, y: null};
67
+var startCoords: CoordinatesType = {x: 0, y: 0};
68
30
-var Axis = {
69
+var Axis: AxisType = {
70
x: {page: 'pageX', client: 'clientX', envScroll: 'currentPageScrollLeft'},
71
y: {page: 'pageY', client: 'clientY', envScroll: 'currentPageScrollTop'},
72
};
73
35
-function getAxisCoordOfEvent(axis, nativeEvent) {
74
+function getAxisCoordOfEvent(
75
+ axis: AxisCoordinateData,
76
+ nativeEvent: _Touch,
77
+): number {
78
var singleTouch = TouchEventUtils.extractSingleTouch(nativeEvent);
79
if (singleTouch) {
80
return singleTouch[axis.page];
84
nativeEvent[axis.client] + ViewportMetrics[axis.envScroll];
85
}
86
45
-function getDistance(coords, nativeEvent) {
87
+function getDistance(
88
+ coords: CoordinatesType,
89
+ nativeEvent: _Touch,
90
+): number {
91
var pageX = getAxisCoordOfEvent(Axis.x, nativeEvent);
92
var pageY = getAxisCoordOfEvent(Axis.y, nativeEvent);
93
return Math.pow(
109
'topMouseUp',
110
].concat(touchEvents);
111
67
-var eventTypes = {
112
+var eventTypes: DispatchConfig = {
113
touchTap: {
114
phasedRegistrationNames: {
115
bubbled: 'onTouchTap',
123
var usedTouchTime = 0;
124
var TOUCH_DELAY = 1000;
125
81
-var TapEventPlugin = {
126
+var TapEventPlugin: PluginModule<_Touch> = {
127
128
tapMoveThreshold: tapMoveThreshold,
129
130
eventTypes: eventTypes,
131
132
extractEvents: function(
88
- topLevelType,
89
- targetInst,
90
- nativeEvent,
91
- nativeEventTarget
133
+ topLevelType: TopLevelTypes,
134
+ targetInst: ReactInstance,
135
+ nativeEvent: _Touch,
136
+ nativeEventTarget: EventTarget,
137
) {
138
if (!isStartish(topLevelType) && !isEndish(topLevelType)) {
139
return null;