react-native-gesture-handler 2.3.0 → 2.4.0
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.
- package/RNGestureHandler.podspec +2 -1
- package/android/build.gradle +10 -2
- package/android/lib/src/main/java/com/swmansion/gesturehandler/GestureHandler.kt +14 -2
- package/android/noreanimated/src/main/java/com/swmansion/gesturehandler/ReanimatedEventDispatcher.kt +10 -0
- package/android/reanimated/src/main/java/com/swmansion/gesturehandler/ReanimatedEventDispatcher.kt +17 -0
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +11 -3
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEnabledRootView.kt +3 -41
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEvent.kt +6 -0
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +10 -54
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootView.kt +2 -0
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerStateChangeEvent.kt +6 -0
- package/ios/RNGHTouchEventType.h +9 -0
- package/ios/RNGestureHandler.h +2 -2
- package/ios/RNGestureHandler.m +21 -8
- package/ios/RNGestureHandler.xcodeproj/project.xcworkspace/xcuserdata/jakubpiasecki.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/RNGestureHandler.xcodeproj/xcuserdata/jakubpiasecki.xcuserdatad/xcschemes/xcschememanagement.plist +19 -0
- package/ios/RNGestureHandlerButton.h +1 -0
- package/ios/RNGestureHandlerButton.m +9 -1
- package/ios/RNGestureHandlerButtonComponentView.mm +14 -1
- package/ios/RNGestureHandlerButtonManager.m +4 -1
- package/ios/RNGestureHandlerEvents.h +2 -2
- package/ios/RNGestureHandlerEvents.m +2 -2
- package/ios/RNGestureHandlerManager.h +2 -0
- package/ios/RNGestureHandlerManager.mm +30 -20
- package/ios/RNGestureHandlerModule.mm +18 -0
- package/ios/RNGestureHandlerPointerTracker.h +2 -2
- package/ios/RNGestureHandlerPointerTracker.m +9 -6
- package/ios/RNGestureHandlerRegistry.h +1 -0
- package/ios/RNGestureHandlerRegistry.m +10 -0
- package/jest-utils/package.json +6 -0
- package/lib/commonjs/GestureHandlerRootView.android.js +7 -1
- package/lib/commonjs/GestureHandlerRootView.android.js.map +1 -1
- package/lib/commonjs/GestureHandlerRootView.js +6 -0
- package/lib/commonjs/GestureHandlerRootView.js.map +1 -1
- package/lib/commonjs/GestureHandlerRootView.web.js +19 -0
- package/lib/commonjs/GestureHandlerRootView.web.js.map +1 -0
- package/lib/commonjs/RNGestureHandlerModule.js +5 -0
- package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/RNGestureHandlerModule.web.js +4 -1
- package/lib/commonjs/RNGestureHandlerModule.web.js.map +1 -1
- package/lib/commonjs/{EventType.js → TouchEventType.js} +4 -4
- package/lib/commonjs/TouchEventType.js.map +1 -0
- package/lib/commonjs/components/GestureButtons.js.map +1 -1
- package/lib/commonjs/components/GestureHandlerButton.js +1 -1
- package/lib/commonjs/components/GestureHandlerButton.js.map +1 -1
- package/lib/commonjs/components/touchables/GenericTouchable.js +2 -0
- package/lib/commonjs/components/touchables/GenericTouchable.js.map +1 -1
- package/lib/commonjs/components/touchables/TouchableOpacity.js +3 -1
- package/lib/commonjs/components/touchables/TouchableOpacity.js.map +1 -1
- package/lib/commonjs/fabric/RNGestureHandlerButtonNativeComponent.js +4 -6
- package/lib/commonjs/fabric/RNGestureHandlerButtonNativeComponent.js.map +1 -1
- package/lib/commonjs/fabric/RNGestureHandlerRootViewNativeComponent.js +4 -6
- package/lib/commonjs/fabric/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
- package/lib/commonjs/getShadowNodeFromRef.js +12 -9
- package/lib/commonjs/getShadowNodeFromRef.js.map +1 -1
- package/lib/commonjs/handlers/createHandler.js +10 -14
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/handlers/gestureHandlerCommon.js +18 -1
- package/lib/commonjs/handlers/gestureHandlerCommon.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector.js +41 -21
- package/lib/commonjs/handlers/gestures/GestureDetector.js.map +1 -1
- package/lib/commonjs/handlers/gestures/eventReceiver.js +6 -5
- package/lib/commonjs/handlers/gestures/eventReceiver.js.map +1 -1
- package/lib/commonjs/handlers/gestures/gesture.js +11 -2
- package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
- package/lib/commonjs/index.js +0 -14
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/init.js +10 -1
- package/lib/commonjs/init.js.map +1 -1
- package/lib/commonjs/jestUtils/index.js +20 -0
- package/lib/commonjs/jestUtils/index.js.map +1 -0
- package/lib/commonjs/{jestUtils.js → jestUtils/jestUtils.js} +12 -12
- package/lib/commonjs/jestUtils/jestUtils.js.map +1 -0
- package/lib/commonjs/utils.js +23 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/GestureHandler.js +4 -1
- package/lib/commonjs/web/GestureHandler.js.map +1 -1
- package/lib/module/GestureHandlerRootView.android.js +7 -2
- package/lib/module/GestureHandlerRootView.android.js.map +1 -1
- package/lib/module/GestureHandlerRootView.js +5 -0
- package/lib/module/GestureHandlerRootView.js.map +1 -1
- package/lib/module/GestureHandlerRootView.web.js +6 -0
- package/lib/module/GestureHandlerRootView.web.js.map +1 -0
- package/lib/module/RNGestureHandlerModule.js +5 -0
- package/lib/module/RNGestureHandlerModule.js.map +1 -1
- package/lib/module/RNGestureHandlerModule.web.js +4 -1
- package/lib/module/RNGestureHandlerModule.web.js.map +1 -1
- package/lib/module/{EventType.js → TouchEventType.js} +2 -2
- package/lib/module/TouchEventType.js.map +1 -0
- package/lib/module/components/GestureButtons.js.map +1 -1
- package/lib/module/components/GestureHandlerButton.js +2 -2
- package/lib/module/components/GestureHandlerButton.js.map +1 -1
- package/lib/module/components/touchables/GenericTouchable.js +2 -0
- package/lib/module/components/touchables/GenericTouchable.js.map +1 -1
- package/lib/module/components/touchables/TouchableOpacity.js +4 -2
- package/lib/module/components/touchables/TouchableOpacity.js.map +1 -1
- package/lib/module/fabric/RNGestureHandlerButtonNativeComponent.js +5 -7
- package/lib/module/fabric/RNGestureHandlerButtonNativeComponent.js.map +1 -1
- package/lib/module/fabric/RNGestureHandlerRootViewNativeComponent.js +5 -8
- package/lib/module/fabric/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
- package/lib/module/getShadowNodeFromRef.js +11 -8
- package/lib/module/getShadowNodeFromRef.js.map +1 -1
- package/lib/module/handlers/createHandler.js +10 -17
- package/lib/module/handlers/createHandler.js.map +1 -1
- package/lib/module/handlers/gestureHandlerCommon.js +11 -1
- package/lib/module/handlers/gestureHandlerCommon.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector.js +41 -22
- package/lib/module/handlers/gestures/GestureDetector.js.map +1 -1
- package/lib/module/handlers/gestures/eventReceiver.js +6 -7
- package/lib/module/handlers/gestures/eventReceiver.js.map +1 -1
- package/lib/module/handlers/gestures/gesture.js +10 -2
- package/lib/module/handlers/gestures/gesture.js.map +1 -1
- package/lib/module/index.js +0 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/init.js +6 -1
- package/lib/module/init.js.map +1 -1
- package/lib/module/jestUtils/index.js +2 -0
- package/lib/module/jestUtils/index.js.map +1 -0
- package/lib/module/{jestUtils.js → jestUtils/jestUtils.js} +12 -12
- package/lib/module/jestUtils/jestUtils.js.map +1 -0
- package/lib/module/utils.js +17 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/GestureHandler.js +4 -1
- package/lib/module/web/GestureHandler.js.map +1 -1
- package/lib/typescript/GestureHandlerRootView.web.d.ts +5 -0
- package/lib/typescript/RNGestureHandlerModule.d.ts +1 -0
- package/lib/typescript/RNGestureHandlerModule.web.d.ts +1 -0
- package/lib/typescript/{EventType.d.ts → TouchEventType.d.ts} +2 -2
- package/lib/typescript/components/GestureButtons.d.ts +18 -6
- package/lib/typescript/components/touchables/TouchableOpacity.d.ts +5 -1
- package/lib/typescript/fabric/RNGestureHandlerButtonNativeComponent.d.ts +13 -0
- package/lib/typescript/fabric/RNGestureHandlerRootViewNativeComponent.d.ts +5 -0
- package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +1 -1
- package/lib/typescript/handlers/gestureHandlerCommon.d.ts +5 -3
- package/lib/typescript/handlers/gestures/GestureDetector.d.ts +0 -3
- package/lib/typescript/handlers/gestures/eventReceiver.d.ts +2 -0
- package/lib/typescript/handlers/gestures/gesture.d.ts +2 -0
- package/lib/typescript/index.d.ts +0 -1
- package/lib/typescript/init.d.ts +1 -0
- package/lib/typescript/jestUtils/index.d.ts +1 -0
- package/lib/typescript/{jestUtils.d.ts → jestUtils/jestUtils.d.ts} +18 -18
- package/lib/typescript/utils.d.ts +2 -0
- package/lib/typescript/web/GestureHandler.d.ts +1 -1
- package/package.json +5 -2
- package/src/GestureHandlerRootView.android.tsx +8 -2
- package/src/GestureHandlerRootView.tsx +6 -0
- package/src/GestureHandlerRootView.web.tsx +12 -0
- package/src/RNGestureHandlerModule.ts +7 -0
- package/src/RNGestureHandlerModule.web.ts +2 -0
- package/src/{EventType.ts → TouchEventType.ts} +2 -2
- package/src/components/GestureButtons.tsx +21 -7
- package/src/components/GestureHandlerButton.tsx +2 -2
- package/src/components/touchables/GenericTouchable.tsx +2 -0
- package/src/components/touchables/TouchableOpacity.tsx +6 -2
- package/src/fabric/RNGestureHandlerButtonNativeComponent.ts +27 -0
- package/src/fabric/RNGestureHandlerRootViewNativeComponent.ts +12 -0
- package/src/getShadowNodeFromRef.ts +12 -9
- package/src/handlers/createHandler.ts +7 -17
- package/src/handlers/gestureHandlerCommon.ts +19 -2
- package/src/handlers/gestures/GestureDetector.tsx +64 -31
- package/src/handlers/gestures/eventReceiver.ts +6 -6
- package/src/handlers/gestures/gesture.ts +13 -2
- package/src/index.ts +0 -1
- package/src/init.ts +8 -1
- package/src/jestUtils/index.ts +1 -0
- package/src/{jestUtils.ts → jestUtils/jestUtils.ts} +21 -21
- package/src/utils.ts +20 -0
- package/src/web/GestureHandler.ts +7 -1
- package/ios/RNTouchEventType.h +0 -9
- package/lib/commonjs/EventType.js.map +0 -1
- package/lib/commonjs/jestUtils.js.map +0 -1
- package/lib/module/EventType.js.map +0 -1
- package/lib/module/jestUtils.js.map +0 -1
- package/src/fabric/RNGestureHandlerButtonNativeComponent.js +0 -27
- package/src/fabric/RNGestureHandlerRootViewNativeComponent.js +0 -19
|
@@ -16,6 +16,8 @@ import {
|
|
|
16
16
|
GestureTouchEvent,
|
|
17
17
|
GestureUpdateEvent,
|
|
18
18
|
GestureStateChangeEvent,
|
|
19
|
+
HandlerStateChangeEvent,
|
|
20
|
+
scheduleFlushOperations,
|
|
19
21
|
} from '../gestureHandlerCommon';
|
|
20
22
|
import {
|
|
21
23
|
GestureStateManager,
|
|
@@ -30,15 +32,18 @@ import {
|
|
|
30
32
|
} from '../PanGestureHandler';
|
|
31
33
|
import { tapGestureHandlerProps } from '../TapGestureHandler';
|
|
32
34
|
import { State } from '../../State';
|
|
33
|
-
import {
|
|
35
|
+
import { TouchEventType } from '../../TouchEventType';
|
|
34
36
|
import { ComposedGesture } from './gestureComposition';
|
|
35
37
|
import { ActionType } from '../../ActionType';
|
|
36
38
|
import { isFabric, tagMessage } from '../../utils';
|
|
37
39
|
import { getShadowNodeFromRef } from '../../getShadowNodeFromRef';
|
|
40
|
+
import { Platform } from 'react-native';
|
|
41
|
+
import type RNGestureHandlerModuleWeb from '../../RNGestureHandlerModule.web';
|
|
42
|
+
import { onGestureHandlerEvent } from './eventReceiver';
|
|
38
43
|
|
|
39
|
-
declare global {
|
|
40
|
-
|
|
41
|
-
}
|
|
44
|
+
declare const global: {
|
|
45
|
+
isFormsStackingContext: (node: unknown) => boolean | null; // JSI function
|
|
46
|
+
};
|
|
42
47
|
|
|
43
48
|
const ALLOWED_PROPS = [
|
|
44
49
|
...baseGestureHandlerWithMonitorProps,
|
|
@@ -84,6 +89,8 @@ function dropHandlers(preparedGesture: GestureConfigReference) {
|
|
|
84
89
|
|
|
85
90
|
unregisterHandler(handler.handlerTag, handler.config.testId);
|
|
86
91
|
}
|
|
92
|
+
|
|
93
|
+
scheduleFlushOperations();
|
|
87
94
|
}
|
|
88
95
|
|
|
89
96
|
function checkGestureCallbacksForWorklets(gesture: GestureType) {
|
|
@@ -107,11 +114,16 @@ function checkGestureCallbacksForWorklets(gesture: GestureType) {
|
|
|
107
114
|
}
|
|
108
115
|
}
|
|
109
116
|
|
|
117
|
+
interface WebEventHandler {
|
|
118
|
+
onGestureHandlerEvent: (event: HandlerStateChangeEvent<unknown>) => void;
|
|
119
|
+
}
|
|
120
|
+
|
|
110
121
|
interface AttachHandlersConfig {
|
|
111
122
|
preparedGesture: GestureConfigReference;
|
|
112
123
|
gestureConfig: ComposedGesture | GestureType | undefined;
|
|
113
124
|
gesture: GestureType[];
|
|
114
125
|
viewTag: number;
|
|
126
|
+
webEventHandlersRef: React.RefObject<WebEventHandler>;
|
|
115
127
|
}
|
|
116
128
|
|
|
117
129
|
function attachHandlers({
|
|
@@ -119,6 +131,7 @@ function attachHandlers({
|
|
|
119
131
|
gestureConfig,
|
|
120
132
|
gesture,
|
|
121
133
|
viewTag,
|
|
134
|
+
webEventHandlersRef,
|
|
122
135
|
}: AttachHandlersConfig) {
|
|
123
136
|
if (!preparedGesture.firstExecution) {
|
|
124
137
|
gestureConfig?.initialize();
|
|
@@ -142,10 +155,12 @@ function attachHandlers({
|
|
|
142
155
|
);
|
|
143
156
|
|
|
144
157
|
registerHandler(handler.handlerTag, handler, handler.config.testId);
|
|
158
|
+
}
|
|
145
159
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
160
|
+
// use setImmediate to extract handlerTags, because all refs should be initialized
|
|
161
|
+
// when it's ran
|
|
162
|
+
setImmediate(() => {
|
|
163
|
+
for (const handler of gesture) {
|
|
149
164
|
let requireToFail: number[] = [];
|
|
150
165
|
if (handler.config.requireToFail) {
|
|
151
166
|
requireToFail = extractValidHandlerTags(handler.config.requireToFail);
|
|
@@ -165,8 +180,11 @@ function attachHandlers({
|
|
|
165
180
|
waitFor: requireToFail,
|
|
166
181
|
})
|
|
167
182
|
);
|
|
168
|
-
}
|
|
169
|
-
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
scheduleFlushOperations();
|
|
186
|
+
});
|
|
187
|
+
|
|
170
188
|
preparedGesture.config = gesture;
|
|
171
189
|
|
|
172
190
|
for (const gesture of preparedGesture.config) {
|
|
@@ -174,11 +192,20 @@ function attachHandlers({
|
|
|
174
192
|
? ActionType.REANIMATED_WORKLET
|
|
175
193
|
: ActionType.JS_FUNCTION_NEW_API;
|
|
176
194
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
195
|
+
if (Platform.OS === 'web') {
|
|
196
|
+
(RNGestureHandlerModule.attachGestureHandler as typeof RNGestureHandlerModuleWeb.attachGestureHandler)(
|
|
197
|
+
gesture.handlerTag,
|
|
198
|
+
viewTag,
|
|
199
|
+
ActionType.JS_FUNCTION_OLD_API, // ignored on web
|
|
200
|
+
webEventHandlersRef
|
|
201
|
+
);
|
|
202
|
+
} else {
|
|
203
|
+
RNGestureHandlerModule.attachGestureHandler(
|
|
204
|
+
gesture.handlerTag,
|
|
205
|
+
viewTag,
|
|
206
|
+
actionType
|
|
207
|
+
);
|
|
208
|
+
}
|
|
182
209
|
}
|
|
183
210
|
|
|
184
211
|
if (preparedGesture.animatedHandlers) {
|
|
@@ -247,6 +274,8 @@ function updateHandlers(
|
|
|
247
274
|
Record<string, unknown>
|
|
248
275
|
>[];
|
|
249
276
|
}
|
|
277
|
+
|
|
278
|
+
scheduleFlushOperations();
|
|
250
279
|
});
|
|
251
280
|
}
|
|
252
281
|
|
|
@@ -322,16 +351,18 @@ function useAnimatedGesture(
|
|
|
322
351
|
}
|
|
323
352
|
}
|
|
324
353
|
|
|
325
|
-
function touchEventTypeToCallbackType(
|
|
354
|
+
function touchEventTypeToCallbackType(
|
|
355
|
+
eventType: TouchEventType
|
|
356
|
+
): CALLBACK_TYPE {
|
|
326
357
|
'worklet';
|
|
327
358
|
switch (eventType) {
|
|
328
|
-
case
|
|
359
|
+
case TouchEventType.TOUCHES_DOWN:
|
|
329
360
|
return CALLBACK_TYPE.TOUCHES_DOWN;
|
|
330
|
-
case
|
|
361
|
+
case TouchEventType.TOUCHES_MOVE:
|
|
331
362
|
return CALLBACK_TYPE.TOUCHES_MOVE;
|
|
332
|
-
case
|
|
363
|
+
case TouchEventType.TOUCHES_UP:
|
|
333
364
|
return CALLBACK_TYPE.TOUCHES_UP;
|
|
334
|
-
case
|
|
365
|
+
case TouchEventType.TOUCHES_CANCELLED:
|
|
335
366
|
return CALLBACK_TYPE.TOUCHES_CANCELLED;
|
|
336
367
|
}
|
|
337
368
|
return CALLBACK_TYPE.UNDEFINED;
|
|
@@ -418,7 +449,7 @@ function useAnimatedGesture(
|
|
|
418
449
|
stateControllers[i] = GestureStateManager.create(event.handlerTag);
|
|
419
450
|
}
|
|
420
451
|
|
|
421
|
-
if (event.eventType !==
|
|
452
|
+
if (event.eventType !== TouchEventType.UNDETERMINED) {
|
|
422
453
|
runWorklet(
|
|
423
454
|
touchEventTypeToCallbackType(event.eventType),
|
|
424
455
|
gesture,
|
|
@@ -468,6 +499,11 @@ export const GestureDetector: React.FunctionComponent<GestureDetectorProps> = (
|
|
|
468
499
|
const useReanimatedHook = gesture.some((g) => g.shouldUseReanimated);
|
|
469
500
|
const viewRef = useRef(null);
|
|
470
501
|
const firstRenderRef = useRef(true);
|
|
502
|
+
const webEventHandlersRef = useRef<WebEventHandler>({
|
|
503
|
+
onGestureHandlerEvent: (e: HandlerStateChangeEvent<unknown>) => {
|
|
504
|
+
onGestureHandlerEvent(e.nativeEvent);
|
|
505
|
+
},
|
|
506
|
+
});
|
|
471
507
|
|
|
472
508
|
const preparedGesture = React.useRef<GestureConfigReference>({
|
|
473
509
|
config: gesture,
|
|
@@ -508,6 +544,7 @@ export const GestureDetector: React.FunctionComponent<GestureDetectorProps> = (
|
|
|
508
544
|
gestureConfig,
|
|
509
545
|
gesture,
|
|
510
546
|
viewTag,
|
|
547
|
+
webEventHandlersRef,
|
|
511
548
|
});
|
|
512
549
|
|
|
513
550
|
return () => {
|
|
@@ -526,6 +563,7 @@ export const GestureDetector: React.FunctionComponent<GestureDetectorProps> = (
|
|
|
526
563
|
gestureConfig,
|
|
527
564
|
gesture,
|
|
528
565
|
viewTag,
|
|
566
|
+
webEventHandlersRef,
|
|
529
567
|
});
|
|
530
568
|
} else {
|
|
531
569
|
updateHandlers(preparedGesture, gestureConfig, gesture);
|
|
@@ -543,17 +581,12 @@ export const GestureDetector: React.FunctionComponent<GestureDetectorProps> = (
|
|
|
543
581
|
if (isFabric()) {
|
|
544
582
|
const node = getShadowNodeFromRef(ref);
|
|
545
583
|
if (global.isFormsStackingContext(node) === false) {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
'GestureDetector has received a child that may get view-flattened. ' +
|
|
553
|
-
'\nTo prevent it from misbehaving you need to wrap the child with a `<View collapsable={false}>`.'
|
|
554
|
-
)
|
|
555
|
-
);
|
|
556
|
-
});
|
|
584
|
+
console.error(
|
|
585
|
+
tagMessage(
|
|
586
|
+
'GestureDetector has received a child that may get view-flattened. ' +
|
|
587
|
+
'\nTo prevent it from misbehaving you need to wrap the child with a `<View collapsable={false}>`.'
|
|
588
|
+
)
|
|
589
|
+
);
|
|
557
590
|
}
|
|
558
591
|
}
|
|
559
592
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeviceEventEmitter, EmitterSubscription } from 'react-native';
|
|
2
2
|
import { State } from '../../State';
|
|
3
|
-
import {
|
|
3
|
+
import { TouchEventType } from '../../TouchEventType';
|
|
4
4
|
import {
|
|
5
5
|
GestureTouchEvent,
|
|
6
6
|
GestureUpdateEvent,
|
|
@@ -48,7 +48,7 @@ function isTouchEvent(
|
|
|
48
48
|
return event.eventType != null;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
function onGestureHandlerEvent(
|
|
51
|
+
export function onGestureHandlerEvent(
|
|
52
52
|
event: GestureUpdateEvent | GestureStateChangeEvent | GestureTouchEvent
|
|
53
53
|
) {
|
|
54
54
|
const handler = findHandler(event.handlerTag) as BaseGesture<
|
|
@@ -87,16 +87,16 @@ function onGestureHandlerEvent(
|
|
|
87
87
|
}
|
|
88
88
|
} else if (isTouchEvent(event)) {
|
|
89
89
|
switch (event.eventType) {
|
|
90
|
-
case
|
|
90
|
+
case TouchEventType.TOUCHES_DOWN:
|
|
91
91
|
handler.handlers?.onTouchesDown?.(event, dummyStateManager);
|
|
92
92
|
break;
|
|
93
|
-
case
|
|
93
|
+
case TouchEventType.TOUCHES_MOVE:
|
|
94
94
|
handler.handlers?.onTouchesMove?.(event, dummyStateManager);
|
|
95
95
|
break;
|
|
96
|
-
case
|
|
96
|
+
case TouchEventType.TOUCHES_UP:
|
|
97
97
|
handler.handlers?.onTouchesUp?.(event, dummyStateManager);
|
|
98
98
|
break;
|
|
99
|
-
case
|
|
99
|
+
case TouchEventType.TOUCHES_CANCELLED:
|
|
100
100
|
handler.handlers?.onTouchesCancelled?.(event, dummyStateManager);
|
|
101
101
|
break;
|
|
102
102
|
}
|
|
@@ -15,6 +15,7 @@ import { PinchGestureHandlerEventPayload } from '../PinchGestureHandler';
|
|
|
15
15
|
import { RotationGestureHandlerEventPayload } from '../RotationGestureHandler';
|
|
16
16
|
import { TapGestureHandlerEventPayload } from '../TapGestureHandler';
|
|
17
17
|
import { NativeViewGestureHandlerPayload } from '../NativeViewGestureHandler';
|
|
18
|
+
import { isRemoteDebuggingEnabled } from '../../utils';
|
|
18
19
|
|
|
19
20
|
export type GestureType =
|
|
20
21
|
| BaseGesture<Record<string, unknown>>
|
|
@@ -43,6 +44,7 @@ export interface BaseGestureConfig
|
|
|
43
44
|
manualActivation?: boolean;
|
|
44
45
|
runOnJS?: boolean;
|
|
45
46
|
testId?: string;
|
|
47
|
+
cancelsTouchesInView?: boolean;
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
type TouchEventHandlerType = (
|
|
@@ -260,6 +262,11 @@ export abstract class BaseGesture<
|
|
|
260
262
|
return this;
|
|
261
263
|
}
|
|
262
264
|
|
|
265
|
+
cancelsTouchesInView(value: boolean) {
|
|
266
|
+
this.config.cancelsTouchesInView = value;
|
|
267
|
+
return this;
|
|
268
|
+
}
|
|
269
|
+
|
|
263
270
|
initialize() {
|
|
264
271
|
this.handlerTag = getNextHandlerTag();
|
|
265
272
|
|
|
@@ -278,9 +285,13 @@ export abstract class BaseGesture<
|
|
|
278
285
|
prepare() {}
|
|
279
286
|
|
|
280
287
|
get shouldUseReanimated(): boolean {
|
|
281
|
-
// use Reanimated when runOnJS isn't set explicitly
|
|
288
|
+
// use Reanimated when runOnJS isn't set explicitly,
|
|
289
|
+
// and all defined callbacks are worklets,
|
|
290
|
+
// and remote debugging is disabled
|
|
282
291
|
return (
|
|
283
|
-
this.config.runOnJS !== true &&
|
|
292
|
+
this.config.runOnJS !== true &&
|
|
293
|
+
!this.handlers.isWorklet.includes(false) &&
|
|
294
|
+
!isRemoteDebuggingEnabled()
|
|
284
295
|
);
|
|
285
296
|
}
|
|
286
297
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { initialize } from './init';
|
|
|
2
2
|
|
|
3
3
|
export { Directions } from './Directions';
|
|
4
4
|
export { State } from './State';
|
|
5
|
-
export { getByGestureTestId, fireGestureHandler } from './jestUtils';
|
|
6
5
|
export { default as gestureHandlerRootHOC } from './gestureHandlerRootHOC';
|
|
7
6
|
export { default as GestureHandlerRootView } from './GestureHandlerRootView';
|
|
8
7
|
export type {
|
package/src/init.ts
CHANGED
|
@@ -2,10 +2,17 @@ import { startListening } from './handlers/gestures/eventReceiver';
|
|
|
2
2
|
import RNGestureHandlerModule from './RNGestureHandlerModule';
|
|
3
3
|
import { isFabric } from './utils';
|
|
4
4
|
|
|
5
|
+
let fabricInitialized = false;
|
|
6
|
+
|
|
5
7
|
export function initialize() {
|
|
6
8
|
startListening();
|
|
9
|
+
}
|
|
7
10
|
|
|
8
|
-
|
|
11
|
+
// since isFabric() may give wrong results before the first render, we call this
|
|
12
|
+
// method during render of GestureHandlerRootView
|
|
13
|
+
export function maybeInitializeFabric() {
|
|
14
|
+
if (isFabric() && !fabricInitialized) {
|
|
9
15
|
RNGestureHandlerModule.install();
|
|
16
|
+
fabricInitialized = true;
|
|
10
17
|
}
|
|
11
18
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getByGestureTestId, fireGestureHandler } from './jestUtils';
|
|
@@ -5,59 +5,59 @@ import {
|
|
|
5
5
|
FlingGestureHandler,
|
|
6
6
|
FlingGestureHandlerEventPayload,
|
|
7
7
|
flingHandlerName,
|
|
8
|
-
} from '
|
|
8
|
+
} from '../handlers/FlingGestureHandler';
|
|
9
9
|
import {
|
|
10
10
|
ForceTouchGestureHandler,
|
|
11
11
|
ForceTouchGestureHandlerEventPayload,
|
|
12
12
|
forceTouchHandlerName,
|
|
13
|
-
} from '
|
|
13
|
+
} from '../handlers/ForceTouchGestureHandler';
|
|
14
14
|
import {
|
|
15
15
|
BaseGestureHandlerProps,
|
|
16
16
|
GestureEvent,
|
|
17
17
|
HandlerStateChangeEvent,
|
|
18
|
-
} from '
|
|
19
|
-
import { FlingGesture } from '
|
|
20
|
-
import { ForceTouchGesture } from '
|
|
21
|
-
import { BaseGesture, GestureType } from '
|
|
22
|
-
import { LongPressGesture } from '
|
|
23
|
-
import { NativeGesture } from '
|
|
24
|
-
import { PanGesture } from '
|
|
25
|
-
import { PinchGesture } from '
|
|
26
|
-
import { RotationGesture } from '
|
|
27
|
-
import { TapGesture } from '
|
|
28
|
-
import { findHandlerByTestID } from '
|
|
18
|
+
} from '../handlers/gestureHandlerCommon';
|
|
19
|
+
import { FlingGesture } from '../handlers/gestures/flingGesture';
|
|
20
|
+
import { ForceTouchGesture } from '../handlers/gestures/forceTouchGesture';
|
|
21
|
+
import { BaseGesture, GestureType } from '../handlers/gestures/gesture';
|
|
22
|
+
import { LongPressGesture } from '../handlers/gestures/longPressGesture';
|
|
23
|
+
import { NativeGesture } from '../handlers/gestures/nativeGesture';
|
|
24
|
+
import { PanGesture } from '../handlers/gestures/panGesture';
|
|
25
|
+
import { PinchGesture } from '../handlers/gestures/pinchGesture';
|
|
26
|
+
import { RotationGesture } from '../handlers/gestures/rotationGesture';
|
|
27
|
+
import { TapGesture } from '../handlers/gestures/tapGesture';
|
|
28
|
+
import { findHandlerByTestID } from '../handlers/handlersRegistry';
|
|
29
29
|
import {
|
|
30
30
|
LongPressGestureHandler,
|
|
31
31
|
LongPressGestureHandlerEventPayload,
|
|
32
32
|
longPressHandlerName,
|
|
33
|
-
} from '
|
|
33
|
+
} from '../handlers/LongPressGestureHandler';
|
|
34
34
|
import {
|
|
35
35
|
NativeViewGestureHandler,
|
|
36
36
|
NativeViewGestureHandlerPayload,
|
|
37
37
|
nativeViewHandlerName,
|
|
38
|
-
} from '
|
|
38
|
+
} from '../handlers/NativeViewGestureHandler';
|
|
39
39
|
import {
|
|
40
40
|
PanGestureHandler,
|
|
41
41
|
PanGestureHandlerEventPayload,
|
|
42
42
|
panHandlerName,
|
|
43
|
-
} from '
|
|
43
|
+
} from '../handlers/PanGestureHandler';
|
|
44
44
|
import {
|
|
45
45
|
PinchGestureHandler,
|
|
46
46
|
PinchGestureHandlerEventPayload,
|
|
47
47
|
pinchHandlerName,
|
|
48
|
-
} from '
|
|
48
|
+
} from '../handlers/PinchGestureHandler';
|
|
49
49
|
import {
|
|
50
50
|
RotationGestureHandler,
|
|
51
51
|
RotationGestureHandlerEventPayload,
|
|
52
52
|
rotationHandlerName,
|
|
53
|
-
} from '
|
|
53
|
+
} from '../handlers/RotationGestureHandler';
|
|
54
54
|
import {
|
|
55
55
|
TapGestureHandler,
|
|
56
56
|
TapGestureHandlerEventPayload,
|
|
57
57
|
tapHandlerName,
|
|
58
|
-
} from '
|
|
59
|
-
import { State } from '
|
|
60
|
-
import { hasProperty, withPrevAndCurrent } from '
|
|
58
|
+
} from '../handlers/TapGestureHandler';
|
|
59
|
+
import { State } from '../State';
|
|
60
|
+
import { hasProperty, withPrevAndCurrent } from '../utils';
|
|
61
61
|
|
|
62
62
|
// load fireEvent conditionally, so RNGH may be used in setups without testing-library
|
|
63
63
|
let fireEvent = (
|
package/src/utils.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { version as rnVersion } from 'react-native/package.json';
|
|
2
|
+
|
|
1
3
|
export function toArray<T>(object: T | T[]): T[] {
|
|
2
4
|
if (!Array.isArray(object)) {
|
|
3
5
|
return [object];
|
|
@@ -32,6 +34,7 @@ export function hasProperty(object: object, key: string) {
|
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
export function isJestEnv(): boolean {
|
|
37
|
+
// @ts-ignore Do not use `@types/node` because it will prioritise Node types over RN types which breaks the types (ex. setTimeout) in React Native projects.
|
|
35
38
|
return hasProperty(global, 'process') && !!process.env.JEST_WORKER_ID;
|
|
36
39
|
}
|
|
37
40
|
|
|
@@ -39,7 +42,24 @@ export function tagMessage(msg: string) {
|
|
|
39
42
|
return `[react-native-gesture-handler] ${msg}`;
|
|
40
43
|
}
|
|
41
44
|
|
|
45
|
+
// helper method to check whether Fabric is enabled, however global.nativeFabricUIManager
|
|
46
|
+
// may not be initialized before the first render
|
|
42
47
|
export function isFabric(): boolean {
|
|
43
48
|
// @ts-expect-error nativeFabricUIManager is not yet included in the RN types
|
|
44
49
|
return !!global?.nativeFabricUIManager;
|
|
45
50
|
}
|
|
51
|
+
|
|
52
|
+
export function shouldUseCodegenNativeComponent(): boolean {
|
|
53
|
+
const [majorStr, minorStr] = rnVersion.split('.');
|
|
54
|
+
const major = Number.parseInt(majorStr);
|
|
55
|
+
const minor = Number.parseInt(minorStr);
|
|
56
|
+
|
|
57
|
+
// use codegenNativeComponent starting with RN 0.68
|
|
58
|
+
return minor >= 68 || major > 0;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function isRemoteDebuggingEnabled(): boolean {
|
|
62
|
+
// react-native-reanimated checks if in remote debugging in the same way
|
|
63
|
+
// @ts-ignore global is available but node types are not included
|
|
64
|
+
return !(global as any).nativeCallSyncHook || (global as any).__REMOTEDEV__;
|
|
65
|
+
}
|
|
@@ -182,7 +182,13 @@ abstract class GestureHandler {
|
|
|
182
182
|
// onHandlerStateChange only
|
|
183
183
|
handlerTag: this.handlerTag,
|
|
184
184
|
target: this.ref,
|
|
185
|
-
oldState
|
|
185
|
+
// send oldState only when the state was changed, or is different than ACTIVE
|
|
186
|
+
// GestureDetector relies on the presence of `oldState` to differentiate between
|
|
187
|
+
// update events and state change events
|
|
188
|
+
oldState:
|
|
189
|
+
state !== this.previousState || state != 4
|
|
190
|
+
? this.oldState
|
|
191
|
+
: undefined,
|
|
186
192
|
},
|
|
187
193
|
timeStamp: Date.now(),
|
|
188
194
|
};
|
package/ios/RNTouchEventType.h
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["EventType.ts"],"names":["EventType","UNDETERMINED","TOUCHES_DOWN","TOUCHES_MOVE","TOUCHES_UP","TOUCHES_CANCELLED"],"mappings":";;;;;;AAAO,MAAMA,SAAS,GAAG;AACvBC,EAAAA,YAAY,EAAE,CADS;AAEvBC,EAAAA,YAAY,EAAE,CAFS;AAGvBC,EAAAA,YAAY,EAAE,CAHS;AAIvBC,EAAAA,UAAU,EAAE,CAJW;AAKvBC,EAAAA,iBAAiB,EAAE;AALI,CAAlB,C,CAQP","sourcesContent":["export const EventType = {\n UNDETERMINED: 0,\n TOUCHES_DOWN: 1,\n TOUCHES_MOVE: 2,\n TOUCHES_UP: 3,\n TOUCHES_CANCELLED: 4,\n} as const;\n\n// eslint-disable-next-line @typescript-eslint/no-redeclare -- backward compatibility; it can be used as a type and as a value\nexport type EventType = typeof EventType[keyof typeof EventType];\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["jestUtils.ts"],"names":["fireEvent","_element","_name","_data","require","_e","handlersDefaultEvents","flingHandlerName","x","y","absoluteX","absoluteY","numberOfPointers","forceTouchHandlerName","force","longPressHandlerName","duration","nativeViewHandlerName","pointerInside","panHandlerName","translationX","translationY","velocityX","velocityY","pinchHandlerName","focalX","focalY","scale","velocity","rotationHandlerName","anchorX","anchorY","rotation","tapHandlerName","isGesture","componentOrGesture","BaseGesture","wrapWithNativeEvent","event","nativeEvent","fillOldStateChanges","previousEvent","currentEvent","isFirstEvent","oldState","State","UNDETERMINED","isGestureStateEvent","state","validateStateTransitions","stringify","JSON","errorMsgWithBothEvents","description","errorMsgWithCurrentEvent","BEGAN","fillMissingDefaultsFor","handlerType","handlerTag","isDiscreteHandler","fillMissingStatesTransitions","events","_events","lastEvent","length","firstEvent","shouldDuplicateFirstEvent","hasState","duplicated","unshift","shouldDuplicateLastEvent","END","FAILED","CANCELLED","push","isWithoutState","noEventsLeft","trueFn","fillEventsForCurrentState","shouldConsumeEvent","shouldTransitionToNextState","peekCurrentEvent","peekNextEvent","consumeCurrentEvent","shift","nextEvent","currentRequiredState","REQUIRED_EVENTS","currentStateIdx","eventData","shouldUseEvent","transformedEvents","ACTIVE","hasAllStates","iterations","nextRequiredState","e","getHandlerData","gesture","emitEvent","eventName","args","DeviceEventEmitter","emit","handlerName","gestureHandlerComponent","props","fireGestureHandler","eventList","_","map","lastSentEvent","hasChangedState","getByGestureTestId","testID","handler","Error"],"mappings":";;;;;;;;AAAA;;AACA;;AAEA;;AAKA;;AAYA;;AAOA;;AACA;;AAKA;;AAKA;;AAKA;;AAKA;;AAKA;;AAKA;;AACA;;;;AAEA;AACA,IAAIA,SAAS,GAAG,CACdC,QADc,EAEdC,KAFc,EAGd,GAAGC,KAHW,KAIX,CACH;AACD,CAND;;AAQA,IA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AAsB,CAAC;AAAEE,IAAAA,UAAF;AAAcD,IAAAA;AAAd,GAAD,CAA5B,CAAJ;AACAoD,EAAAA,CAAC,GAAG,+BAAmBA,CAAnB,EAAsBrE,mBAAtB,CAAJ;AACAqE,EAAAA,CAAC,GAAG,+BAAmBA,CAAnB,EAAsB5D,wBAAtB,CAAJ,CAXM,CAYN;;AACA4D,EAAAA,CAAC,GAAGA,CAAC,CAACC,GAAF,CAAMzE,mBAAN,CAAJ;AAEA,QAAMwB,MAAM,GAAIgD,CAAhB;AAEA,QAAM5C,UAAU,GAAGJ,MAAM,CAACuB,KAAP,EAAnB;AAEAe,EAAAA,SAAS,CAAC,6BAAD,EAAgClC,UAAhC,CAAT;AACA,MAAI8C,aAAa,GAAG9C,UAApB;;AACA,OAAK,MAAM3B,KAAX,IAAoBuB,MAApB,EAA4B;AAC1B,UAAMmD,eAAe,GACnBD,aAAa,CAACxE,WAAd,CAA0BS,KAA1B,KAAoCV,KAAK,CAACC,WAAN,CAAkBS,KADxD;;AAGA,QAAIgE,eAAJ,EAAqB;AACnBb,MAAAA,SAAS,CAAC,6BAAD,EAAgC7D,KAAhC,CAAT;AACD,KAFD,MAEO;AACL6D,MAAAA,SAAS,CAAC,uBAAD,EAA0B7D,KAA1B,CAAT;AACD;;AACDyE,IAAAA,aAAa,GAAGzE,KAAhB;AACD;AACF;;AAEM,SAAS2E,kBAAT,CAA4BC,MAA5B,EAA4C;AACjD,QAAMC,OAAO,GAAG,2CAAoBD,MAApB,CAAhB;;AACA,MAAIC,OAAO,KAAK,IAAhB,EAAsB;AACpB,UAAM,IAAIC,KAAJ,CAAW,qBAAoBF,MAAO,mBAAtC,CAAN;AACD;;AACD,SAAOC,OAAP;AACD","sourcesContent":["import invariant from 'invariant';\nimport { DeviceEventEmitter } from 'react-native';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport {\n FlingGestureHandler,\n FlingGestureHandlerEventPayload,\n flingHandlerName,\n} from './handlers/FlingGestureHandler';\nimport {\n ForceTouchGestureHandler,\n ForceTouchGestureHandlerEventPayload,\n forceTouchHandlerName,\n} from './handlers/ForceTouchGestureHandler';\nimport {\n BaseGestureHandlerProps,\n GestureEvent,\n HandlerStateChangeEvent,\n} from './handlers/gestureHandlerCommon';\nimport { FlingGesture } from './handlers/gestures/flingGesture';\nimport { ForceTouchGesture } from './handlers/gestures/forceTouchGesture';\nimport { BaseGesture, GestureType } from './handlers/gestures/gesture';\nimport { LongPressGesture } from './handlers/gestures/longPressGesture';\nimport { NativeGesture } from './handlers/gestures/nativeGesture';\nimport { PanGesture } from './handlers/gestures/panGesture';\nimport { PinchGesture } from './handlers/gestures/pinchGesture';\nimport { RotationGesture } from './handlers/gestures/rotationGesture';\nimport { TapGesture } from './handlers/gestures/tapGesture';\nimport { findHandlerByTestID } from './handlers/handlersRegistry';\nimport {\n LongPressGestureHandler,\n LongPressGestureHandlerEventPayload,\n longPressHandlerName,\n} from './handlers/LongPressGestureHandler';\nimport {\n NativeViewGestureHandler,\n NativeViewGestureHandlerPayload,\n nativeViewHandlerName,\n} from './handlers/NativeViewGestureHandler';\nimport {\n PanGestureHandler,\n PanGestureHandlerEventPayload,\n panHandlerName,\n} from './handlers/PanGestureHandler';\nimport {\n PinchGestureHandler,\n PinchGestureHandlerEventPayload,\n pinchHandlerName,\n} from './handlers/PinchGestureHandler';\nimport {\n RotationGestureHandler,\n RotationGestureHandlerEventPayload,\n rotationHandlerName,\n} from './handlers/RotationGestureHandler';\nimport {\n TapGestureHandler,\n TapGestureHandlerEventPayload,\n tapHandlerName,\n} from './handlers/TapGestureHandler';\nimport { State } from './State';\nimport { hasProperty, withPrevAndCurrent } from './utils';\n\n// load fireEvent conditionally, so RNGH may be used in setups without testing-library\nlet fireEvent = (\n _element: ReactTestInstance,\n _name: string,\n ..._data: any[]\n) => {\n // NOOP\n};\n\ntry {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n fireEvent = require('@testing-library/react-native').fireEvent;\n} catch (_e) {\n // do nothing if not available\n}\n\ntype GestureHandlerTestEvent<\n TEventPayload extends Record<string, unknown> = Record<string, unknown>\n> = (\n | GestureEvent<TEventPayload>\n | HandlerStateChangeEvent<TEventPayload>\n)['nativeEvent'];\n\ntype HandlerNames = keyof DefaultEventsMapping;\n\ntype WithNumberOfPointers<T> = {\n [P in keyof T]: T[P] & { numberOfPointers: number };\n};\ntype DefaultEventsMapping = WithNumberOfPointers<{\n [flingHandlerName]: FlingGestureHandlerEventPayload;\n [forceTouchHandlerName]: ForceTouchGestureHandlerEventPayload;\n [longPressHandlerName]: LongPressGestureHandlerEventPayload;\n [nativeViewHandlerName]: NativeViewGestureHandlerPayload;\n [panHandlerName]: PanGestureHandlerEventPayload;\n [pinchHandlerName]: PinchGestureHandlerEventPayload;\n [rotationHandlerName]: RotationGestureHandlerEventPayload;\n [tapHandlerName]: TapGestureHandlerEventPayload;\n}>;\n\nconst handlersDefaultEvents: DefaultEventsMapping = {\n [flingHandlerName]: {\n x: 0,\n y: 0,\n absoluteX: 0,\n absoluteY: 0,\n numberOfPointers: 1,\n },\n [forceTouchHandlerName]: {\n x: 0,\n y: 0,\n absoluteX: 0,\n absoluteY: 0,\n force: 1,\n numberOfPointers: 1,\n },\n [longPressHandlerName]: {\n x: 0,\n y: 0,\n absoluteX: 0,\n absoluteY: 0,\n duration: 100,\n numberOfPointers: 1,\n },\n [nativeViewHandlerName]: {\n pointerInside: true,\n numberOfPointers: 1,\n },\n [panHandlerName]: {\n x: 0,\n y: 0,\n absoluteX: 0,\n absoluteY: 0,\n translationX: 100,\n translationY: 0,\n velocityX: 3,\n velocityY: 0,\n numberOfPointers: 1,\n },\n [pinchHandlerName]: {\n focalX: 0,\n focalY: 0,\n scale: 2,\n velocity: 1,\n numberOfPointers: 2,\n },\n [rotationHandlerName]: {\n anchorX: 0,\n anchorY: 0,\n rotation: 3.14,\n velocity: 2,\n numberOfPointers: 2,\n },\n [tapHandlerName]: {\n x: 0,\n y: 0,\n absoluteX: 0,\n absoluteY: 0,\n numberOfPointers: 1,\n },\n};\n\nfunction isGesture(\n componentOrGesture: ReactTestInstance | GestureType\n): componentOrGesture is GestureType {\n return componentOrGesture instanceof BaseGesture;\n}\n\ninterface WrappedGestureHandlerTestEvent {\n nativeEvent: GestureHandlerTestEvent;\n}\nfunction wrapWithNativeEvent(\n event: GestureHandlerTestEvent\n): WrappedGestureHandlerTestEvent {\n return { nativeEvent: event };\n}\n\nfunction fillOldStateChanges(\n previousEvent: GestureHandlerTestEvent | null,\n currentEvent: Omit<GestureHandlerTestEvent, 'oldState'>\n): GestureHandlerTestEvent {\n const isFirstEvent = previousEvent === null;\n if (isFirstEvent) {\n return {\n oldState: State.UNDETERMINED,\n ...currentEvent,\n } as GestureHandlerTestEvent;\n }\n\n const isGestureStateEvent = previousEvent.state !== currentEvent.state;\n if (isGestureStateEvent) {\n return {\n oldState: previousEvent?.state,\n ...currentEvent,\n } as GestureHandlerTestEvent;\n } else {\n return currentEvent as GestureHandlerTestEvent;\n }\n}\n\ntype EventWithStates = Partial<\n Pick<GestureHandlerTestEvent, 'oldState' | 'state'>\n>;\nfunction validateStateTransitions(\n previousEvent: EventWithStates | null,\n currentEvent: EventWithStates\n) {\n function stringify(event: Record<string, unknown> | null) {\n return JSON.stringify(event, null, 2);\n }\n function errorMsgWithBothEvents(description: string) {\n return `${description}, invalid event: ${stringify(\n currentEvent\n )}, previous event: ${stringify(previousEvent)}`;\n }\n\n function errorMsgWithCurrentEvent(description: string) {\n return `${description}, invalid event: ${stringify(currentEvent)}`;\n }\n\n invariant(\n hasProperty(currentEvent, 'state'),\n errorMsgWithCurrentEvent('every event must have state')\n );\n\n const isFirstEvent = previousEvent === null;\n if (isFirstEvent) {\n invariant(\n currentEvent.state === State.BEGAN,\n errorMsgWithCurrentEvent('first event must have BEGAN state')\n );\n }\n\n if (previousEvent !== null) {\n if (previousEvent.state !== currentEvent.state) {\n invariant(\n hasProperty(currentEvent, 'oldState'),\n errorMsgWithCurrentEvent(\n 'when state changes, oldState field should be present'\n )\n );\n invariant(\n currentEvent.oldState === previousEvent.state,\n errorMsgWithBothEvents(\n \"when state changes, oldState should be the same as previous event' state\"\n )\n );\n }\n }\n\n return currentEvent;\n}\n\ntype EventWithoutStates = Omit<GestureHandlerTestEvent, 'oldState' | 'state'>;\ninterface HandlerInfo {\n handlerType: HandlerNames;\n handlerTag: number;\n}\nfunction fillMissingDefaultsFor({\n handlerType,\n handlerTag,\n}: HandlerInfo): (\n event: Partial<GestureHandlerTestEvent>\n) => EventWithoutStates {\n return (event) => {\n return {\n ...handlersDefaultEvents[handlerType],\n ...event,\n handlerTag,\n };\n };\n}\n\nfunction isDiscreteHandler(handlerType: HandlerNames) {\n return (\n handlerType === 'TapGestureHandler' ||\n handlerType === 'LongPressGestureHandler'\n );\n}\n\nfunction fillMissingStatesTransitions(\n events: EventWithoutStates[],\n isDiscreteHandler: boolean\n): EventWithoutStates[] {\n type Event = EventWithoutStates | null;\n const _events = [...events];\n const lastEvent = _events[_events.length - 1] ?? null;\n const firstEvent = _events[0] ?? null;\n\n const shouldDuplicateFirstEvent =\n !isDiscreteHandler && !hasState(State.BEGAN)(firstEvent);\n if (shouldDuplicateFirstEvent) {\n const duplicated = { ...firstEvent, state: State.BEGAN };\n // @ts-ignore badly typed, property may exist and we don't want to copy it\n delete duplicated.oldState;\n _events.unshift(duplicated);\n }\n\n const shouldDuplicateLastEvent =\n !hasState(State.END)(lastEvent) ||\n !hasState(State.FAILED)(lastEvent) ||\n !hasState(State.CANCELLED)(lastEvent);\n\n if (shouldDuplicateLastEvent) {\n const duplicated = { ...lastEvent, state: State.END };\n // @ts-ignore badly typed, property may exist and we don't want to copy it\n delete duplicated.oldState;\n _events.push(duplicated);\n }\n\n function isWithoutState(event: Event) {\n return event !== null && !hasProperty(event, 'state');\n }\n function hasState(state: State) {\n return (event: Event) => event !== null && event.state === state;\n }\n function noEventsLeft(event: Event) {\n return event === null;\n }\n\n function trueFn() {\n return true;\n }\n interface Args {\n shouldConsumeEvent?: (event: Event) => boolean;\n shouldTransitionToNextState?: (nextEvent: Event) => boolean;\n }\n function fillEventsForCurrentState({\n shouldConsumeEvent = trueFn,\n shouldTransitionToNextState = trueFn,\n }: Args) {\n function peekCurrentEvent(): Event {\n return _events[0] ?? null;\n }\n function peekNextEvent(): Event {\n return _events[1] ?? null;\n }\n function consumeCurrentEvent() {\n _events.shift();\n }\n const currentEvent = peekCurrentEvent();\n const nextEvent = peekNextEvent();\n const currentRequiredState = REQUIRED_EVENTS[currentStateIdx];\n\n let eventData = {};\n const shouldUseEvent = shouldConsumeEvent(currentEvent);\n if (shouldUseEvent) {\n eventData = currentEvent!;\n consumeCurrentEvent();\n }\n transformedEvents.push({ state: currentRequiredState, ...eventData });\n if (shouldTransitionToNextState(nextEvent)) {\n currentStateIdx++;\n }\n }\n\n const REQUIRED_EVENTS = [State.BEGAN, State.ACTIVE, State.END];\n\n let currentStateIdx = 0;\n const transformedEvents: EventWithoutStates[] = [];\n let hasAllStates;\n let iterations = 0;\n do {\n const nextRequiredState = REQUIRED_EVENTS[currentStateIdx];\n if (nextRequiredState === State.BEGAN) {\n fillEventsForCurrentState({\n shouldConsumeEvent: (e: Event) =>\n isWithoutState(e) || hasState(State.BEGAN)(e),\n });\n } else if (nextRequiredState === State.ACTIVE) {\n const shouldConsumeEvent = (e: Event) =>\n isWithoutState(e) || hasState(State.ACTIVE)(e);\n const shouldTransitionToNextState = (nextEvent: Event) =>\n noEventsLeft(nextEvent) ||\n hasState(State.END)(nextEvent) ||\n hasState(State.FAILED)(nextEvent) ||\n hasState(State.CANCELLED)(nextEvent);\n\n fillEventsForCurrentState({\n shouldConsumeEvent,\n shouldTransitionToNextState,\n });\n } else if (nextRequiredState === State.END) {\n fillEventsForCurrentState({});\n }\n hasAllStates = currentStateIdx === REQUIRED_EVENTS.length;\n\n invariant(\n iterations++ <= 500,\n 'exceeded max number of iterations, please report a bug in RNGH repository with your test case'\n );\n } while (!hasAllStates);\n\n return transformedEvents;\n}\n\ntype EventEmitter = (\n eventName: string,\n args: { nativeEvent: GestureHandlerTestEvent }\n) => void;\ninterface HandlerData {\n emitEvent: EventEmitter;\n handlerType: HandlerNames;\n handlerTag: number;\n}\nfunction getHandlerData(\n componentOrGesture: ReactTestInstance | GestureType\n): HandlerData {\n if (isGesture(componentOrGesture)) {\n const gesture = componentOrGesture;\n return {\n emitEvent: (eventName, args) => {\n DeviceEventEmitter.emit(eventName, args.nativeEvent);\n },\n handlerType: gesture.handlerName as HandlerNames,\n handlerTag: gesture.handlerTag,\n };\n }\n const gestureHandlerComponent = componentOrGesture;\n return {\n emitEvent: (eventName, args) => {\n fireEvent(gestureHandlerComponent, eventName, args);\n },\n handlerType: gestureHandlerComponent.props.handlerType as HandlerNames,\n handlerTag: gestureHandlerComponent.props.handlerTag as number,\n };\n}\ntype AllGestures =\n | TapGesture\n | PanGesture\n | LongPressGesture\n | RotationGesture\n | PinchGesture\n | FlingGesture\n | ForceTouchGesture\n | NativeGesture;\n\ntype AllHandlers =\n | TapGestureHandler\n | PanGestureHandler\n | LongPressGestureHandler\n | RotationGestureHandler\n | PinchGestureHandler\n | FlingGestureHandler\n | ForceTouchGestureHandler\n | NativeViewGestureHandler;\n\n// prettier-ignore\ntype ClassComponentConstructor<P> = new (props: P) => React.Component<P, any, any>;\n\ntype ExtractPayloadFromProps<T> = T extends BaseGestureHandlerProps<\n infer TPayload\n>\n ? TPayload\n : never;\n\ntype ExtractConfig<T> = T extends BaseGesture<infer TGesturePayload>\n ? TGesturePayload\n : T extends ClassComponentConstructor<infer THandlerProps>\n ? ExtractPayloadFromProps<THandlerProps>\n : Record<string, unknown>;\n\nexport function fireGestureHandler<THandler extends AllGestures | AllHandlers>(\n componentOrGesture: ReactTestInstance | GestureType,\n eventList: Partial<GestureHandlerTestEvent<ExtractConfig<THandler>>>[] = []\n): void {\n const { emitEvent, handlerType, handlerTag } = getHandlerData(\n componentOrGesture\n );\n\n let _ = fillMissingStatesTransitions(\n eventList,\n isDiscreteHandler(handlerType)\n );\n _ = _.map(fillMissingDefaultsFor({ handlerTag, handlerType }));\n _ = withPrevAndCurrent(_, fillOldStateChanges);\n _ = withPrevAndCurrent(_, validateStateTransitions);\n // @ts-ignore TODO\n _ = _.map(wrapWithNativeEvent);\n\n const events = (_ as unknown) as WrappedGestureHandlerTestEvent[];\n\n const firstEvent = events.shift()!;\n\n emitEvent('onGestureHandlerStateChange', firstEvent);\n let lastSentEvent = firstEvent;\n for (const event of events) {\n const hasChangedState =\n lastSentEvent.nativeEvent.state !== event.nativeEvent.state;\n\n if (hasChangedState) {\n emitEvent('onGestureHandlerStateChange', event);\n } else {\n emitEvent('onGestureHandlerEvent', event);\n }\n lastSentEvent = event;\n }\n}\n\nexport function getByGestureTestId(testID: string) {\n const handler = findHandlerByTestID(testID);\n if (handler === null) {\n throw new Error(`Handler with id: '${testID}' cannot be found`);\n }\n return handler;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["EventType.ts"],"names":["EventType","UNDETERMINED","TOUCHES_DOWN","TOUCHES_MOVE","TOUCHES_UP","TOUCHES_CANCELLED"],"mappings":"AAAA,OAAO,MAAMA,SAAS,GAAG;AACvBC,EAAAA,YAAY,EAAE,CADS;AAEvBC,EAAAA,YAAY,EAAE,CAFS;AAGvBC,EAAAA,YAAY,EAAE,CAHS;AAIvBC,EAAAA,UAAU,EAAE,CAJW;AAKvBC,EAAAA,iBAAiB,EAAE;AALI,CAAlB,C,CAQP","sourcesContent":["export const EventType = {\n UNDETERMINED: 0,\n TOUCHES_DOWN: 1,\n TOUCHES_MOVE: 2,\n TOUCHES_UP: 3,\n TOUCHES_CANCELLED: 4,\n} as const;\n\n// eslint-disable-next-line @typescript-eslint/no-redeclare -- backward compatibility; it can be used as a type and as a value\nexport type EventType = typeof EventType[keyof typeof EventType];\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["jestUtils.ts"],"names":["invariant","DeviceEventEmitter","flingHandlerName","forceTouchHandlerName","BaseGesture","findHandlerByTestID","longPressHandlerName","nativeViewHandlerName","panHandlerName","pinchHandlerName","rotationHandlerName","tapHandlerName","State","hasProperty","withPrevAndCurrent","fireEvent","_element","_name","_data","require","_e","handlersDefaultEvents","x","y","absoluteX","absoluteY","numberOfPointers","force","duration","pointerInside","translationX","translationY","velocityX","velocityY","focalX","focalY","scale","velocity","anchorX","anchorY","rotation","isGesture","componentOrGesture","wrapWithNativeEvent","event","nativeEvent","fillOldStateChanges","previousEvent","currentEvent","isFirstEvent","oldState","UNDETERMINED","isGestureStateEvent","state","validateStateTransitions","stringify","JSON","errorMsgWithBothEvents","description","errorMsgWithCurrentEvent","BEGAN","fillMissingDefaultsFor","handlerType","handlerTag","isDiscreteHandler","fillMissingStatesTransitions","events","_events","lastEvent","length","firstEvent","shouldDuplicateFirstEvent","hasState","duplicated","unshift","shouldDuplicateLastEvent","END","FAILED","CANCELLED","push","isWithoutState","noEventsLeft","trueFn","fillEventsForCurrentState","shouldConsumeEvent","shouldTransitionToNextState","peekCurrentEvent","peekNextEvent","consumeCurrentEvent","shift","nextEvent","currentRequiredState","REQUIRED_EVENTS","currentStateIdx","eventData","shouldUseEvent","transformedEvents","ACTIVE","hasAllStates","iterations","nextRequiredState","e","getHandlerData","gesture","emitEvent","eventName","args","emit","handlerName","gestureHandlerComponent","props","fireGestureHandler","eventList","_","map","lastSentEvent","hasChangedState","getByGestureTestId","testID","handler","Error"],"mappings":"AAAA,OAAOA,SAAP,MAAsB,WAAtB;AACA,SAASC,kBAAT,QAAmC,cAAnC;AAEA,SAGEC,gBAHF,QAIO,gCAJP;AAKA,SAGEC,qBAHF,QAIO,qCAJP;AAYA,SAASC,WAAT,QAAyC,6BAAzC;AAOA,SAASC,mBAAT,QAAoC,6BAApC;AACA,SAGEC,oBAHF,QAIO,oCAJP;AAKA,SAGEC,qBAHF,QAIO,qCAJP;AAKA,SAGEC,cAHF,QAIO,8BAJP;AAKA,SAGEC,gBAHF,QAIO,gCAJP;AAKA,SA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D,MAEO;AACL4D,MAAAA,SAAS,CAAC,uBAAD,EAA0B5D,KAA1B,CAAT;AACD;;AACDuE,IAAAA,aAAa,GAAGvE,KAAhB;AACD;AACF;AAED,OAAO,SAASyE,kBAAT,CAA4BC,MAA5B,EAA4C;AACjD,QAAMC,OAAO,GAAGlH,mBAAmB,CAACiH,MAAD,CAAnC;;AACA,MAAIC,OAAO,KAAK,IAAhB,EAAsB;AACpB,UAAM,IAAIC,KAAJ,CAAW,qBAAoBF,MAAO,mBAAtC,CAAN;AACD;;AACD,SAAOC,OAAP;AACD","sourcesContent":["import invariant from 'invariant';\nimport { DeviceEventEmitter } from 'react-native';\nimport { ReactTestInstance } from 'react-test-renderer';\nimport {\n FlingGestureHandler,\n FlingGestureHandlerEventPayload,\n flingHandlerName,\n} from './handlers/FlingGestureHandler';\nimport {\n ForceTouchGestureHandler,\n ForceTouchGestureHandlerEventPayload,\n forceTouchHandlerName,\n} from './handlers/ForceTouchGestureHandler';\nimport {\n BaseGestureHandlerProps,\n GestureEvent,\n HandlerStateChangeEvent,\n} from './handlers/gestureHandlerCommon';\nimport { FlingGesture } from './handlers/gestures/flingGesture';\nimport { ForceTouchGesture } from './handlers/gestures/forceTouchGesture';\nimport { BaseGesture, GestureType } from './handlers/gestures/gesture';\nimport { LongPressGesture } from './handlers/gestures/longPressGesture';\nimport { NativeGesture } from './handlers/gestures/nativeGesture';\nimport { PanGesture } from './handlers/gestures/panGesture';\nimport { PinchGesture } from './handlers/gestures/pinchGesture';\nimport { RotationGesture } from './handlers/gestures/rotationGesture';\nimport { TapGesture } from './handlers/gestures/tapGesture';\nimport { findHandlerByTestID } from './handlers/handlersRegistry';\nimport {\n LongPressGestureHandler,\n LongPressGestureHandlerEventPayload,\n longPressHandlerName,\n} from './handlers/LongPressGestureHandler';\nimport {\n NativeViewGestureHandler,\n NativeViewGestureHandlerPayload,\n nativeViewHandlerName,\n} from './handlers/NativeViewGestureHandler';\nimport {\n PanGestureHandler,\n PanGestureHandlerEventPayload,\n panHandlerName,\n} from './handlers/PanGestureHandler';\nimport {\n PinchGestureHandler,\n PinchGestureHandlerEventPayload,\n pinchHandlerName,\n} from './handlers/PinchGestureHandler';\nimport {\n RotationGestureHandler,\n RotationGestureHandlerEventPayload,\n rotationHandlerName,\n} from './handlers/RotationGestureHandler';\nimport {\n TapGestureHandler,\n TapGestureHandlerEventPayload,\n tapHandlerName,\n} from './handlers/TapGestureHandler';\nimport { State } from './State';\nimport { hasProperty, withPrevAndCurrent } from './utils';\n\n// load fireEvent conditionally, so RNGH may be used in setups without testing-library\nlet fireEvent = (\n _element: ReactTestInstance,\n _name: string,\n ..._data: any[]\n) => {\n // NOOP\n};\n\ntry {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n fireEvent = require('@testing-library/react-native').fireEvent;\n} catch (_e) {\n // do nothing if not available\n}\n\ntype GestureHandlerTestEvent<\n TEventPayload extends Record<string, unknown> = Record<string, unknown>\n> = (\n | GestureEvent<TEventPayload>\n | HandlerStateChangeEvent<TEventPayload>\n)['nativeEvent'];\n\ntype HandlerNames = keyof DefaultEventsMapping;\n\ntype WithNumberOfPointers<T> = {\n [P in keyof T]: T[P] & { numberOfPointers: number };\n};\ntype DefaultEventsMapping = WithNumberOfPointers<{\n [flingHandlerName]: FlingGestureHandlerEventPayload;\n [forceTouchHandlerName]: ForceTouchGestureHandlerEventPayload;\n [longPressHandlerName]: LongPressGestureHandlerEventPayload;\n [nativeViewHandlerName]: NativeViewGestureHandlerPayload;\n [panHandlerName]: PanGestureHandlerEventPayload;\n [pinchHandlerName]: PinchGestureHandlerEventPayload;\n [rotationHandlerName]: RotationGestureHandlerEventPayload;\n [tapHandlerName]: TapGestureHandlerEventPayload;\n}>;\n\nconst handlersDefaultEvents: DefaultEventsMapping = {\n [flingHandlerName]: {\n x: 0,\n y: 0,\n absoluteX: 0,\n absoluteY: 0,\n numberOfPointers: 1,\n },\n [forceTouchHandlerName]: {\n x: 0,\n y: 0,\n absoluteX: 0,\n absoluteY: 0,\n force: 1,\n numberOfPointers: 1,\n },\n [longPressHandlerName]: {\n x: 0,\n y: 0,\n absoluteX: 0,\n absoluteY: 0,\n duration: 100,\n numberOfPointers: 1,\n },\n [nativeViewHandlerName]: {\n pointerInside: true,\n numberOfPointers: 1,\n },\n [panHandlerName]: {\n x: 0,\n y: 0,\n absoluteX: 0,\n absoluteY: 0,\n translationX: 100,\n translationY: 0,\n velocityX: 3,\n velocityY: 0,\n numberOfPointers: 1,\n },\n [pinchHandlerName]: {\n focalX: 0,\n focalY: 0,\n scale: 2,\n velocity: 1,\n numberOfPointers: 2,\n },\n [rotationHandlerName]: {\n anchorX: 0,\n anchorY: 0,\n rotation: 3.14,\n velocity: 2,\n numberOfPointers: 2,\n },\n [tapHandlerName]: {\n x: 0,\n y: 0,\n absoluteX: 0,\n absoluteY: 0,\n numberOfPointers: 1,\n },\n};\n\nfunction isGesture(\n componentOrGesture: ReactTestInstance | GestureType\n): componentOrGesture is GestureType {\n return componentOrGesture instanceof BaseGesture;\n}\n\ninterface WrappedGestureHandlerTestEvent {\n nativeEvent: GestureHandlerTestEvent;\n}\nfunction wrapWithNativeEvent(\n event: GestureHandlerTestEvent\n): WrappedGestureHandlerTestEvent {\n return { nativeEvent: event };\n}\n\nfunction fillOldStateChanges(\n previousEvent: GestureHandlerTestEvent | null,\n currentEvent: Omit<GestureHandlerTestEvent, 'oldState'>\n): GestureHandlerTestEvent {\n const isFirstEvent = previousEvent === null;\n if (isFirstEvent) {\n return {\n oldState: State.UNDETERMINED,\n ...currentEvent,\n } as GestureHandlerTestEvent;\n }\n\n const isGestureStateEvent = previousEvent.state !== currentEvent.state;\n if (isGestureStateEvent) {\n return {\n oldState: previousEvent?.state,\n ...currentEvent,\n } as GestureHandlerTestEvent;\n } else {\n return currentEvent as GestureHandlerTestEvent;\n }\n}\n\ntype EventWithStates = Partial<\n Pick<GestureHandlerTestEvent, 'oldState' | 'state'>\n>;\nfunction validateStateTransitions(\n previousEvent: EventWithStates | null,\n currentEvent: EventWithStates\n) {\n function stringify(event: Record<string, unknown> | null) {\n return JSON.stringify(event, null, 2);\n }\n function errorMsgWithBothEvents(description: string) {\n return `${description}, invalid event: ${stringify(\n currentEvent\n )}, previous event: ${stringify(previousEvent)}`;\n }\n\n function errorMsgWithCurrentEvent(description: string) {\n return `${description}, invalid event: ${stringify(currentEvent)}`;\n }\n\n invariant(\n hasProperty(currentEvent, 'state'),\n errorMsgWithCurrentEvent('every event must have state')\n );\n\n const isFirstEvent = previousEvent === null;\n if (isFirstEvent) {\n invariant(\n currentEvent.state === State.BEGAN,\n errorMsgWithCurrentEvent('first event must have BEGAN state')\n );\n }\n\n if (previousEvent !== null) {\n if (previousEvent.state !== currentEvent.state) {\n invariant(\n hasProperty(currentEvent, 'oldState'),\n errorMsgWithCurrentEvent(\n 'when state changes, oldState field should be present'\n )\n );\n invariant(\n currentEvent.oldState === previousEvent.state,\n errorMsgWithBothEvents(\n \"when state changes, oldState should be the same as previous event' state\"\n )\n );\n }\n }\n\n return currentEvent;\n}\n\ntype EventWithoutStates = Omit<GestureHandlerTestEvent, 'oldState' | 'state'>;\ninterface HandlerInfo {\n handlerType: HandlerNames;\n handlerTag: number;\n}\nfunction fillMissingDefaultsFor({\n handlerType,\n handlerTag,\n}: HandlerInfo): (\n event: Partial<GestureHandlerTestEvent>\n) => EventWithoutStates {\n return (event) => {\n return {\n ...handlersDefaultEvents[handlerType],\n ...event,\n handlerTag,\n };\n };\n}\n\nfunction isDiscreteHandler(handlerType: HandlerNames) {\n return (\n handlerType === 'TapGestureHandler' ||\n handlerType === 'LongPressGestureHandler'\n );\n}\n\nfunction fillMissingStatesTransitions(\n events: EventWithoutStates[],\n isDiscreteHandler: boolean\n): EventWithoutStates[] {\n type Event = EventWithoutStates | null;\n const _events = [...events];\n const lastEvent = _events[_events.length - 1] ?? null;\n const firstEvent = _events[0] ?? null;\n\n const shouldDuplicateFirstEvent =\n !isDiscreteHandler && !hasState(State.BEGAN)(firstEvent);\n if (shouldDuplicateFirstEvent) {\n const duplicated = { ...firstEvent, state: State.BEGAN };\n // @ts-ignore badly typed, property may exist and we don't want to copy it\n delete duplicated.oldState;\n _events.unshift(duplicated);\n }\n\n const shouldDuplicateLastEvent =\n !hasState(State.END)(lastEvent) ||\n !hasState(State.FAILED)(lastEvent) ||\n !hasState(State.CANCELLED)(lastEvent);\n\n if (shouldDuplicateLastEvent) {\n const duplicated = { ...lastEvent, state: State.END };\n // @ts-ignore badly typed, property may exist and we don't want to copy it\n delete duplicated.oldState;\n _events.push(duplicated);\n }\n\n function isWithoutState(event: Event) {\n return event !== null && !hasProperty(event, 'state');\n }\n function hasState(state: State) {\n return (event: Event) => event !== null && event.state === state;\n }\n function noEventsLeft(event: Event) {\n return event === null;\n }\n\n function trueFn() {\n return true;\n }\n interface Args {\n shouldConsumeEvent?: (event: Event) => boolean;\n shouldTransitionToNextState?: (nextEvent: Event) => boolean;\n }\n function fillEventsForCurrentState({\n shouldConsumeEvent = trueFn,\n shouldTransitionToNextState = trueFn,\n }: Args) {\n function peekCurrentEvent(): Event {\n return _events[0] ?? null;\n }\n function peekNextEvent(): Event {\n return _events[1] ?? null;\n }\n function consumeCurrentEvent() {\n _events.shift();\n }\n const currentEvent = peekCurrentEvent();\n const nextEvent = peekNextEvent();\n const currentRequiredState = REQUIRED_EVENTS[currentStateIdx];\n\n let eventData = {};\n const shouldUseEvent = shouldConsumeEvent(currentEvent);\n if (shouldUseEvent) {\n eventData = currentEvent!;\n consumeCurrentEvent();\n }\n transformedEvents.push({ state: currentRequiredState, ...eventData });\n if (shouldTransitionToNextState(nextEvent)) {\n currentStateIdx++;\n }\n }\n\n const REQUIRED_EVENTS = [State.BEGAN, State.ACTIVE, State.END];\n\n let currentStateIdx = 0;\n const transformedEvents: EventWithoutStates[] = [];\n let hasAllStates;\n let iterations = 0;\n do {\n const nextRequiredState = REQUIRED_EVENTS[currentStateIdx];\n if (nextRequiredState === State.BEGAN) {\n fillEventsForCurrentState({\n shouldConsumeEvent: (e: Event) =>\n isWithoutState(e) || hasState(State.BEGAN)(e),\n });\n } else if (nextRequiredState === State.ACTIVE) {\n const shouldConsumeEvent = (e: Event) =>\n isWithoutState(e) || hasState(State.ACTIVE)(e);\n const shouldTransitionToNextState = (nextEvent: Event) =>\n noEventsLeft(nextEvent) ||\n hasState(State.END)(nextEvent) ||\n hasState(State.FAILED)(nextEvent) ||\n hasState(State.CANCELLED)(nextEvent);\n\n fillEventsForCurrentState({\n shouldConsumeEvent,\n shouldTransitionToNextState,\n });\n } else if (nextRequiredState === State.END) {\n fillEventsForCurrentState({});\n }\n hasAllStates = currentStateIdx === REQUIRED_EVENTS.length;\n\n invariant(\n iterations++ <= 500,\n 'exceeded max number of iterations, please report a bug in RNGH repository with your test case'\n );\n } while (!hasAllStates);\n\n return transformedEvents;\n}\n\ntype EventEmitter = (\n eventName: string,\n args: { nativeEvent: GestureHandlerTestEvent }\n) => void;\ninterface HandlerData {\n emitEvent: EventEmitter;\n handlerType: HandlerNames;\n handlerTag: number;\n}\nfunction getHandlerData(\n componentOrGesture: ReactTestInstance | GestureType\n): HandlerData {\n if (isGesture(componentOrGesture)) {\n const gesture = componentOrGesture;\n return {\n emitEvent: (eventName, args) => {\n DeviceEventEmitter.emit(eventName, args.nativeEvent);\n },\n handlerType: gesture.handlerName as HandlerNames,\n handlerTag: gesture.handlerTag,\n };\n }\n const gestureHandlerComponent = componentOrGesture;\n return {\n emitEvent: (eventName, args) => {\n fireEvent(gestureHandlerComponent, eventName, args);\n },\n handlerType: gestureHandlerComponent.props.handlerType as HandlerNames,\n handlerTag: gestureHandlerComponent.props.handlerTag as number,\n };\n}\ntype AllGestures =\n | TapGesture\n | PanGesture\n | LongPressGesture\n | RotationGesture\n | PinchGesture\n | FlingGesture\n | ForceTouchGesture\n | NativeGesture;\n\ntype AllHandlers =\n | TapGestureHandler\n | PanGestureHandler\n | LongPressGestureHandler\n | RotationGestureHandler\n | PinchGestureHandler\n | FlingGestureHandler\n | ForceTouchGestureHandler\n | NativeViewGestureHandler;\n\n// prettier-ignore\ntype ClassComponentConstructor<P> = new (props: P) => React.Component<P, any, any>;\n\ntype ExtractPayloadFromProps<T> = T extends BaseGestureHandlerProps<\n infer TPayload\n>\n ? TPayload\n : never;\n\ntype ExtractConfig<T> = T extends BaseGesture<infer TGesturePayload>\n ? TGesturePayload\n : T extends ClassComponentConstructor<infer THandlerProps>\n ? ExtractPayloadFromProps<THandlerProps>\n : Record<string, unknown>;\n\nexport function fireGestureHandler<THandler extends AllGestures | AllHandlers>(\n componentOrGesture: ReactTestInstance | GestureType,\n eventList: Partial<GestureHandlerTestEvent<ExtractConfig<THandler>>>[] = []\n): void {\n const { emitEvent, handlerType, handlerTag } = getHandlerData(\n componentOrGesture\n );\n\n let _ = fillMissingStatesTransitions(\n eventList,\n isDiscreteHandler(handlerType)\n );\n _ = _.map(fillMissingDefaultsFor({ handlerTag, handlerType }));\n _ = withPrevAndCurrent(_, fillOldStateChanges);\n _ = withPrevAndCurrent(_, validateStateTransitions);\n // @ts-ignore TODO\n _ = _.map(wrapWithNativeEvent);\n\n const events = (_ as unknown) as WrappedGestureHandlerTestEvent[];\n\n const firstEvent = events.shift()!;\n\n emitEvent('onGestureHandlerStateChange', firstEvent);\n let lastSentEvent = firstEvent;\n for (const event of events) {\n const hasChangedState =\n lastSentEvent.nativeEvent.state !== event.nativeEvent.state;\n\n if (hasChangedState) {\n emitEvent('onGestureHandlerStateChange', event);\n } else {\n emitEvent('onGestureHandlerEvent', event);\n }\n lastSentEvent = event;\n }\n}\n\nexport function getByGestureTestId(testID: string) {\n const handler = findHandlerByTestID(testID);\n if (handler === null) {\n throw new Error(`Handler with id: '${testID}' cannot be found`);\n }\n return handler;\n}\n"]}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @flow strict-local
|
|
3
|
-
* @format
|
|
4
|
-
*/
|
|
5
|
-
/* eslint-disable */
|
|
6
|
-
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
7
|
-
import type { HostComponent } from 'react-native';
|
|
8
|
-
import type { ColorValue } from 'react-native/Libraries/StyleSheet';
|
|
9
|
-
import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';
|
|
10
|
-
import type { Int32 } from 'react-native/Libraries/Types/CodegenTypes';
|
|
11
|
-
|
|
12
|
-
type NativeProps = $ReadOnly<{|
|
|
13
|
-
...ViewProps, // This is required.
|
|
14
|
-
exclusive: boolean,
|
|
15
|
-
foreground: boolean,
|
|
16
|
-
borderless: boolean,
|
|
17
|
-
enabled: boolean,
|
|
18
|
-
rippleColor: ColorValue,
|
|
19
|
-
rippleRadius: Int32,
|
|
20
|
-
|}>;
|
|
21
|
-
|
|
22
|
-
type ComponentType = HostComponent<NativeProps>;
|
|
23
|
-
|
|
24
|
-
export default (codegenNativeComponent<NativeProps>(
|
|
25
|
-
'RNGestureHandlerButton',
|
|
26
|
-
{}
|
|
27
|
-
): ComponentType);
|