@office-iss/react-native-win32 0.69.0 → 0.70.0-preview.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/.eslintrc.js +0 -1
  2. package/.flowconfig +5 -1
  3. package/CHANGELOG.json +194 -32
  4. package/CHANGELOG.md +79 -19
  5. package/IntegrationTests/AsyncStorageTest.js +20 -4
  6. package/IntegrationTests/BUCK +2 -2
  7. package/IntegrationTests/LayoutEventsTest.js +4 -1
  8. package/IntegrationTests/{launchWebSocketServer.command → launchWebSocketServer.sh} +3 -9
  9. package/Libraries/Alert/Alert.js +18 -4
  10. package/Libraries/Alert/Alert.win32.js +2 -0
  11. package/Libraries/Alert/NativeAlertManager.js +1 -0
  12. package/Libraries/Animated/Animated.js +2 -2
  13. package/Libraries/Animated/AnimatedEvent.js +7 -4
  14. package/Libraries/Animated/AnimatedImplementation.js +17 -3
  15. package/Libraries/Animated/AnimatedMock.js +7 -2
  16. package/Libraries/Animated/NativeAnimatedHelper.js +220 -95
  17. package/Libraries/Animated/NativeAnimatedModule.js +3 -0
  18. package/Libraries/Animated/NativeAnimatedTurboModule.js +3 -0
  19. package/Libraries/Animated/animations/SpringAnimation.js +3 -3
  20. package/Libraries/Animated/animations/TimingAnimation.js +3 -3
  21. package/Libraries/Animated/createAnimatedComponent.js +8 -1
  22. package/Libraries/Animated/nodes/AnimatedAddition.js +3 -1
  23. package/Libraries/Animated/nodes/AnimatedColor.js +50 -29
  24. package/Libraries/Animated/nodes/AnimatedDiffClamp.js +3 -1
  25. package/Libraries/Animated/nodes/AnimatedDivision.js +3 -1
  26. package/Libraries/Animated/nodes/AnimatedInterpolation.js +22 -21
  27. package/Libraries/Animated/nodes/AnimatedModulo.js +3 -1
  28. package/Libraries/Animated/nodes/AnimatedMultiplication.js +3 -2
  29. package/Libraries/Animated/nodes/AnimatedProps.js +20 -12
  30. package/Libraries/Animated/nodes/AnimatedStyle.js +19 -16
  31. package/Libraries/Animated/nodes/AnimatedSubtraction.js +3 -1
  32. package/Libraries/Animated/nodes/AnimatedTransform.js +5 -5
  33. package/Libraries/Animated/nodes/AnimatedValue.js +14 -5
  34. package/Libraries/Animated/nodes/AnimatedValueXY.js +28 -1
  35. package/Libraries/Animated/useAnimatedProps.js +1 -0
  36. package/Libraries/AppState/AppState.js +0 -32
  37. package/Libraries/BatchedBridge/MessageQueue.js +21 -15
  38. package/Libraries/BatchedBridge/NativeModules.js +3 -4
  39. package/Libraries/Blob/FileReader.js +0 -6
  40. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +0 -20
  41. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.win32.js +0 -20
  42. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +4 -0
  43. package/Libraries/Components/Keyboard/Keyboard.js +0 -11
  44. package/Libraries/Components/Pressable/Pressable.js +2 -0
  45. package/Libraries/Components/Pressable/Pressable.win32.js +2 -0
  46. package/Libraries/Components/SafeAreaView/RCTSafeAreaViewNativeComponent.js +1 -3
  47. package/Libraries/Components/SafeAreaView/SafeAreaView.js +3 -30
  48. package/Libraries/Components/SafeAreaView/SafeAreaView.win32.js +4 -32
  49. package/Libraries/Components/ScrollView/ScrollView.js +13 -11
  50. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +5 -3
  51. package/Libraries/Components/StatusBar/StatusBar.js +10 -7
  52. package/Libraries/Components/TextInput/InputAccessoryView.js +14 -13
  53. package/Libraries/Components/TextInput/TextInput.js +12 -2
  54. package/Libraries/Components/Touchable/PooledClass.js +16 -4
  55. package/Libraries/Components/Touchable/Touchable.js +50 -1
  56. package/Libraries/Components/Touchable/Touchable.win32.js +972 -0
  57. package/Libraries/Components/Touchable/TouchableNativeFeedback.js +6 -2
  58. package/Libraries/Components/View/ReactNativeStyleAttributes.js +0 -7
  59. package/Libraries/Components/View/ViewPropTypes.js +3 -8
  60. package/Libraries/Components/View/ViewPropTypes.win32.js +3 -8
  61. package/Libraries/Core/ExceptionsManager.js +2 -0
  62. package/Libraries/Core/ReactNativeVersion.js +2 -2
  63. package/Libraries/Core/Timers/JSTimers.js +2 -2
  64. package/Libraries/Core/polyfillPromise.js +0 -32
  65. package/Libraries/Core/setUpBatchedBridge.js +5 -1
  66. package/Libraries/Core/setUpPerformance.js +1 -1
  67. package/Libraries/EventEmitter/NativeEventEmitter.js +0 -13
  68. package/Libraries/Image/AssetSourceResolver.js +2 -2
  69. package/Libraries/Image/Image.android.js +5 -3
  70. package/Libraries/Image/Image.ios.js +6 -3
  71. package/Libraries/Image/Image.win32.js +6 -3
  72. package/Libraries/Image/ImageSource.js +7 -5
  73. package/Libraries/Inspector/ElementBox.js +2 -2
  74. package/Libraries/Inspector/NetworkOverlay.js +13 -8
  75. package/Libraries/Interaction/PanResponder.js +16 -14
  76. package/Libraries/Linking/Linking.js +0 -11
  77. package/Libraries/Lists/FlatList.js +3 -2
  78. package/Libraries/Lists/SectionList.js +2 -0
  79. package/Libraries/Lists/ViewabilityHelper.js +7 -3
  80. package/Libraries/Lists/VirtualizeUtils.js +33 -20
  81. package/Libraries/Lists/VirtualizedList.js +93 -47
  82. package/Libraries/Lists/VirtualizedListContext.js +1 -0
  83. package/Libraries/Lists/VirtualizedSectionList.js +14 -9
  84. package/Libraries/Lists/__tests__/VirtualizeUtils-test.js +19 -18
  85. package/Libraries/Lists/__tests__/VirtualizedList-test.js +10 -6
  86. package/Libraries/LogBox/Data/LogBoxData.js +1 -1
  87. package/Libraries/LogBox/Data/parseLogBoxLog.js +1 -1
  88. package/Libraries/LogBox/LogBox.js +3 -1
  89. package/Libraries/LogBox/UI/AnsiHighlight.js +2 -0
  90. package/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js +3 -0
  91. package/Libraries/LogBox/UI/LogBoxInspectorSourceMapStatus.js +0 -3
  92. package/Libraries/LogBox/UI/LogBoxInspectorStackFrames.js +8 -3
  93. package/Libraries/NativeComponent/BaseViewConfig.android.js +9 -18
  94. package/Libraries/NativeComponent/BaseViewConfig.ios.js +26 -12
  95. package/Libraries/NativeComponent/BaseViewConfig.win32.js +26 -12
  96. package/Libraries/Network/XMLHttpRequest.js +9 -11
  97. package/Libraries/Performance/PureComponentDebug.js +1 -0
  98. package/Libraries/PermissionsAndroid/NativePermissionsAndroid.js +9 -1
  99. package/Libraries/PermissionsAndroid/PermissionsAndroid.js +16 -0
  100. package/Libraries/Pressability/Pressability.js +26 -16
  101. package/Libraries/Pressability/Pressability.win32.js +26 -16
  102. package/Libraries/Promise.js +0 -1
  103. package/Libraries/ReactNative/AppRegistry.js +16 -13
  104. package/Libraries/ReactNative/BridgelessUIManager.js +2 -0
  105. package/Libraries/ReactNative/PaperUIManager.js +9 -9
  106. package/Libraries/ReactNative/PaperUIManager.win32.js +7 -8
  107. package/Libraries/ReactNative/ReactNativeFeatureFlags.js +12 -0
  108. package/Libraries/ReactNative/ReactNativeRuntimeDiagnostics.js +68 -0
  109. package/Libraries/ReactNative/getNativeComponentAttributes.js +6 -7
  110. package/Libraries/ReactNative/renderApplication.js +1 -1
  111. package/Libraries/Renderer/implementations/ReactFabric-dev.js +4443 -3615
  112. package/Libraries/Renderer/implementations/ReactFabric-prod.js +1496 -1170
  113. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +1694 -1356
  114. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +4439 -3588
  115. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +1583 -1249
  116. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +1719 -1372
  117. package/Libraries/Storage/AsyncStorage.js +7 -1
  118. package/Libraries/StyleSheet/PlatformColorValueTypes.ios.js +8 -0
  119. package/Libraries/StyleSheet/flattenStyle.js +1 -1
  120. package/Libraries/StyleSheet/processTransform.js +2 -0
  121. package/Libraries/StyleSheet/splitLayoutProps.js +2 -0
  122. package/Libraries/Text/Text.js +15 -7
  123. package/Libraries/Types/CoreEventTypes.js +137 -11
  124. package/Libraries/Types/CoreEventTypes.win32.js +147 -22
  125. package/Libraries/Utilities/Dimensions.js +0 -13
  126. package/Libraries/Utilities/Dimensions.win32.js +0 -9
  127. package/Libraries/Utilities/HMRClient.js +3 -3
  128. package/Libraries/Utilities/Platform.ios.js +0 -7
  129. package/Libraries/Utilities/ReactNativeTestTools.js +3 -1
  130. package/Libraries/Utilities/codegenNativeCommands.js +11 -2
  131. package/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js +2 -0
  132. package/Libraries/Utilities/stringifySafe.js +3 -1
  133. package/Libraries/Utilities/truncate.js +1 -1
  134. package/Libraries/Utilities/verifyComponentAttributeEquivalence.js +2 -2
  135. package/Libraries/Vibration/Vibration.js +1 -1
  136. package/Libraries/WebSocket/WebSocket.js +1 -0
  137. package/Libraries/vendor/emitter/EventEmitter.js +105 -12
  138. package/Libraries/vendor/emitter/__flowtests__/EventEmitter-flowtest.js +73 -117
  139. package/flow/JSITimerInternalType.js +30 -0
  140. package/jest/assetFileTransformer.js +3 -2
  141. package/jest/setup.js +4 -0
  142. package/jest.config.js +0 -1
  143. package/overrides.json +23 -16
  144. package/package.json +23 -24
  145. package/rntypes/index.d.ts +0 -1
  146. package/src/rntypes/index.d.ts +0 -1
  147. package/Libraries/vendor/emitter/EventSubscription.js +0 -19
  148. package/Libraries/vendor/emitter/_EmitterSubscription.js +0 -62
  149. package/Libraries/vendor/emitter/_EventEmitter.js +0 -184
  150. package/Libraries/vendor/emitter/_EventSubscription.js +0 -45
  151. package/Libraries/vendor/emitter/_EventSubscriptionVendor.js +0 -108
  152. package/jest/preprocessor.js +0 -40
  153. package/jest/preprocessor_DO_NOT_USE.js +0 -122
  154. package/src/Libraries/Lists/__tests__/__snapshots__/VirtualizeUtils-test.js.snap +0 -3
@@ -0,0 +1,972 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow
8
+ * @format
9
+ */
10
+
11
+ import * as React from 'react';
12
+ import BoundingDimensions from './BoundingDimensions';
13
+ import Platform from '../../Utilities/Platform';
14
+ import Position from './Position';
15
+ import UIManager from '../../ReactNative/UIManager';
16
+ import SoundManager from '../Sound/SoundManager';
17
+
18
+ import {PressabilityDebugView} from '../../Pressability/PressabilityDebug';
19
+
20
+ import type {ColorValue} from '../../StyleSheet/StyleSheet';
21
+ import type {EdgeInsetsProp} from '../../StyleSheet/EdgeInsetsPropType';
22
+ import type {PressEvent} from '../../Types/CoreEventTypes';
23
+
24
+ const extractSingleTouch = (nativeEvent: {
25
+ +altKey: ?boolean,
26
+ +button: ?number,
27
+ +changedTouches: $ReadOnlyArray<PressEvent['nativeEvent']>,
28
+ +ctrlKey: ?boolean,
29
+ +force?: number,
30
+ +identifier: number,
31
+ +locationX: number,
32
+ +locationY: number,
33
+ +metaKey: ?boolean,
34
+ +pageX: number,
35
+ +pageY: number,
36
+ +shiftKey: ?boolean,
37
+ +target: ?number,
38
+ +timestamp: number,
39
+ +touches: $ReadOnlyArray<PressEvent['nativeEvent']>,
40
+ }) => {
41
+ const touches = nativeEvent.touches;
42
+ const changedTouches = nativeEvent.changedTouches;
43
+ const hasTouches = touches && touches.length > 0;
44
+ const hasChangedTouches = changedTouches && changedTouches.length > 0;
45
+
46
+ return !hasTouches && hasChangedTouches
47
+ ? changedTouches[0]
48
+ : hasTouches
49
+ ? touches[0]
50
+ : nativeEvent;
51
+ };
52
+
53
+ /**
54
+ * `Touchable`: Taps done right.
55
+ *
56
+ * You hook your `ResponderEventPlugin` events into `Touchable`. `Touchable`
57
+ * will measure time/geometry and tells you when to give feedback to the user.
58
+ *
59
+ * ====================== Touchable Tutorial ===============================
60
+ * The `Touchable` mixin helps you handle the "press" interaction. It analyzes
61
+ * the geometry of elements, and observes when another responder (scroll view
62
+ * etc) has stolen the touch lock. It notifies your component when it should
63
+ * give feedback to the user. (bouncing/highlighting/unhighlighting).
64
+ *
65
+ * - When a touch was activated (typically you highlight)
66
+ * - When a touch was deactivated (typically you unhighlight)
67
+ * - When a touch was "pressed" - a touch ended while still within the geometry
68
+ * of the element, and no other element (like scroller) has "stolen" touch
69
+ * lock ("responder") (Typically you bounce the element).
70
+ *
71
+ * A good tap interaction isn't as simple as you might think. There should be a
72
+ * slight delay before showing a highlight when starting a touch. If a
73
+ * subsequent touch move exceeds the boundary of the element, it should
74
+ * unhighlight, but if that same touch is brought back within the boundary, it
75
+ * should rehighlight again. A touch can move in and out of that boundary
76
+ * several times, each time toggling highlighting, but a "press" is only
77
+ * triggered if that touch ends while within the element's boundary and no
78
+ * scroller (or anything else) has stolen the lock on touches.
79
+ *
80
+ * To create a new type of component that handles interaction using the
81
+ * `Touchable` mixin, do the following:
82
+ *
83
+ * - Initialize the `Touchable` state.
84
+ *
85
+ * getInitialState: function() {
86
+ * return merge(this.touchableGetInitialState(), yourComponentState);
87
+ * }
88
+ *
89
+ * - Choose the rendered component who's touches should start the interactive
90
+ * sequence. On that rendered node, forward all `Touchable` responder
91
+ * handlers. You can choose any rendered node you like. Choose a node whose
92
+ * hit target you'd like to instigate the interaction sequence:
93
+ *
94
+ * // In render function:
95
+ * return (
96
+ * <View
97
+ * onStartShouldSetResponder={this.touchableHandleStartShouldSetResponder}
98
+ * onResponderTerminationRequest={this.touchableHandleResponderTerminationRequest}
99
+ * onResponderGrant={this.touchableHandleResponderGrant}
100
+ * onResponderMove={this.touchableHandleResponderMove}
101
+ * onResponderRelease={this.touchableHandleResponderRelease}
102
+ * onResponderTerminate={this.touchableHandleResponderTerminate}>
103
+ * <View>
104
+ * Even though the hit detection/interactions are triggered by the
105
+ * wrapping (typically larger) node, we usually end up implementing
106
+ * custom logic that highlights this inner one.
107
+ * </View>
108
+ * </View>
109
+ * );
110
+ *
111
+ * - You may set up your own handlers for each of these events, so long as you
112
+ * also invoke the `touchable*` handlers inside of your custom handler.
113
+ *
114
+ * - Implement the handlers on your component class in order to provide
115
+ * feedback to the user. See documentation for each of these class methods
116
+ * that you should implement.
117
+ *
118
+ * touchableHandlePress: function() {
119
+ * this.performBounceAnimation(); // or whatever you want to do.
120
+ * },
121
+ * touchableHandleActivePressIn: function() {
122
+ * this.beginHighlighting(...); // Whatever you like to convey activation
123
+ * },
124
+ * touchableHandleActivePressOut: function() {
125
+ * this.endHighlighting(...); // Whatever you like to convey deactivation
126
+ * },
127
+ *
128
+ * - There are more advanced methods you can implement (see documentation below):
129
+ * touchableGetHighlightDelayMS: function() {
130
+ * return 20;
131
+ * }
132
+ * // In practice, *always* use a predeclared constant (conserve memory).
133
+ * touchableGetPressRectOffset: function() {
134
+ * return {top: 20, left: 20, right: 20, bottom: 100};
135
+ * }
136
+ */
137
+
138
+ /**
139
+ * Touchable states.
140
+ */
141
+
142
+ const States = {
143
+ NOT_RESPONDER: 'NOT_RESPONDER', // Not the responder
144
+ RESPONDER_INACTIVE_PRESS_IN: 'RESPONDER_INACTIVE_PRESS_IN', // Responder, inactive, in the `PressRect`
145
+ RESPONDER_INACTIVE_PRESS_OUT: 'RESPONDER_INACTIVE_PRESS_OUT', // Responder, inactive, out of `PressRect`
146
+ RESPONDER_ACTIVE_PRESS_IN: 'RESPONDER_ACTIVE_PRESS_IN', // Responder, active, in the `PressRect`
147
+ RESPONDER_ACTIVE_PRESS_OUT: 'RESPONDER_ACTIVE_PRESS_OUT', // Responder, active, out of `PressRect`
148
+ RESPONDER_ACTIVE_LONG_PRESS_IN: 'RESPONDER_ACTIVE_LONG_PRESS_IN', // Responder, active, in the `PressRect`, after long press threshold
149
+ RESPONDER_ACTIVE_LONG_PRESS_OUT: 'RESPONDER_ACTIVE_LONG_PRESS_OUT', // Responder, active, out of `PressRect`, after long press threshold
150
+ ERROR: 'ERROR',
151
+ };
152
+
153
+ type State =
154
+ | typeof States.NOT_RESPONDER
155
+ | typeof States.RESPONDER_INACTIVE_PRESS_IN
156
+ | typeof States.RESPONDER_INACTIVE_PRESS_OUT
157
+ | typeof States.RESPONDER_ACTIVE_PRESS_IN
158
+ | typeof States.RESPONDER_ACTIVE_PRESS_OUT
159
+ | typeof States.RESPONDER_ACTIVE_LONG_PRESS_IN
160
+ | typeof States.RESPONDER_ACTIVE_LONG_PRESS_OUT
161
+ | typeof States.ERROR;
162
+
163
+ /*
164
+ * Quick lookup map for states that are considered to be "active"
165
+ */
166
+
167
+ const baseStatesConditions = {
168
+ NOT_RESPONDER: false,
169
+ RESPONDER_INACTIVE_PRESS_IN: false,
170
+ RESPONDER_INACTIVE_PRESS_OUT: false,
171
+ RESPONDER_ACTIVE_PRESS_IN: false,
172
+ RESPONDER_ACTIVE_PRESS_OUT: false,
173
+ RESPONDER_ACTIVE_LONG_PRESS_IN: false,
174
+ RESPONDER_ACTIVE_LONG_PRESS_OUT: false,
175
+ ERROR: false,
176
+ };
177
+
178
+ const IsActive = {
179
+ ...baseStatesConditions,
180
+ RESPONDER_ACTIVE_PRESS_OUT: true,
181
+ RESPONDER_ACTIVE_PRESS_IN: true,
182
+ };
183
+
184
+ /**
185
+ * Quick lookup for states that are considered to be "pressing" and are
186
+ * therefore eligible to result in a "selection" if the press stops.
187
+ */
188
+ const IsPressingIn = {
189
+ ...baseStatesConditions,
190
+ RESPONDER_INACTIVE_PRESS_IN: true,
191
+ RESPONDER_ACTIVE_PRESS_IN: true,
192
+ RESPONDER_ACTIVE_LONG_PRESS_IN: true,
193
+ };
194
+
195
+ const IsLongPressingIn = {
196
+ ...baseStatesConditions,
197
+ RESPONDER_ACTIVE_LONG_PRESS_IN: true,
198
+ };
199
+
200
+ /**
201
+ * Inputs to the state machine.
202
+ */
203
+ const Signals = {
204
+ DELAY: 'DELAY',
205
+ RESPONDER_GRANT: 'RESPONDER_GRANT',
206
+ RESPONDER_RELEASE: 'RESPONDER_RELEASE',
207
+ RESPONDER_TERMINATED: 'RESPONDER_TERMINATED',
208
+ ENTER_PRESS_RECT: 'ENTER_PRESS_RECT',
209
+ LEAVE_PRESS_RECT: 'LEAVE_PRESS_RECT',
210
+ LONG_PRESS_DETECTED: 'LONG_PRESS_DETECTED',
211
+ };
212
+
213
+ type Signal =
214
+ | typeof Signals.DELAY
215
+ | typeof Signals.RESPONDER_GRANT
216
+ | typeof Signals.RESPONDER_RELEASE
217
+ | typeof Signals.RESPONDER_TERMINATED
218
+ | typeof Signals.ENTER_PRESS_RECT
219
+ | typeof Signals.LEAVE_PRESS_RECT
220
+ | typeof Signals.LONG_PRESS_DETECTED;
221
+
222
+ /**
223
+ * Mapping from States x Signals => States
224
+ */
225
+ const Transitions = {
226
+ NOT_RESPONDER: {
227
+ DELAY: States.ERROR,
228
+ RESPONDER_GRANT: States.RESPONDER_INACTIVE_PRESS_IN,
229
+ RESPONDER_RELEASE: States.ERROR,
230
+ RESPONDER_TERMINATED: States.ERROR,
231
+ ENTER_PRESS_RECT: States.ERROR,
232
+ LEAVE_PRESS_RECT: States.ERROR,
233
+ LONG_PRESS_DETECTED: States.ERROR,
234
+ },
235
+ RESPONDER_INACTIVE_PRESS_IN: {
236
+ DELAY: States.RESPONDER_ACTIVE_PRESS_IN,
237
+ RESPONDER_GRANT: States.ERROR,
238
+ RESPONDER_RELEASE: States.NOT_RESPONDER,
239
+ RESPONDER_TERMINATED: States.NOT_RESPONDER,
240
+ ENTER_PRESS_RECT: States.RESPONDER_INACTIVE_PRESS_IN,
241
+ LEAVE_PRESS_RECT: States.RESPONDER_INACTIVE_PRESS_OUT,
242
+ LONG_PRESS_DETECTED: States.ERROR,
243
+ },
244
+ RESPONDER_INACTIVE_PRESS_OUT: {
245
+ DELAY: States.RESPONDER_ACTIVE_PRESS_OUT,
246
+ RESPONDER_GRANT: States.ERROR,
247
+ RESPONDER_RELEASE: States.NOT_RESPONDER,
248
+ RESPONDER_TERMINATED: States.NOT_RESPONDER,
249
+ ENTER_PRESS_RECT: States.RESPONDER_INACTIVE_PRESS_IN,
250
+ LEAVE_PRESS_RECT: States.RESPONDER_INACTIVE_PRESS_OUT,
251
+ LONG_PRESS_DETECTED: States.ERROR,
252
+ },
253
+ RESPONDER_ACTIVE_PRESS_IN: {
254
+ DELAY: States.ERROR,
255
+ RESPONDER_GRANT: States.ERROR,
256
+ RESPONDER_RELEASE: States.NOT_RESPONDER,
257
+ RESPONDER_TERMINATED: States.NOT_RESPONDER,
258
+ ENTER_PRESS_RECT: States.RESPONDER_ACTIVE_PRESS_IN,
259
+ LEAVE_PRESS_RECT: States.RESPONDER_ACTIVE_PRESS_OUT,
260
+ LONG_PRESS_DETECTED: States.RESPONDER_ACTIVE_LONG_PRESS_IN,
261
+ },
262
+ RESPONDER_ACTIVE_PRESS_OUT: {
263
+ DELAY: States.ERROR,
264
+ RESPONDER_GRANT: States.ERROR,
265
+ RESPONDER_RELEASE: States.NOT_RESPONDER,
266
+ RESPONDER_TERMINATED: States.NOT_RESPONDER,
267
+ ENTER_PRESS_RECT: States.RESPONDER_ACTIVE_PRESS_IN,
268
+ LEAVE_PRESS_RECT: States.RESPONDER_ACTIVE_PRESS_OUT,
269
+ LONG_PRESS_DETECTED: States.ERROR,
270
+ },
271
+ RESPONDER_ACTIVE_LONG_PRESS_IN: {
272
+ DELAY: States.ERROR,
273
+ RESPONDER_GRANT: States.ERROR,
274
+ RESPONDER_RELEASE: States.NOT_RESPONDER,
275
+ RESPONDER_TERMINATED: States.NOT_RESPONDER,
276
+ ENTER_PRESS_RECT: States.RESPONDER_ACTIVE_LONG_PRESS_IN,
277
+ LEAVE_PRESS_RECT: States.RESPONDER_ACTIVE_LONG_PRESS_OUT,
278
+ LONG_PRESS_DETECTED: States.RESPONDER_ACTIVE_LONG_PRESS_IN,
279
+ },
280
+ RESPONDER_ACTIVE_LONG_PRESS_OUT: {
281
+ DELAY: States.ERROR,
282
+ RESPONDER_GRANT: States.ERROR,
283
+ RESPONDER_RELEASE: States.NOT_RESPONDER,
284
+ RESPONDER_TERMINATED: States.NOT_RESPONDER,
285
+ ENTER_PRESS_RECT: States.RESPONDER_ACTIVE_LONG_PRESS_IN,
286
+ LEAVE_PRESS_RECT: States.RESPONDER_ACTIVE_LONG_PRESS_OUT,
287
+ LONG_PRESS_DETECTED: States.ERROR,
288
+ },
289
+ error: {
290
+ DELAY: States.NOT_RESPONDER,
291
+ RESPONDER_GRANT: States.RESPONDER_INACTIVE_PRESS_IN,
292
+ RESPONDER_RELEASE: States.NOT_RESPONDER,
293
+ RESPONDER_TERMINATED: States.NOT_RESPONDER,
294
+ ENTER_PRESS_RECT: States.NOT_RESPONDER,
295
+ LEAVE_PRESS_RECT: States.NOT_RESPONDER,
296
+ LONG_PRESS_DETECTED: States.NOT_RESPONDER,
297
+ },
298
+ };
299
+
300
+ // ==== Typical Constants for integrating into UI components ====
301
+ // var HIT_EXPAND_PX = 20;
302
+ // var HIT_VERT_OFFSET_PX = 10;
303
+ const HIGHLIGHT_DELAY_MS = 130;
304
+
305
+ const PRESS_EXPAND_PX = 20;
306
+
307
+ const LONG_PRESS_THRESHOLD = 500;
308
+
309
+ const LONG_PRESS_DELAY_MS = LONG_PRESS_THRESHOLD - HIGHLIGHT_DELAY_MS;
310
+
311
+ const LONG_PRESS_ALLOWED_MOVEMENT = 10;
312
+
313
+ // Default amount "active" region protrudes beyond box
314
+
315
+ /**
316
+ * By convention, methods prefixed with underscores are meant to be @private,
317
+ * and not @protected. Mixers shouldn't access them - not even to provide them
318
+ * as callback handlers.
319
+ *
320
+ *
321
+ * ========== Geometry =========
322
+ * `Touchable` only assumes that there exists a `HitRect` node. The `PressRect`
323
+ * is an abstract box that is extended beyond the `HitRect`.
324
+ *
325
+ * +--------------------------+
326
+ * | | - "Start" events in `HitRect` cause `HitRect`
327
+ * | +--------------------+ | to become the responder.
328
+ * | | +--------------+ | | - `HitRect` is typically expanded around
329
+ * | | | | | | the `VisualRect`, but shifted downward.
330
+ * | | | VisualRect | | | - After pressing down, after some delay,
331
+ * | | | | | | and before letting up, the Visual React
332
+ * | | +--------------+ | | will become "active". This makes it eligible
333
+ * | | HitRect | | for being highlighted (so long as the
334
+ * | +--------------------+ | press remains in the `PressRect`).
335
+ * | PressRect o |
336
+ * +----------------------|---+
337
+ * Out Region |
338
+ * +-----+ This gap between the `HitRect` and
339
+ * `PressRect` allows a touch to move far away
340
+ * from the original hit rect, and remain
341
+ * highlighted, and eligible for a "Press".
342
+ * Customize this via
343
+ * `touchableGetPressRectOffset()`.
344
+ *
345
+ *
346
+ *
347
+ * ======= State Machine =======
348
+ *
349
+ * +-------------+ <---+ RESPONDER_RELEASE
350
+ * |NOT_RESPONDER|
351
+ * +-------------+ <---+ RESPONDER_TERMINATED
352
+ * +
353
+ * | RESPONDER_GRANT (HitRect)
354
+ * v
355
+ * +---------------------------+ DELAY +-------------------------+ T + DELAY +------------------------------+
356
+ * |RESPONDER_INACTIVE_PRESS_IN|+-------->|RESPONDER_ACTIVE_PRESS_IN| +------------> |RESPONDER_ACTIVE_LONG_PRESS_IN|
357
+ * +---------------------------+ +-------------------------+ +------------------------------+
358
+ * + ^ + ^ + ^
359
+ * |LEAVE_ |ENTER_ |LEAVE_ |ENTER_ |LEAVE_ |ENTER_
360
+ * |PRESS_RECT |PRESS_RECT |PRESS_RECT |PRESS_RECT |PRESS_RECT |PRESS_RECT
361
+ * | | | | | |
362
+ * v + v + v +
363
+ * +----------------------------+ DELAY +--------------------------+ +-------------------------------+
364
+ * |RESPONDER_INACTIVE_PRESS_OUT|+------->|RESPONDER_ACTIVE_PRESS_OUT| |RESPONDER_ACTIVE_LONG_PRESS_OUT|
365
+ * +----------------------------+ +--------------------------+ +-------------------------------+
366
+ *
367
+ * T + DELAY => LONG_PRESS_DELAY_MS + DELAY
368
+ *
369
+ * Not drawn are the side effects of each transition. The most important side
370
+ * effect is the `touchableHandlePress` abstract method invocation that occurs
371
+ * when a responder is released while in either of the "Press" states.
372
+ *
373
+ * The other important side effects are the highlight abstract method
374
+ * invocations (internal callbacks) to be implemented by the mixer.
375
+ *
376
+ *
377
+ * @lends Touchable.prototype
378
+ */
379
+ const TouchableMixin = {
380
+ componentDidMount: function () {
381
+ if (!Platform.isTV) {
382
+ return;
383
+ }
384
+ },
385
+
386
+ /**
387
+ * Clear all timeouts on unmount
388
+ */
389
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
390
+ * Flow's LTI update could not be added via codemod */
391
+ componentWillUnmount: function () {
392
+ this.touchableDelayTimeout && clearTimeout(this.touchableDelayTimeout);
393
+ this.longPressDelayTimeout && clearTimeout(this.longPressDelayTimeout);
394
+ this.pressOutDelayTimeout && clearTimeout(this.pressOutDelayTimeout);
395
+ },
396
+
397
+ /**
398
+ * It's prefer that mixins determine state in this way, having the class
399
+ * explicitly mix the state in the one and only `getInitialState` method.
400
+ *
401
+ * @return {object} State object to be placed inside of
402
+ * `this.state.touchable`.
403
+ */
404
+ touchableGetInitialState: function (): $TEMPORARY$object<{|
405
+ touchable: $TEMPORARY$object<{|responderID: null, touchState: void|}>,
406
+ |}> {
407
+ return {
408
+ touchable: {touchState: undefined, responderID: null},
409
+ };
410
+ },
411
+
412
+ // ==== Hooks to Gesture Responder system ====
413
+ /**
414
+ * Must return true if embedded in a native platform scroll view.
415
+ */
416
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
417
+ * Flow's LTI update could not be added via codemod */
418
+ touchableHandleResponderTerminationRequest: function (): any {
419
+ return !this.props.rejectResponderTermination;
420
+ },
421
+
422
+ /**
423
+ * Must return true to start the process of `Touchable`.
424
+ */
425
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
426
+ * Flow's LTI update could not be added via codemod */
427
+ touchableHandleStartShouldSetResponder: function (): any {
428
+ return !this.props.disabled;
429
+ },
430
+
431
+ /**
432
+ * Return true to cancel press on long press.
433
+ */
434
+ touchableLongPressCancelsPress: function (): boolean {
435
+ return true;
436
+ },
437
+
438
+ /**
439
+ * Place as callback for a DOM element's `onResponderGrant` event.
440
+ * @param {SyntheticEvent} e Synthetic event from event system.
441
+ *
442
+ */
443
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
444
+ * Flow's LTI update could not be added via codemod */
445
+ touchableHandleResponderGrant: function (e: PressEvent) {
446
+ const dispatchID = e.currentTarget;
447
+ // Since e is used in a callback invoked on another event loop
448
+ // (as in setTimeout etc), we need to call e.persist() on the
449
+ // event to make sure it doesn't get reused in the event object pool.
450
+ e.persist();
451
+
452
+ this.pressOutDelayTimeout && clearTimeout(this.pressOutDelayTimeout);
453
+ this.pressOutDelayTimeout = null;
454
+
455
+ this.state.touchable.touchState = States.NOT_RESPONDER;
456
+ this.state.touchable.responderID = dispatchID;
457
+ this._receiveSignal(Signals.RESPONDER_GRANT, e);
458
+ let delayMS =
459
+ this.touchableGetHighlightDelayMS !== undefined
460
+ ? Math.max(this.touchableGetHighlightDelayMS(), 0)
461
+ : HIGHLIGHT_DELAY_MS;
462
+ delayMS = isNaN(delayMS) ? HIGHLIGHT_DELAY_MS : delayMS;
463
+ if (delayMS !== 0) {
464
+ this.touchableDelayTimeout = setTimeout(
465
+ this._handleDelay.bind(this, e),
466
+ delayMS,
467
+ );
468
+ } else {
469
+ this._handleDelay(e);
470
+ }
471
+
472
+ let longDelayMS =
473
+ this.touchableGetLongPressDelayMS !== undefined
474
+ ? Math.max(this.touchableGetLongPressDelayMS(), 10)
475
+ : LONG_PRESS_DELAY_MS;
476
+ longDelayMS = isNaN(longDelayMS) ? LONG_PRESS_DELAY_MS : longDelayMS;
477
+ this.longPressDelayTimeout = setTimeout(
478
+ this._handleLongDelay.bind(this, e),
479
+ longDelayMS + delayMS,
480
+ );
481
+ },
482
+
483
+ /**
484
+ * Place as callback for a DOM element's `onResponderRelease` event.
485
+ */
486
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
487
+ * Flow's LTI update could not be added via codemod */
488
+ touchableHandleResponderRelease: function (e: PressEvent) {
489
+ this.pressInLocation = null;
490
+ this._receiveSignal(Signals.RESPONDER_RELEASE, e);
491
+ },
492
+
493
+ /**
494
+ * Place as callback for a DOM element's `onResponderTerminate` event.
495
+ */
496
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
497
+ * Flow's LTI update could not be added via codemod */
498
+ touchableHandleResponderTerminate: function (e: PressEvent) {
499
+ this.pressInLocation = null;
500
+ this._receiveSignal(Signals.RESPONDER_TERMINATED, e);
501
+ },
502
+
503
+ /**
504
+ * Place as callback for a DOM element's `onResponderMove` event.
505
+ */
506
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
507
+ * Flow's LTI update could not be added via codemod */
508
+ touchableHandleResponderMove: function (e: PressEvent) {
509
+ // Measurement may not have returned yet.
510
+ if (!this.state.touchable.positionOnActivate) {
511
+ return;
512
+ }
513
+
514
+ const positionOnActivate = this.state.touchable.positionOnActivate;
515
+ const dimensionsOnActivate = this.state.touchable.dimensionsOnActivate;
516
+ const pressRectOffset = this.touchableGetPressRectOffset
517
+ ? this.touchableGetPressRectOffset()
518
+ : {
519
+ left: PRESS_EXPAND_PX,
520
+ right: PRESS_EXPAND_PX,
521
+ top: PRESS_EXPAND_PX,
522
+ bottom: PRESS_EXPAND_PX,
523
+ };
524
+
525
+ let pressExpandLeft = pressRectOffset.left;
526
+ let pressExpandTop = pressRectOffset.top;
527
+ let pressExpandRight = pressRectOffset.right;
528
+ let pressExpandBottom = pressRectOffset.bottom;
529
+
530
+ const hitSlop = this.touchableGetHitSlop
531
+ ? this.touchableGetHitSlop()
532
+ : null;
533
+
534
+ if (hitSlop) {
535
+ pressExpandLeft += hitSlop.left || 0;
536
+ pressExpandTop += hitSlop.top || 0;
537
+ pressExpandRight += hitSlop.right || 0;
538
+ pressExpandBottom += hitSlop.bottom || 0;
539
+ }
540
+
541
+ const touch = extractSingleTouch(e.nativeEvent);
542
+ const pageX = touch && touch.pageX;
543
+ const pageY = touch && touch.pageY;
544
+
545
+ if (this.pressInLocation) {
546
+ const movedDistance = this._getDistanceBetweenPoints(
547
+ pageX,
548
+ pageY,
549
+ this.pressInLocation.pageX,
550
+ this.pressInLocation.pageY,
551
+ );
552
+ if (movedDistance > LONG_PRESS_ALLOWED_MOVEMENT) {
553
+ this._cancelLongPressDelayTimeout();
554
+ }
555
+ }
556
+
557
+ const isTouchWithinActive =
558
+ pageX > positionOnActivate.left - pressExpandLeft &&
559
+ pageY > positionOnActivate.top - pressExpandTop &&
560
+ pageX <
561
+ positionOnActivate.left +
562
+ dimensionsOnActivate.width +
563
+ pressExpandRight &&
564
+ pageY <
565
+ positionOnActivate.top +
566
+ dimensionsOnActivate.height +
567
+ pressExpandBottom;
568
+ if (isTouchWithinActive) {
569
+ const prevState = this.state.touchable.touchState;
570
+ this._receiveSignal(Signals.ENTER_PRESS_RECT, e);
571
+ const curState = this.state.touchable.touchState;
572
+ if (
573
+ curState === States.RESPONDER_INACTIVE_PRESS_IN &&
574
+ prevState !== States.RESPONDER_INACTIVE_PRESS_IN
575
+ ) {
576
+ // fix for t7967420
577
+ this._cancelLongPressDelayTimeout();
578
+ }
579
+ } else {
580
+ this._cancelLongPressDelayTimeout();
581
+ this._receiveSignal(Signals.LEAVE_PRESS_RECT, e);
582
+ }
583
+ },
584
+
585
+ /**
586
+ * Invoked when the item receives focus. Mixers might override this to
587
+ * visually distinguish the `VisualRect` so that the user knows that it
588
+ * currently has the focus. Most platforms only support a single element being
589
+ * focused at a time, in which case there may have been a previously focused
590
+ * element that was blurred just prior to this. This can be overridden when
591
+ * using `Touchable.Mixin.withoutDefaultFocusAndBlur`.
592
+ */
593
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
594
+ * Flow's LTI update could not be added via codemod */
595
+ touchableHandleFocus: function (e: Event) {
596
+ this.props.onFocus && this.props.onFocus(e);
597
+ },
598
+
599
+ /**
600
+ * Invoked when the item loses focus. Mixers might override this to
601
+ * visually distinguish the `VisualRect` so that the user knows that it
602
+ * no longer has focus. Most platforms only support a single element being
603
+ * focused at a time, in which case the focus may have moved to another.
604
+ * This can be overridden when using
605
+ * `Touchable.Mixin.withoutDefaultFocusAndBlur`.
606
+ */
607
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
608
+ * Flow's LTI update could not be added via codemod */
609
+ touchableHandleBlur: function (e: Event) {
610
+ this.props.onBlur && this.props.onBlur(e);
611
+ },
612
+
613
+ // ==== Abstract Application Callbacks ====
614
+
615
+ /**
616
+ * Invoked when the item should be highlighted. Mixers should implement this
617
+ * to visually distinguish the `VisualRect` so that the user knows that
618
+ * releasing a touch will result in a "selection" (analog to click).
619
+ *
620
+ * @abstract
621
+ * touchableHandleActivePressIn: function,
622
+ */
623
+
624
+ /**
625
+ * Invoked when the item is "active" (in that it is still eligible to become
626
+ * a "select") but the touch has left the `PressRect`. Usually the mixer will
627
+ * want to unhighlight the `VisualRect`. If the user (while pressing) moves
628
+ * back into the `PressRect` `touchableHandleActivePressIn` will be invoked
629
+ * again and the mixer should probably highlight the `VisualRect` again. This
630
+ * event will not fire on an `touchEnd/mouseUp` event, only move events while
631
+ * the user is depressing the mouse/touch.
632
+ *
633
+ * @abstract
634
+ * touchableHandleActivePressOut: function
635
+ */
636
+
637
+ /**
638
+ * Invoked when the item is "selected" - meaning the interaction ended by
639
+ * letting up while the item was either in the state
640
+ * `RESPONDER_ACTIVE_PRESS_IN` or `RESPONDER_INACTIVE_PRESS_IN`.
641
+ *
642
+ * @abstract
643
+ * touchableHandlePress: function
644
+ */
645
+
646
+ /**
647
+ * Invoked when the item is long pressed - meaning the interaction ended by
648
+ * letting up while the item was in `RESPONDER_ACTIVE_LONG_PRESS_IN`. If
649
+ * `touchableHandleLongPress` is *not* provided, `touchableHandlePress` will
650
+ * be called as it normally is. If `touchableHandleLongPress` is provided, by
651
+ * default any `touchableHandlePress` callback will not be invoked. To
652
+ * override this default behavior, override `touchableLongPressCancelsPress`
653
+ * to return false. As a result, `touchableHandlePress` will be called when
654
+ * lifting up, even if `touchableHandleLongPress` has also been called.
655
+ *
656
+ * @abstract
657
+ * touchableHandleLongPress: function
658
+ */
659
+
660
+ /**
661
+ * Returns the number of millis to wait before triggering a highlight.
662
+ *
663
+ * @abstract
664
+ * touchableGetHighlightDelayMS: function
665
+ */
666
+
667
+ /**
668
+ * Returns the amount to extend the `HitRect` into the `PressRect`. Positive
669
+ * numbers mean the size expands outwards.
670
+ *
671
+ * @abstract
672
+ * touchableGetPressRectOffset: function
673
+ */
674
+
675
+ // ==== Internal Logic ====
676
+
677
+ /**
678
+ * Measures the `HitRect` node on activation. The Bounding rectangle is with
679
+ * respect to viewport - not page, so adding the `pageXOffset/pageYOffset`
680
+ * should result in points that are in the same coordinate system as an
681
+ * event's `globalX/globalY` data values.
682
+ *
683
+ * - Consider caching this for the lifetime of the component, or possibly
684
+ * being able to share this cache between any `ScrollMap` view.
685
+ *
686
+ * @sideeffects
687
+ * @private
688
+ */
689
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
690
+ * Flow's LTI update could not be added via codemod */
691
+ _remeasureMetricsOnActivation: function () {
692
+ const responderID = this.state.touchable.responderID;
693
+ if (responderID == null) {
694
+ return;
695
+ }
696
+
697
+ if (typeof responderID === 'number') {
698
+ UIManager.measure(responderID, this._handleQueryLayout);
699
+ } else {
700
+ responderID.measure(this._handleQueryLayout);
701
+ }
702
+ },
703
+
704
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
705
+ * Flow's LTI update could not be added via codemod */
706
+ _handleQueryLayout: function (
707
+ l: number,
708
+ t: number,
709
+ w: number,
710
+ h: number,
711
+ globalX: number,
712
+ globalY: number,
713
+ ) {
714
+ //don't do anything UIManager failed to measure node
715
+ if (!l && !t && !w && !h && !globalX && !globalY) {
716
+ return;
717
+ }
718
+ this.state.touchable.positionOnActivate &&
719
+ Position.release(this.state.touchable.positionOnActivate);
720
+ this.state.touchable.dimensionsOnActivate &&
721
+ BoundingDimensions.release(this.state.touchable.dimensionsOnActivate);
722
+ this.state.touchable.positionOnActivate = Position.getPooled(
723
+ globalX,
724
+ globalY,
725
+ );
726
+ this.state.touchable.dimensionsOnActivate = BoundingDimensions.getPooled(
727
+ w,
728
+ h,
729
+ );
730
+ },
731
+
732
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
733
+ * Flow's LTI update could not be added via codemod */
734
+ _handleDelay: function (e: PressEvent) {
735
+ this.touchableDelayTimeout = null;
736
+ this._receiveSignal(Signals.DELAY, e);
737
+ },
738
+
739
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
740
+ * Flow's LTI update could not be added via codemod */
741
+ _handleLongDelay: function (e: PressEvent) {
742
+ this.longPressDelayTimeout = null;
743
+ const curState = this.state.touchable.touchState;
744
+ if (
745
+ curState === States.RESPONDER_ACTIVE_PRESS_IN ||
746
+ curState === States.RESPONDER_ACTIVE_LONG_PRESS_IN
747
+ ) {
748
+ this._receiveSignal(Signals.LONG_PRESS_DETECTED, e);
749
+ }
750
+ },
751
+
752
+ /**
753
+ * Receives a state machine signal, performs side effects of the transition
754
+ * and stores the new state. Validates the transition as well.
755
+ *
756
+ * @param {Signals} signal State machine signal.
757
+ * @throws Error if invalid state transition or unrecognized signal.
758
+ * @sideeffects
759
+ */
760
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
761
+ * Flow's LTI update could not be added via codemod */
762
+ _receiveSignal: function (signal: Signal, e: PressEvent) {
763
+ const responderID = this.state.touchable.responderID;
764
+ const curState = this.state.touchable.touchState;
765
+ const nextState = Transitions[curState] && Transitions[curState][signal];
766
+ if (!responderID && signal === Signals.RESPONDER_RELEASE) {
767
+ return;
768
+ }
769
+ if (!nextState) {
770
+ throw new Error(
771
+ 'Unrecognized signal `' +
772
+ signal +
773
+ '` or state `' +
774
+ curState +
775
+ '` for Touchable responder `' +
776
+ typeof this.state.touchable.responderID ===
777
+ 'number'
778
+ ? this.state.touchable.responderID
779
+ : 'host component' + '`',
780
+ );
781
+ }
782
+ if (nextState === States.ERROR) {
783
+ throw new Error(
784
+ 'Touchable cannot transition from `' +
785
+ curState +
786
+ '` to `' +
787
+ signal +
788
+ '` for responder `' +
789
+ typeof this.state.touchable.responderID ===
790
+ 'number'
791
+ ? this.state.touchable.responderID
792
+ : '<<host component>>' + '`',
793
+ );
794
+ }
795
+ if (curState !== nextState) {
796
+ this._performSideEffectsForTransition(curState, nextState, signal, e);
797
+ this.state.touchable.touchState = nextState;
798
+ }
799
+ },
800
+
801
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
802
+ * Flow's LTI update could not be added via codemod */
803
+ _cancelLongPressDelayTimeout: function () {
804
+ this.longPressDelayTimeout && clearTimeout(this.longPressDelayTimeout);
805
+ this.longPressDelayTimeout = null;
806
+ },
807
+
808
+ _isHighlight: function (state: State): boolean {
809
+ return (
810
+ state === States.RESPONDER_ACTIVE_PRESS_IN ||
811
+ state === States.RESPONDER_ACTIVE_LONG_PRESS_IN
812
+ );
813
+ },
814
+
815
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
816
+ * Flow's LTI update could not be added via codemod */
817
+ _savePressInLocation: function (e: PressEvent) {
818
+ const touch = extractSingleTouch(e.nativeEvent);
819
+ const pageX = touch && touch.pageX;
820
+ const pageY = touch && touch.pageY;
821
+ const locationX = touch && touch.locationX;
822
+ const locationY = touch && touch.locationY;
823
+ this.pressInLocation = {pageX, pageY, locationX, locationY};
824
+ },
825
+
826
+ _getDistanceBetweenPoints: function (
827
+ aX: number,
828
+ aY: number,
829
+ bX: number,
830
+ bY: number,
831
+ ): number {
832
+ const deltaX = aX - bX;
833
+ const deltaY = aY - bY;
834
+ return Math.sqrt(deltaX * deltaX + deltaY * deltaY);
835
+ },
836
+
837
+ /**
838
+ * Will perform a transition between touchable states, and identify any
839
+ * highlighting or unhighlighting that must be performed for this particular
840
+ * transition.
841
+ *
842
+ * @param {States} curState Current Touchable state.
843
+ * @param {States} nextState Next Touchable state.
844
+ * @param {Signal} signal Signal that triggered the transition.
845
+ * @param {Event} e Native event.
846
+ * @sideeffects
847
+ */
848
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
849
+ * Flow's LTI update could not be added via codemod */
850
+ _performSideEffectsForTransition: function (
851
+ curState: State,
852
+ nextState: State,
853
+ signal: Signal,
854
+ e: PressEvent,
855
+ ) {
856
+ const curIsHighlight = this._isHighlight(curState);
857
+ const newIsHighlight = this._isHighlight(nextState);
858
+
859
+ const isFinalSignal =
860
+ signal === Signals.RESPONDER_TERMINATED ||
861
+ signal === Signals.RESPONDER_RELEASE;
862
+
863
+ if (isFinalSignal) {
864
+ this._cancelLongPressDelayTimeout();
865
+ }
866
+
867
+ const isInitialTransition =
868
+ curState === States.NOT_RESPONDER &&
869
+ nextState === States.RESPONDER_INACTIVE_PRESS_IN;
870
+
871
+ const isActiveTransition = !IsActive[curState] && IsActive[nextState];
872
+ if (isInitialTransition || isActiveTransition) {
873
+ this._remeasureMetricsOnActivation();
874
+ }
875
+
876
+ if (IsPressingIn[curState] && signal === Signals.LONG_PRESS_DETECTED) {
877
+ this.touchableHandleLongPress && this.touchableHandleLongPress(e);
878
+ }
879
+
880
+ if (newIsHighlight && !curIsHighlight) {
881
+ this._startHighlight(e);
882
+ } else if (!newIsHighlight && curIsHighlight) {
883
+ this._endHighlight(e);
884
+ }
885
+
886
+ if (IsPressingIn[curState] && signal === Signals.RESPONDER_RELEASE) {
887
+ const hasLongPressHandler = !!this.props.onLongPress;
888
+ const pressIsLongButStillCallOnPress =
889
+ IsLongPressingIn[curState] && // We *are* long pressing.. // But either has no long handler
890
+ (!hasLongPressHandler || !this.touchableLongPressCancelsPress()); // or we're told to ignore it.
891
+
892
+ const shouldInvokePress =
893
+ !IsLongPressingIn[curState] || pressIsLongButStillCallOnPress;
894
+ if (shouldInvokePress && this.touchableHandlePress) {
895
+ if (!newIsHighlight && !curIsHighlight) {
896
+ // we never highlighted because of delay, but we should highlight now
897
+ this._startHighlight(e);
898
+ this._endHighlight(e);
899
+ }
900
+ if (Platform.OS === 'android' && !this.props.touchSoundDisabled) {
901
+ SoundManager.playTouchSound();
902
+ }
903
+ this.touchableHandlePress(e);
904
+ }
905
+ }
906
+
907
+ this.touchableDelayTimeout && clearTimeout(this.touchableDelayTimeout);
908
+ this.touchableDelayTimeout = null;
909
+ },
910
+
911
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
912
+ * Flow's LTI update could not be added via codemod */
913
+ _startHighlight: function (e: PressEvent) {
914
+ this._savePressInLocation(e);
915
+ this.touchableHandleActivePressIn && this.touchableHandleActivePressIn(e);
916
+ },
917
+
918
+ /* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
919
+ * Flow's LTI update could not be added via codemod */
920
+ _endHighlight: function (e: PressEvent) {
921
+ if (this.touchableHandleActivePressOut) {
922
+ if (
923
+ this.touchableGetPressOutDelayMS &&
924
+ this.touchableGetPressOutDelayMS()
925
+ ) {
926
+ this.pressOutDelayTimeout = setTimeout(() => {
927
+ this.touchableHandleActivePressOut(e);
928
+ }, this.touchableGetPressOutDelayMS());
929
+ } else {
930
+ this.touchableHandleActivePressOut(e);
931
+ }
932
+ }
933
+ },
934
+
935
+ withoutDefaultFocusAndBlur: ({}: $TEMPORARY$object<{||}>),
936
+ };
937
+
938
+ /**
939
+ * Provide an optional version of the mixin where `touchableHandleFocus` and
940
+ * `touchableHandleBlur` can be overridden. This allows appropriate defaults to
941
+ * be set on TV platforms, without breaking existing implementations of
942
+ * `Touchable`.
943
+ */
944
+ const {
945
+ touchableHandleFocus,
946
+ touchableHandleBlur,
947
+ ...TouchableMixinWithoutDefaultFocusAndBlur
948
+ } = TouchableMixin;
949
+ TouchableMixin.withoutDefaultFocusAndBlur =
950
+ TouchableMixinWithoutDefaultFocusAndBlur;
951
+
952
+ const Touchable = {
953
+ Mixin: TouchableMixin,
954
+ /**
955
+ * Renders a debugging overlay to visualize touch target with hitSlop (might not work on Android).
956
+ */
957
+ renderDebugView: ({
958
+ color,
959
+ hitSlop,
960
+ }: {
961
+ color: ColorValue,
962
+ hitSlop: EdgeInsetsProp,
963
+ ...
964
+ }): null | React.Node => {
965
+ if (__DEV__) {
966
+ return <PressabilityDebugView color={color} hitSlop={hitSlop} />;
967
+ }
968
+ return null;
969
+ },
970
+ };
971
+
972
+ module.exports = Touchable;