react-native-gesture-handler 2.18.1 → 2.20.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -0
- package/android/build.gradle +11 -29
- package/android/fabric/src/main/java/com/swmansion/gesturehandler/ReactContextExtensions.kt +1 -1
- package/android/paper/src/main/java/com/swmansion/gesturehandler/ReactContextExtensions.kt +1 -1
- package/android/src/main/AndroidManifest.xml +1 -3
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +21 -21
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +2 -2
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureUtils.kt +1 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/HoverGestureHandler.kt +16 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/LongPressGestureHandler.kt +80 -4
- package/android/src/main/java/com/swmansion/gesturehandler/core/PanGestureHandler.kt +8 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/PinchGestureHandler.kt +2 -1
- package/android/src/main/java/com/swmansion/gesturehandler/core/ScaleGestureDetector.java +10 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/StylusData.kt +103 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/Vector.kt +2 -2
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +24 -15
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +3 -0
- package/android/src/main/java/com/swmansion/gesturehandler/react/eventbuilders/HoverGestureHandlerEventDataBuilder.kt +7 -0
- package/android/src/main/java/com/swmansion/gesturehandler/react/eventbuilders/PanGestureHandlerEventDataBuilder.kt +7 -0
- package/android/src/main/jni/CMakeLists.txt +18 -9
- package/apple/Handlers/RNFlingHandler.h +1 -0
- package/apple/Handlers/RNFlingHandler.m +153 -19
- package/apple/Handlers/RNHoverHandler.m +44 -2
- package/apple/Handlers/RNLongPressHandler.m +111 -20
- package/apple/Handlers/RNManualHandler.m +53 -29
- package/apple/Handlers/RNNativeViewHandler.mm +22 -15
- package/apple/Handlers/RNPanHandler.m +57 -7
- package/apple/Handlers/RNRotationHandler.m +1 -1
- package/apple/RNGHStylusData.h +77 -0
- package/apple/RNGHStylusData.m +37 -0
- package/apple/RNGHUIKit.h +2 -0
- package/apple/RNGHVector.h +31 -0
- package/apple/RNGHVector.m +67 -0
- package/apple/RNGestureHandler.h +7 -0
- package/apple/{RNGestureHandler.m → RNGestureHandler.mm} +63 -1
- package/apple/RNGestureHandlerButtonComponentView.mm +41 -0
- package/apple/RNGestureHandlerDirection.h +25 -0
- package/apple/RNGestureHandlerEvents.h +3 -1
- package/apple/RNGestureHandlerEvents.m +11 -3
- package/lib/commonjs/PointerType.js +2 -1
- package/lib/commonjs/PointerType.js.map +1 -1
- package/lib/commonjs/components/GestureButtons.js +5 -1
- package/lib/commonjs/components/GestureButtons.js.map +1 -1
- package/lib/commonjs/components/GestureComponents.js.map +1 -1
- package/lib/commonjs/components/Pressable/Pressable.js +66 -78
- package/lib/commonjs/components/Pressable/Pressable.js.map +1 -1
- package/lib/commonjs/components/Pressable/index.js +0 -8
- package/lib/commonjs/components/Pressable/index.js.map +1 -1
- package/lib/commonjs/components/Pressable/utils.js +1 -23
- package/lib/commonjs/components/Pressable/utils.js.map +1 -1
- package/lib/commonjs/components/ReanimatedSwipeable.js +60 -41
- package/lib/commonjs/components/ReanimatedSwipeable.js.map +1 -1
- package/lib/commonjs/handlers/GestureHandlerEventPayload.js +4 -0
- package/lib/commonjs/handlers/LongPressGestureHandler.js +1 -1
- package/lib/commonjs/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/commonjs/handlers/createHandler.js +2 -1
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/utils.js +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector/utils.js.map +1 -1
- package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/hoverGesture.js.map +1 -1
- package/lib/commonjs/handlers/gestures/longPressGesture.js +10 -0
- package/lib/commonjs/handlers/gestures/longPressGesture.js.map +1 -1
- package/lib/commonjs/jestUtils/jestUtils.js +12 -4
- package/lib/commonjs/jestUtils/jestUtils.js.map +1 -1
- package/lib/commonjs/mocks.js +16 -3
- package/lib/commonjs/mocks.js.map +1 -1
- package/lib/commonjs/utils.js +4 -0
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/constants.js +3 -3
- package/lib/commonjs/web/constants.js.map +1 -1
- package/lib/commonjs/web/handlers/GestureHandler.js +2 -3
- package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/HoverGestureHandler.js +18 -1
- package/lib/commonjs/web/handlers/HoverGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/LongPressGestureHandler.js +43 -9
- package/lib/commonjs/web/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/NativeViewGestureHandler.js +14 -3
- package/lib/commonjs/web/handlers/NativeViewGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/PanGestureHandler.js +12 -1
- package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/commonjs/web/interfaces.js.map +1 -1
- package/lib/commonjs/web/tools/EventManager.js.map +1 -1
- package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js +55 -11
- package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/commonjs/web/tools/KeyboardEventManager.js +110 -0
- package/lib/commonjs/web/tools/KeyboardEventManager.js.map +1 -0
- package/lib/commonjs/web/tools/PointerEventManager.js +3 -37
- package/lib/commonjs/web/tools/PointerEventManager.js.map +1 -1
- package/lib/commonjs/web/tools/Vector.js +4 -2
- package/lib/commonjs/web/tools/Vector.js.map +1 -1
- package/lib/commonjs/web/utils.js +187 -13
- package/lib/commonjs/web/utils.js.map +1 -1
- package/lib/module/PointerType.js +2 -1
- package/lib/module/PointerType.js.map +1 -1
- package/lib/module/components/GestureButtons.js +5 -1
- package/lib/module/components/GestureButtons.js.map +1 -1
- package/lib/module/components/GestureComponents.js.map +1 -1
- package/lib/module/components/Pressable/Pressable.js +67 -78
- package/lib/module/components/Pressable/Pressable.js.map +1 -1
- package/lib/module/components/Pressable/index.js +0 -1
- package/lib/module/components/Pressable/index.js.map +1 -1
- package/lib/module/components/Pressable/utils.js +1 -22
- package/lib/module/components/Pressable/utils.js.map +1 -1
- package/lib/module/components/ReanimatedSwipeable.js +58 -37
- package/lib/module/components/ReanimatedSwipeable.js.map +1 -1
- package/lib/module/handlers/GestureHandlerEventPayload.js +1 -1
- package/lib/module/handlers/LongPressGestureHandler.js +1 -1
- package/lib/module/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/module/handlers/createHandler.js +2 -1
- package/lib/module/handlers/createHandler.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector/utils.js +2 -2
- package/lib/module/handlers/gestures/GestureDetector/utils.js.map +1 -1
- package/lib/module/handlers/gestures/gesture.js.map +1 -1
- package/lib/module/handlers/gestures/hoverGesture.js.map +1 -1
- package/lib/module/handlers/gestures/longPressGesture.js +10 -0
- package/lib/module/handlers/gestures/longPressGesture.js.map +1 -1
- package/lib/module/jestUtils/jestUtils.js +12 -4
- package/lib/module/jestUtils/jestUtils.js.map +1 -1
- package/lib/module/mocks.js +13 -3
- package/lib/module/mocks.js.map +1 -1
- package/lib/module/utils.js +1 -0
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/constants.js +1 -1
- package/lib/module/web/constants.js.map +1 -1
- package/lib/module/web/handlers/GestureHandler.js +2 -3
- package/lib/module/web/handlers/GestureHandler.js.map +1 -1
- package/lib/module/web/handlers/HoverGestureHandler.js +18 -1
- package/lib/module/web/handlers/HoverGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/LongPressGestureHandler.js +43 -9
- package/lib/module/web/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/NativeViewGestureHandler.js +14 -3
- package/lib/module/web/handlers/NativeViewGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/PanGestureHandler.js +12 -1
- package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/module/web/interfaces.js.map +1 -1
- package/lib/module/web/tools/EventManager.js.map +1 -1
- package/lib/module/web/tools/GestureHandlerWebDelegate.js +54 -10
- package/lib/module/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/module/web/tools/KeyboardEventManager.js +96 -0
- package/lib/module/web/tools/KeyboardEventManager.js.map +1 -0
- package/lib/module/web/tools/PointerEventManager.js +4 -38
- package/lib/module/web/tools/PointerEventManager.js.map +1 -1
- package/lib/module/web/tools/Vector.js +5 -3
- package/lib/module/web/tools/Vector.js.map +1 -1
- package/lib/module/web/utils.js +184 -13
- package/lib/module/web/utils.js.map +1 -1
- package/lib/typescript/PointerType.d.ts +2 -1
- package/lib/typescript/components/GestureComponents.d.ts +1 -1
- package/lib/typescript/components/Pressable/index.d.ts +1 -1
- package/lib/typescript/components/Pressable/utils.d.ts +3 -5
- package/lib/typescript/handlers/GestureHandlerEventPayload.d.ts +35 -0
- package/lib/typescript/handlers/LongPressGestureHandler.d.ts +5 -1
- package/lib/typescript/handlers/gestures/gesture.d.ts +2 -2
- package/lib/typescript/handlers/gestures/hoverGesture.d.ts +1 -6
- package/lib/typescript/handlers/gestures/longPressGesture.d.ts +5 -0
- package/lib/typescript/handlers/handlersRegistry.d.ts +1 -1
- package/lib/typescript/jestUtils/jestUtils.d.ts +1 -1
- package/lib/typescript/mocks.d.ts +4 -3
- package/lib/typescript/utils.d.ts +1 -0
- package/lib/typescript/web/constants.d.ts +1 -1
- package/lib/typescript/web/handlers/GestureHandler.d.ts +1 -1
- package/lib/typescript/web/handlers/HoverGestureHandler.d.ts +2 -0
- package/lib/typescript/web/handlers/LongPressGestureHandler.d.ts +3 -0
- package/lib/typescript/web/handlers/NativeViewGestureHandler.d.ts +1 -0
- package/lib/typescript/web/handlers/PanGestureHandler.d.ts +3 -1
- package/lib/typescript/web/interfaces.d.ts +9 -4
- package/lib/typescript/web/tools/EventManager.d.ts +2 -2
- package/lib/typescript/web/tools/GestureHandlerDelegate.d.ts +1 -0
- package/lib/typescript/web/tools/GestureHandlerWebDelegate.d.ts +6 -0
- package/lib/typescript/web/tools/KeyboardEventManager.d.ts +13 -0
- package/lib/typescript/web/utils.d.ts +2 -1
- package/package.json +3 -3
- package/src/PointerType.ts +1 -0
- package/src/components/GestureButtons.tsx +2 -1
- package/src/components/GestureComponents.tsx +1 -1
- package/src/components/Pressable/Pressable.tsx +77 -70
- package/src/components/Pressable/index.ts +1 -1
- package/src/components/Pressable/utils.ts +5 -49
- package/src/components/ReanimatedSwipeable.tsx +70 -47
- package/src/handlers/GestureHandlerEventPayload.ts +42 -0
- package/src/handlers/LongPressGestureHandler.ts +6 -0
- package/src/handlers/createHandler.tsx +1 -0
- package/src/handlers/gestures/GestureDetector/utils.ts +2 -2
- package/src/handlers/gestures/gesture.ts +3 -1
- package/src/handlers/gestures/hoverGesture.ts +1 -7
- package/src/handlers/gestures/longPressGesture.ts +9 -0
- package/src/jestUtils/jestUtils.ts +9 -1
- package/src/{mocks.ts → mocks.tsx} +8 -3
- package/src/utils.ts +2 -0
- package/src/web/constants.ts +1 -1
- package/src/web/handlers/GestureHandler.ts +4 -2
- package/src/web/handlers/HoverGestureHandler.ts +16 -2
- package/src/web/handlers/LongPressGestureHandler.ts +49 -10
- package/src/web/handlers/NativeViewGestureHandler.ts +14 -4
- package/src/web/handlers/PanGestureHandler.ts +14 -1
- package/src/web/interfaces.ts +10 -4
- package/src/web/tools/EventManager.ts +2 -4
- package/src/web/tools/GestureHandlerDelegate.ts +1 -0
- package/src/web/tools/GestureHandlerWebDelegate.ts +67 -10
- package/src/web/tools/KeyboardEventManager.ts +91 -0
- package/src/web/tools/PointerEventManager.ts +2 -38
- package/src/web/tools/Vector.ts +4 -3
- package/src/web/utils.ts +188 -13
- package/lib/commonjs/web/tools/TouchEventManager.js +0 -164
- package/lib/commonjs/web/tools/TouchEventManager.js.map +0 -1
- package/lib/module/web/tools/TouchEventManager.js +0 -149
- package/lib/module/web/tools/TouchEventManager.js.map +0 -1
- package/lib/typescript/web/tools/TouchEventManager.d.ts +0 -11
- package/src/web/tools/TouchEventManager.ts +0 -175
@@ -199,6 +199,26 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
|
|
199
199
|
props: SwipeableProps,
|
200
200
|
ref: ForwardedRef<SwipeableMethods>
|
201
201
|
) {
|
202
|
+
const {
|
203
|
+
leftThreshold,
|
204
|
+
rightThreshold,
|
205
|
+
onSwipeableOpenStartDrag,
|
206
|
+
onSwipeableCloseStartDrag,
|
207
|
+
enableTrackpadTwoFingerGesture,
|
208
|
+
enabled,
|
209
|
+
containerStyle,
|
210
|
+
childrenContainerStyle,
|
211
|
+
animationOptions,
|
212
|
+
overshootLeft,
|
213
|
+
overshootRight,
|
214
|
+
onSwipeableWillOpen,
|
215
|
+
onSwipeableWillClose,
|
216
|
+
onSwipeableOpen,
|
217
|
+
onSwipeableClose,
|
218
|
+
testID,
|
219
|
+
...remainingProps
|
220
|
+
} = props;
|
221
|
+
|
202
222
|
const rowState = useSharedValue<number>(0);
|
203
223
|
|
204
224
|
const userDrag = useSharedValue<number>(0);
|
@@ -240,8 +260,8 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
|
|
240
260
|
overshootFriction = defaultProps.overshootFriction,
|
241
261
|
} = props;
|
242
262
|
|
243
|
-
const overshootLeftProp =
|
244
|
-
const overshootRightProp =
|
263
|
+
const overshootLeftProp = overshootLeft;
|
264
|
+
const overshootRightProp = overshootRight;
|
245
265
|
|
246
266
|
const calculateCurrentOffset = useCallback(() => {
|
247
267
|
'worklet';
|
@@ -317,45 +337,40 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
|
|
317
337
|
|
318
338
|
const dispatchImmediateEvents = useCallback(
|
319
339
|
(fromValue: number, toValue: number) => {
|
320
|
-
if (toValue > 0 &&
|
321
|
-
|
322
|
-
} else if (toValue < 0 &&
|
323
|
-
|
324
|
-
} else if (
|
340
|
+
if (toValue > 0 && onSwipeableWillOpen) {
|
341
|
+
onSwipeableWillOpen('left');
|
342
|
+
} else if (toValue < 0 && onSwipeableWillOpen) {
|
343
|
+
onSwipeableWillOpen('right');
|
344
|
+
} else if (onSwipeableWillClose) {
|
325
345
|
const closingDirection = fromValue > 0 ? 'left' : 'right';
|
326
|
-
|
346
|
+
onSwipeableWillClose(closingDirection);
|
327
347
|
}
|
328
348
|
},
|
329
|
-
[
|
330
|
-
props,
|
331
|
-
props.onSwipeableWillClose,
|
332
|
-
props.onSwipeableWillOpen,
|
333
|
-
swipeableMethods,
|
334
|
-
]
|
349
|
+
[onSwipeableWillClose, onSwipeableWillOpen]
|
335
350
|
);
|
336
351
|
|
337
352
|
const dispatchEndEvents = useCallback(
|
338
353
|
(fromValue: number, toValue: number) => {
|
339
|
-
if (toValue > 0 &&
|
340
|
-
|
341
|
-
} else if (toValue < 0 &&
|
342
|
-
|
343
|
-
} else if (
|
354
|
+
if (toValue > 0 && onSwipeableOpen) {
|
355
|
+
onSwipeableOpen('left', swipeableMethods.current);
|
356
|
+
} else if (toValue < 0 && onSwipeableOpen) {
|
357
|
+
onSwipeableOpen('right', swipeableMethods.current);
|
358
|
+
} else if (onSwipeableClose) {
|
344
359
|
const closingDirection = fromValue > 0 ? 'left' : 'right';
|
345
|
-
|
360
|
+
onSwipeableClose(closingDirection, swipeableMethods.current);
|
346
361
|
}
|
347
362
|
},
|
348
|
-
[
|
363
|
+
[onSwipeableClose, onSwipeableOpen]
|
349
364
|
);
|
350
365
|
|
351
|
-
const animationOptionsProp =
|
366
|
+
const animationOptionsProp = animationOptions;
|
352
367
|
|
353
368
|
const animateRow = useCallback(
|
354
369
|
(fromValue: number, toValue: number, velocityX?: number) => {
|
355
370
|
'worklet';
|
356
371
|
rowState.value = Math.sign(toValue);
|
357
372
|
|
358
|
-
const
|
373
|
+
const translationSpringConfig = {
|
359
374
|
duration: 1000,
|
360
375
|
dampingRatio: 0.9,
|
361
376
|
stiffness: 500,
|
@@ -364,9 +379,14 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
|
|
364
379
|
...animationOptionsProp,
|
365
380
|
};
|
366
381
|
|
382
|
+
const progressSpringConfig = {
|
383
|
+
...translationSpringConfig,
|
384
|
+
velocity: 0,
|
385
|
+
};
|
386
|
+
|
367
387
|
appliedTranslation.value = withSpring(
|
368
388
|
toValue,
|
369
|
-
|
389
|
+
translationSpringConfig,
|
370
390
|
(isFinished) => {
|
371
391
|
if (isFinished) {
|
372
392
|
runOnJS(dispatchEndEvents)(fromValue, toValue);
|
@@ -376,23 +396,27 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
|
|
376
396
|
|
377
397
|
const progressTarget = toValue === 0 ? 0 : 1;
|
378
398
|
|
379
|
-
// Velocity is in px, while progress is in %
|
380
|
-
springConfig.velocity = 0;
|
381
|
-
|
382
399
|
showLeftProgress.value =
|
383
|
-
leftWidth.value > 0
|
400
|
+
leftWidth.value > 0
|
401
|
+
? withSpring(progressTarget, progressSpringConfig)
|
402
|
+
: 0;
|
384
403
|
showRightProgress.value =
|
385
|
-
rightWidth.value > 0
|
404
|
+
rightWidth.value > 0
|
405
|
+
? withSpring(progressTarget, progressSpringConfig)
|
406
|
+
: 0;
|
386
407
|
|
387
408
|
runOnJS(dispatchImmediateEvents)(fromValue, toValue);
|
388
409
|
},
|
389
410
|
[
|
390
|
-
|
411
|
+
rowState,
|
412
|
+
animationOptionsProp,
|
391
413
|
appliedTranslation,
|
392
|
-
|
414
|
+
showLeftProgress,
|
415
|
+
leftWidth.value,
|
416
|
+
showRightProgress,
|
417
|
+
rightWidth.value,
|
393
418
|
dispatchImmediateEvents,
|
394
|
-
|
395
|
-
rowState,
|
419
|
+
dispatchEndEvents,
|
396
420
|
]
|
397
421
|
);
|
398
422
|
|
@@ -483,8 +507,8 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
|
|
483
507
|
</Animated.View>
|
484
508
|
);
|
485
509
|
|
486
|
-
const leftThresholdProp =
|
487
|
-
const rightThresholdProp =
|
510
|
+
const leftThresholdProp = leftThreshold;
|
511
|
+
const rightThresholdProp = rightThreshold;
|
488
512
|
|
489
513
|
const handleRelease = (
|
490
514
|
event: GestureStateChangeEvent<PanGestureHandlerEventPayload>
|
@@ -535,9 +559,6 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
|
|
535
559
|
}
|
536
560
|
});
|
537
561
|
|
538
|
-
const onSwipeableOpenStartDrag = props.onSwipeableOpenStartDrag;
|
539
|
-
const onSwipeableCloseStartDrag = props.onSwipeableCloseStartDrag;
|
540
|
-
|
541
562
|
const panGesture = Gesture.Pan()
|
542
563
|
.onUpdate((event: GestureUpdateEvent<PanGestureHandlerEventPayload>) => {
|
543
564
|
userDrag.value = event.translationX;
|
@@ -564,10 +585,8 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
|
|
564
585
|
}
|
565
586
|
);
|
566
587
|
|
567
|
-
if (
|
568
|
-
panGesture.enableTrackpadTwoFingerGesture(
|
569
|
-
props.enableTrackpadTwoFingerGesture
|
570
|
-
);
|
588
|
+
if (enableTrackpadTwoFingerGesture) {
|
589
|
+
panGesture.enableTrackpadTwoFingerGesture(enableTrackpadTwoFingerGesture);
|
571
590
|
}
|
572
591
|
|
573
592
|
panGesture.activeOffsetX([
|
@@ -580,7 +599,7 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
|
|
580
599
|
swipeableMethods,
|
581
600
|
]);
|
582
601
|
|
583
|
-
panGesture.enabled(
|
602
|
+
panGesture.enabled(enabled !== false);
|
584
603
|
|
585
604
|
const animatedStyle = useAnimatedStyle(
|
586
605
|
() => ({
|
@@ -590,12 +609,10 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
|
|
590
609
|
[appliedTranslation, rowState]
|
591
610
|
);
|
592
611
|
|
593
|
-
const
|
594
|
-
const childrenContainerStyle = props.childrenContainerStyle;
|
595
|
-
|
596
|
-
return (
|
612
|
+
const swipeableComponent = (
|
597
613
|
<GestureDetector gesture={panGesture} touchAction="pan-y">
|
598
614
|
<Animated.View
|
615
|
+
{...remainingProps}
|
599
616
|
onLayout={onRowLayout}
|
600
617
|
style={[styles.container, containerStyle]}>
|
601
618
|
{leftElement}
|
@@ -608,6 +625,12 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
|
|
608
625
|
</Animated.View>
|
609
626
|
</GestureDetector>
|
610
627
|
);
|
628
|
+
|
629
|
+
return testID ? (
|
630
|
+
<View testID={testID}>{swipeableComponent}</View>
|
631
|
+
) : (
|
632
|
+
swipeableComponent
|
633
|
+
);
|
611
634
|
}
|
612
635
|
);
|
613
636
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import { StylusData } from '../web/interfaces';
|
2
|
+
|
1
3
|
export type FlingGestureHandlerEventPayload = {
|
2
4
|
x: number;
|
3
5
|
y: number;
|
@@ -120,6 +122,11 @@ export type PanGestureHandlerEventPayload = {
|
|
120
122
|
* value is expressed in point units per second.
|
121
123
|
*/
|
122
124
|
velocityY: number;
|
125
|
+
|
126
|
+
/**
|
127
|
+
* Object containing additional stylus data.
|
128
|
+
*/
|
129
|
+
stylusData: StylusData | undefined;
|
123
130
|
};
|
124
131
|
|
125
132
|
export type PinchGestureHandlerEventPayload = {
|
@@ -182,3 +189,38 @@ export type RotationGestureHandlerEventPayload = {
|
|
182
189
|
*/
|
183
190
|
velocity: number;
|
184
191
|
};
|
192
|
+
|
193
|
+
export type HoverGestureHandlerEventPayload = {
|
194
|
+
/**
|
195
|
+
* X coordinate of the current position of the pointer relative to the view
|
196
|
+
* attached to the handler. Expressed in point units.
|
197
|
+
*/
|
198
|
+
x: number;
|
199
|
+
|
200
|
+
/**
|
201
|
+
* Y coordinate of the current position of the pointer relative to the view
|
202
|
+
* attached to the handler. Expressed in point units.
|
203
|
+
*/
|
204
|
+
y: number;
|
205
|
+
|
206
|
+
/**
|
207
|
+
* X coordinate of the current position of the pointer relative to the window.
|
208
|
+
* The value is expressed in point units. It is recommended to use it instead
|
209
|
+
* of `x` in cases when the original view can be transformed as an
|
210
|
+
* effect of the gesture.
|
211
|
+
*/
|
212
|
+
absoluteX: number;
|
213
|
+
|
214
|
+
/**
|
215
|
+
* Y coordinate of the current position of the pointer relative to the window.
|
216
|
+
* The value is expressed in point units. It is recommended to use it instead
|
217
|
+
* of `y` in cases when the original view can be transformed as an
|
218
|
+
* effect of the gesture.
|
219
|
+
*/
|
220
|
+
absoluteY: number;
|
221
|
+
|
222
|
+
/**
|
223
|
+
* Object containing additional stylus data.
|
224
|
+
*/
|
225
|
+
stylusData: StylusData | undefined;
|
226
|
+
};
|
@@ -8,6 +8,7 @@ import {
|
|
8
8
|
export const longPressGestureHandlerProps = [
|
9
9
|
'minDurationMs',
|
10
10
|
'maxDist',
|
11
|
+
'numberOfPointers',
|
11
12
|
] as const;
|
12
13
|
|
13
14
|
export interface LongPressGestureConfig {
|
@@ -24,6 +25,11 @@ export interface LongPressGestureConfig {
|
|
24
25
|
* will fail to recognize the gesture. The default value is 10.
|
25
26
|
*/
|
26
27
|
maxDist?: number;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Determine exact number of points required to handle the long press gesture.
|
31
|
+
*/
|
32
|
+
numberOfPointers?: number;
|
27
33
|
}
|
28
34
|
|
29
35
|
export interface LongPressGestureHandlerProps
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Platform } from 'react-native';
|
2
2
|
|
3
|
-
import { tagMessage } from '../../../utils';
|
3
|
+
import { isJestEnv, tagMessage } from '../../../utils';
|
4
4
|
import { GestureRef, BaseGesture, GestureType } from '../gesture';
|
5
5
|
|
6
6
|
import { flingGestureHandlerProps } from '../../FlingGestureHandler';
|
@@ -100,7 +100,7 @@ export function checkGestureCallbacksForWorklets(gesture: GestureType) {
|
|
100
100
|
const areAllNotWorklets = !areSomeWorklets && areSomeNotWorklets;
|
101
101
|
// If none of the callbacks are worklets and the gesture is not explicitly marked with
|
102
102
|
// `.runOnJS(true)` show a warning
|
103
|
-
if (areAllNotWorklets) {
|
103
|
+
if (areAllNotWorklets && !isJestEnv()) {
|
104
104
|
console.warn(
|
105
105
|
tagMessage(
|
106
106
|
`None of the callbacks in the gesture are worklets. If you wish to run them on the JS thread use '.runOnJS(true)' modifier on the gesture to make this explicit. Otherwise, mark the callbacks as 'worklet' to run them on the UI thread.`
|
@@ -18,6 +18,7 @@ import type {
|
|
18
18
|
RotationGestureHandlerEventPayload,
|
19
19
|
TapGestureHandlerEventPayload,
|
20
20
|
NativeViewGestureHandlerPayload,
|
21
|
+
HoverGestureHandlerEventPayload,
|
21
22
|
} from '../GestureHandlerEventPayload';
|
22
23
|
import { isRemoteDebuggingEnabled } from '../../utils';
|
23
24
|
|
@@ -31,7 +32,8 @@ export type GestureType =
|
|
31
32
|
| BaseGesture<PinchGestureHandlerEventPayload>
|
32
33
|
| BaseGesture<FlingGestureHandlerEventPayload>
|
33
34
|
| BaseGesture<ForceTouchGestureHandlerEventPayload>
|
34
|
-
| BaseGesture<NativeViewGestureHandlerPayload
|
35
|
+
| BaseGesture<NativeViewGestureHandlerPayload>
|
36
|
+
| BaseGesture<HoverGestureHandlerEventPayload>;
|
35
37
|
|
36
38
|
export type GestureRef =
|
37
39
|
| number
|
@@ -1,12 +1,6 @@
|
|
1
1
|
import { BaseGestureConfig, ContinousBaseGesture } from './gesture';
|
2
2
|
import { GestureUpdateEvent } from '../gestureHandlerCommon';
|
3
|
-
|
4
|
-
export type HoverGestureHandlerEventPayload = {
|
5
|
-
x: number;
|
6
|
-
y: number;
|
7
|
-
absoluteX: number;
|
8
|
-
absoluteY: number;
|
9
|
-
};
|
3
|
+
import type { HoverGestureHandlerEventPayload } from '../GestureHandlerEventPayload';
|
10
4
|
|
11
5
|
export type HoverGestureChangeEventPayload = {
|
12
6
|
changeX: number;
|
@@ -31,6 +31,15 @@ export class LongPressGesture extends BaseGesture<LongPressGestureHandlerEventPa
|
|
31
31
|
this.config.maxDist = distance;
|
32
32
|
return this;
|
33
33
|
}
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Determine exact number of points required to handle the long press gesture.
|
37
|
+
* @param pointers
|
38
|
+
*/
|
39
|
+
numberOfPointers(pointers: number) {
|
40
|
+
this.config.numberOfPointers = pointers;
|
41
|
+
return this;
|
42
|
+
}
|
34
43
|
}
|
35
44
|
|
36
45
|
export type LongPressGestureType = InstanceType<typeof LongPressGesture>;
|
@@ -138,6 +138,7 @@ const handlersDefaultEvents: DefaultEventsMapping = {
|
|
138
138
|
velocityX: 3,
|
139
139
|
velocityY: 0,
|
140
140
|
numberOfPointers: 1,
|
141
|
+
stylusData: undefined,
|
141
142
|
},
|
142
143
|
[pinchHandlerName]: {
|
143
144
|
focalX: 0,
|
@@ -404,6 +405,7 @@ interface HandlerData {
|
|
404
405
|
emitEvent: EventEmitter;
|
405
406
|
handlerType: HandlerNames;
|
406
407
|
handlerTag: number;
|
408
|
+
enabled: boolean | undefined;
|
407
409
|
}
|
408
410
|
function getHandlerData(
|
409
411
|
componentOrGesture: ReactTestInstance | GestureType
|
@@ -416,6 +418,7 @@ function getHandlerData(
|
|
416
418
|
},
|
417
419
|
handlerType: gesture.handlerName as HandlerNames,
|
418
420
|
handlerTag: gesture.handlerTag,
|
421
|
+
enabled: gesture.config.enabled,
|
419
422
|
};
|
420
423
|
}
|
421
424
|
const gestureHandlerComponent = componentOrGesture;
|
@@ -425,6 +428,7 @@ function getHandlerData(
|
|
425
428
|
},
|
426
429
|
handlerType: gestureHandlerComponent.props.handlerType as HandlerNames,
|
427
430
|
handlerTag: gestureHandlerComponent.props.handlerTag as number,
|
431
|
+
enabled: gestureHandlerComponent.props.enabled,
|
428
432
|
};
|
429
433
|
}
|
430
434
|
type AllGestures =
|
@@ -466,9 +470,13 @@ export function fireGestureHandler<THandler extends AllGestures | AllHandlers>(
|
|
466
470
|
componentOrGesture: ReactTestInstance | GestureType,
|
467
471
|
eventList: Partial<GestureHandlerTestEvent<ExtractConfig<THandler>>>[] = []
|
468
472
|
): void {
|
469
|
-
const { emitEvent, handlerType, handlerTag } =
|
473
|
+
const { emitEvent, handlerType, handlerTag, enabled } =
|
470
474
|
getHandlerData(componentOrGesture);
|
471
475
|
|
476
|
+
if (enabled === false) {
|
477
|
+
return;
|
478
|
+
}
|
479
|
+
|
472
480
|
let _ = fillMissingStatesTransitions(
|
473
481
|
eventList,
|
474
482
|
isDiscreteHandler(handlerType)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import React from 'react';
|
1
2
|
import {
|
2
3
|
TouchableHighlight,
|
3
4
|
TouchableNativeFeedback,
|
@@ -30,9 +31,13 @@ const LongPressGestureHandler = View;
|
|
30
31
|
const PinchGestureHandler = View;
|
31
32
|
const RotationGestureHandler = View;
|
32
33
|
const FlingGestureHandler = View;
|
33
|
-
const RawButton =
|
34
|
-
|
35
|
-
|
34
|
+
const RawButton = ({ enabled, ...rest }: any) => (
|
35
|
+
<TouchableNativeFeedback disabled={!enabled} {...rest}>
|
36
|
+
<View />
|
37
|
+
</TouchableNativeFeedback>
|
38
|
+
);
|
39
|
+
const BaseButton = RawButton;
|
40
|
+
const RectButton = RawButton;
|
36
41
|
const BorderlessButton = TouchableNativeFeedback;
|
37
42
|
|
38
43
|
export default {
|
package/src/utils.ts
CHANGED
package/src/web/constants.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
export const DEFAULT_TOUCH_SLOP = 15;
|
2
|
-
export const
|
2
|
+
export const MINIMAL_RECOGNIZABLE_MAGNITUDE = 0.1;
|
@@ -14,10 +14,10 @@ import EventManager from '../tools/EventManager';
|
|
14
14
|
import GestureHandlerOrchestrator from '../tools/GestureHandlerOrchestrator';
|
15
15
|
import InteractionManager from '../tools/InteractionManager';
|
16
16
|
import PointerTracker, { TrackerElement } from '../tools/PointerTracker';
|
17
|
-
import { GestureHandlerDelegate } from '../tools/GestureHandlerDelegate';
|
18
17
|
import IGestureHandler from './IGestureHandler';
|
19
18
|
import { MouseButton } from '../../handlers/gestureHandlerCommon';
|
20
19
|
import { PointerType } from '../../PointerType';
|
20
|
+
import { GestureHandlerDelegate } from '../tools/GestureHandlerDelegate';
|
21
21
|
|
22
22
|
export default abstract class GestureHandler implements IGestureHandler {
|
23
23
|
private lastSentState: State | null = null;
|
@@ -507,7 +507,7 @@ export default abstract class GestureHandler implements IGestureHandler {
|
|
507
507
|
nativeEvent: {
|
508
508
|
handlerTag: this.handlerTag,
|
509
509
|
state: this.currentState,
|
510
|
-
eventType:
|
510
|
+
eventType: eventType,
|
511
511
|
changedTouches: changed,
|
512
512
|
allTouches: all,
|
513
513
|
numberOfTouches: numberOfTouches,
|
@@ -589,6 +589,8 @@ export default abstract class GestureHandler implements IGestureHandler {
|
|
589
589
|
this.config = { enabled: enabled, ...props };
|
590
590
|
this.enabled = enabled;
|
591
591
|
|
592
|
+
this.delegate.onEnabledChange(enabled);
|
593
|
+
|
592
594
|
if (this.config.shouldCancelWhenOutside !== undefined) {
|
593
595
|
this.setShouldCancelWhenOutside(this.config.shouldCancelWhenOutside);
|
594
596
|
}
|
@@ -1,13 +1,22 @@
|
|
1
1
|
import { State } from '../../State';
|
2
|
-
import { AdaptedEvent, Config } from '../interfaces';
|
2
|
+
import { AdaptedEvent, Config, StylusData } from '../interfaces';
|
3
3
|
import GestureHandlerOrchestrator from '../tools/GestureHandlerOrchestrator';
|
4
4
|
import GestureHandler from './GestureHandler';
|
5
5
|
|
6
6
|
export default class HoverGestureHandler extends GestureHandler {
|
7
|
+
private stylusData: StylusData | undefined;
|
8
|
+
|
7
9
|
public init(ref: number, propsRef: React.RefObject<unknown>) {
|
8
10
|
super.init(ref, propsRef);
|
9
11
|
}
|
10
12
|
|
13
|
+
protected transformNativeEvent(): Record<string, unknown> {
|
14
|
+
return {
|
15
|
+
...super.transformNativeEvent(),
|
16
|
+
stylusData: this.stylusData,
|
17
|
+
};
|
18
|
+
}
|
19
|
+
|
11
20
|
public updateGestureConfig({ enabled = true, ...props }: Config): void {
|
12
21
|
super.updateGestureConfig({ enabled: enabled, ...props });
|
13
22
|
}
|
@@ -16,6 +25,7 @@ export default class HoverGestureHandler extends GestureHandler {
|
|
16
25
|
GestureHandlerOrchestrator.getInstance().recordHandlerIfNotPresent(this);
|
17
26
|
|
18
27
|
this.tracker.addToTracker(event);
|
28
|
+
this.stylusData = event.stylusData;
|
19
29
|
super.onPointerMoveOver(event);
|
20
30
|
|
21
31
|
if (this.getState() === State.UNDETERMINED) {
|
@@ -25,7 +35,9 @@ export default class HoverGestureHandler extends GestureHandler {
|
|
25
35
|
}
|
26
36
|
|
27
37
|
protected onPointerMoveOut(event: AdaptedEvent): void {
|
28
|
-
this.tracker.
|
38
|
+
this.tracker.removeFromTracker(event.pointerId);
|
39
|
+
this.stylusData = event.stylusData;
|
40
|
+
|
29
41
|
super.onPointerMoveOut(event);
|
30
42
|
|
31
43
|
this.end();
|
@@ -33,6 +45,8 @@ export default class HoverGestureHandler extends GestureHandler {
|
|
33
45
|
|
34
46
|
protected onPointerMove(event: AdaptedEvent): void {
|
35
47
|
this.tracker.track(event);
|
48
|
+
this.stylusData = event.stylusData;
|
49
|
+
|
36
50
|
super.onPointerMove(event);
|
37
51
|
}
|
38
52
|
|
@@ -12,6 +12,7 @@ export default class LongPressGestureHandler extends GestureHandler {
|
|
12
12
|
private defaultMaxDistSq = DEFAULT_MAX_DIST_DP * SCALING_FACTOR;
|
13
13
|
|
14
14
|
private maxDistSq = this.defaultMaxDistSq;
|
15
|
+
private numberOfPointers = 1;
|
15
16
|
private startX = 0;
|
16
17
|
private startY = 0;
|
17
18
|
|
@@ -45,6 +46,10 @@ export default class LongPressGestureHandler extends GestureHandler {
|
|
45
46
|
if (this.config.maxDist !== undefined) {
|
46
47
|
this.maxDistSq = this.config.maxDist * this.config.maxDist;
|
47
48
|
}
|
49
|
+
|
50
|
+
if (this.config.numberOfPointers !== undefined) {
|
51
|
+
this.numberOfPointers = this.config.numberOfPointers;
|
52
|
+
}
|
48
53
|
}
|
49
54
|
|
50
55
|
protected resetConfig(): void {
|
@@ -64,17 +69,36 @@ export default class LongPressGestureHandler extends GestureHandler {
|
|
64
69
|
|
65
70
|
this.tracker.addToTracker(event);
|
66
71
|
super.onPointerDown(event);
|
67
|
-
|
72
|
+
|
73
|
+
this.startX = event.x;
|
74
|
+
this.startY = event.y;
|
75
|
+
|
76
|
+
this.tryBegin();
|
68
77
|
this.tryActivate();
|
69
|
-
this.checkDistanceFail(event);
|
70
78
|
|
71
79
|
this.tryToSendTouchEvent(event);
|
72
80
|
}
|
81
|
+
protected onPointerAdd(event: AdaptedEvent): void {
|
82
|
+
super.onPointerAdd(event);
|
83
|
+
this.tracker.addToTracker(event);
|
84
|
+
|
85
|
+
if (this.tracker.getTrackedPointersCount() > this.numberOfPointers) {
|
86
|
+
this.fail();
|
87
|
+
return;
|
88
|
+
}
|
89
|
+
|
90
|
+
const absoluteCoordsAverage = this.tracker.getAbsoluteCoordsAverage();
|
91
|
+
|
92
|
+
this.startX = absoluteCoordsAverage.x;
|
93
|
+
this.startY = absoluteCoordsAverage.y;
|
94
|
+
|
95
|
+
this.tryActivate();
|
96
|
+
}
|
73
97
|
|
74
98
|
protected onPointerMove(event: AdaptedEvent): void {
|
75
99
|
super.onPointerMove(event);
|
76
100
|
this.tracker.track(event);
|
77
|
-
this.checkDistanceFail(
|
101
|
+
this.checkDistanceFail();
|
78
102
|
}
|
79
103
|
|
80
104
|
protected onPointerUp(event: AdaptedEvent): void {
|
@@ -88,7 +112,19 @@ export default class LongPressGestureHandler extends GestureHandler {
|
|
88
112
|
}
|
89
113
|
}
|
90
114
|
|
91
|
-
|
115
|
+
protected onPointerRemove(event: AdaptedEvent): void {
|
116
|
+
super.onPointerRemove(event);
|
117
|
+
this.tracker.removeFromTracker(event.pointerId);
|
118
|
+
|
119
|
+
if (
|
120
|
+
this.tracker.getTrackedPointersCount() < this.numberOfPointers &&
|
121
|
+
this.getState() !== State.ACTIVE
|
122
|
+
) {
|
123
|
+
this.fail();
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
private tryBegin(): void {
|
92
128
|
if (this.currentState !== State.UNDETERMINED) {
|
93
129
|
return;
|
94
130
|
}
|
@@ -97,12 +133,13 @@ export default class LongPressGestureHandler extends GestureHandler {
|
|
97
133
|
this.startTime = this.previousTime;
|
98
134
|
|
99
135
|
this.begin();
|
100
|
-
|
101
|
-
this.startX = event.x;
|
102
|
-
this.startY = event.y;
|
103
136
|
}
|
104
137
|
|
105
138
|
private tryActivate(): void {
|
139
|
+
if (this.tracker.getTrackedPointersCount() !== this.numberOfPointers) {
|
140
|
+
return;
|
141
|
+
}
|
142
|
+
|
106
143
|
if (this.minDurationMs > 0) {
|
107
144
|
this.activationTimeout = setTimeout(() => {
|
108
145
|
this.activate();
|
@@ -112,9 +149,11 @@ export default class LongPressGestureHandler extends GestureHandler {
|
|
112
149
|
}
|
113
150
|
}
|
114
151
|
|
115
|
-
private checkDistanceFail(
|
116
|
-
const
|
117
|
-
|
152
|
+
private checkDistanceFail(): void {
|
153
|
+
const absoluteCoordsAverage = this.tracker.getAbsoluteCoordsAverage();
|
154
|
+
|
155
|
+
const dx = absoluteCoordsAverage.x - this.startX;
|
156
|
+
const dy = absoluteCoordsAverage.y - this.startY;
|
118
157
|
const distSq = dx * dx + dy * dy;
|
119
158
|
|
120
159
|
if (distSq <= this.maxDistSq) {
|
@@ -27,10 +27,7 @@ export default class NativeViewGestureHandler extends GestureHandler {
|
|
27
27
|
|
28
28
|
const view = this.delegate.getView() as HTMLElement;
|
29
29
|
|
30
|
-
view
|
31
|
-
// @ts-ignore Turns on defualt touch behavior on Safari
|
32
|
-
view.style['WebkitTouchCallout'] = 'auto';
|
33
|
-
|
30
|
+
this.restoreViewStyles(view);
|
34
31
|
this.buttonRole = view.getAttribute('role') === 'button';
|
35
32
|
}
|
36
33
|
|
@@ -43,6 +40,19 @@ export default class NativeViewGestureHandler extends GestureHandler {
|
|
43
40
|
if (this.config.disallowInterruption !== undefined) {
|
44
41
|
this.disallowInterruption = this.config.disallowInterruption;
|
45
42
|
}
|
43
|
+
|
44
|
+
const view = this.delegate.getView() as HTMLElement;
|
45
|
+
this.restoreViewStyles(view);
|
46
|
+
}
|
47
|
+
|
48
|
+
private restoreViewStyles(view: HTMLElement) {
|
49
|
+
if (!view) {
|
50
|
+
return;
|
51
|
+
}
|
52
|
+
|
53
|
+
view.style['touchAction'] = 'auto';
|
54
|
+
// @ts-ignore Turns on defualt touch behavior on Safari
|
55
|
+
view.style['WebkitTouchCallout'] = 'auto';
|
46
56
|
}
|
47
57
|
|
48
58
|
protected resetConfig(): void {
|