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.
Files changed (210) hide show
  1. package/README.md +1 -0
  2. package/android/build.gradle +11 -29
  3. package/android/fabric/src/main/java/com/swmansion/gesturehandler/ReactContextExtensions.kt +1 -1
  4. package/android/paper/src/main/java/com/swmansion/gesturehandler/ReactContextExtensions.kt +1 -1
  5. package/android/src/main/AndroidManifest.xml +1 -3
  6. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +21 -21
  7. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +2 -2
  8. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureUtils.kt +1 -0
  9. package/android/src/main/java/com/swmansion/gesturehandler/core/HoverGestureHandler.kt +16 -0
  10. package/android/src/main/java/com/swmansion/gesturehandler/core/LongPressGestureHandler.kt +80 -4
  11. package/android/src/main/java/com/swmansion/gesturehandler/core/PanGestureHandler.kt +8 -0
  12. package/android/src/main/java/com/swmansion/gesturehandler/core/PinchGestureHandler.kt +2 -1
  13. package/android/src/main/java/com/swmansion/gesturehandler/core/ScaleGestureDetector.java +10 -0
  14. package/android/src/main/java/com/swmansion/gesturehandler/core/StylusData.kt +103 -0
  15. package/android/src/main/java/com/swmansion/gesturehandler/core/Vector.kt +2 -2
  16. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +24 -15
  17. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +3 -0
  18. package/android/src/main/java/com/swmansion/gesturehandler/react/eventbuilders/HoverGestureHandlerEventDataBuilder.kt +7 -0
  19. package/android/src/main/java/com/swmansion/gesturehandler/react/eventbuilders/PanGestureHandlerEventDataBuilder.kt +7 -0
  20. package/android/src/main/jni/CMakeLists.txt +18 -9
  21. package/apple/Handlers/RNFlingHandler.h +1 -0
  22. package/apple/Handlers/RNFlingHandler.m +153 -19
  23. package/apple/Handlers/RNHoverHandler.m +44 -2
  24. package/apple/Handlers/RNLongPressHandler.m +111 -20
  25. package/apple/Handlers/RNManualHandler.m +53 -29
  26. package/apple/Handlers/RNNativeViewHandler.mm +22 -15
  27. package/apple/Handlers/RNPanHandler.m +57 -7
  28. package/apple/Handlers/RNRotationHandler.m +1 -1
  29. package/apple/RNGHStylusData.h +77 -0
  30. package/apple/RNGHStylusData.m +37 -0
  31. package/apple/RNGHUIKit.h +2 -0
  32. package/apple/RNGHVector.h +31 -0
  33. package/apple/RNGHVector.m +67 -0
  34. package/apple/RNGestureHandler.h +7 -0
  35. package/apple/{RNGestureHandler.m → RNGestureHandler.mm} +63 -1
  36. package/apple/RNGestureHandlerButtonComponentView.mm +41 -0
  37. package/apple/RNGestureHandlerDirection.h +25 -0
  38. package/apple/RNGestureHandlerEvents.h +3 -1
  39. package/apple/RNGestureHandlerEvents.m +11 -3
  40. package/lib/commonjs/PointerType.js +2 -1
  41. package/lib/commonjs/PointerType.js.map +1 -1
  42. package/lib/commonjs/components/GestureButtons.js +5 -1
  43. package/lib/commonjs/components/GestureButtons.js.map +1 -1
  44. package/lib/commonjs/components/GestureComponents.js.map +1 -1
  45. package/lib/commonjs/components/Pressable/Pressable.js +66 -78
  46. package/lib/commonjs/components/Pressable/Pressable.js.map +1 -1
  47. package/lib/commonjs/components/Pressable/index.js +0 -8
  48. package/lib/commonjs/components/Pressable/index.js.map +1 -1
  49. package/lib/commonjs/components/Pressable/utils.js +1 -23
  50. package/lib/commonjs/components/Pressable/utils.js.map +1 -1
  51. package/lib/commonjs/components/ReanimatedSwipeable.js +60 -41
  52. package/lib/commonjs/components/ReanimatedSwipeable.js.map +1 -1
  53. package/lib/commonjs/handlers/GestureHandlerEventPayload.js +4 -0
  54. package/lib/commonjs/handlers/LongPressGestureHandler.js +1 -1
  55. package/lib/commonjs/handlers/LongPressGestureHandler.js.map +1 -1
  56. package/lib/commonjs/handlers/createHandler.js +2 -1
  57. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  58. package/lib/commonjs/handlers/gestures/GestureDetector/utils.js +1 -1
  59. package/lib/commonjs/handlers/gestures/GestureDetector/utils.js.map +1 -1
  60. package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
  61. package/lib/commonjs/handlers/gestures/hoverGesture.js.map +1 -1
  62. package/lib/commonjs/handlers/gestures/longPressGesture.js +10 -0
  63. package/lib/commonjs/handlers/gestures/longPressGesture.js.map +1 -1
  64. package/lib/commonjs/jestUtils/jestUtils.js +12 -4
  65. package/lib/commonjs/jestUtils/jestUtils.js.map +1 -1
  66. package/lib/commonjs/mocks.js +16 -3
  67. package/lib/commonjs/mocks.js.map +1 -1
  68. package/lib/commonjs/utils.js +4 -0
  69. package/lib/commonjs/utils.js.map +1 -1
  70. package/lib/commonjs/web/constants.js +3 -3
  71. package/lib/commonjs/web/constants.js.map +1 -1
  72. package/lib/commonjs/web/handlers/GestureHandler.js +2 -3
  73. package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
  74. package/lib/commonjs/web/handlers/HoverGestureHandler.js +18 -1
  75. package/lib/commonjs/web/handlers/HoverGestureHandler.js.map +1 -1
  76. package/lib/commonjs/web/handlers/LongPressGestureHandler.js +43 -9
  77. package/lib/commonjs/web/handlers/LongPressGestureHandler.js.map +1 -1
  78. package/lib/commonjs/web/handlers/NativeViewGestureHandler.js +14 -3
  79. package/lib/commonjs/web/handlers/NativeViewGestureHandler.js.map +1 -1
  80. package/lib/commonjs/web/handlers/PanGestureHandler.js +12 -1
  81. package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
  82. package/lib/commonjs/web/interfaces.js.map +1 -1
  83. package/lib/commonjs/web/tools/EventManager.js.map +1 -1
  84. package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js +55 -11
  85. package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js.map +1 -1
  86. package/lib/commonjs/web/tools/KeyboardEventManager.js +110 -0
  87. package/lib/commonjs/web/tools/KeyboardEventManager.js.map +1 -0
  88. package/lib/commonjs/web/tools/PointerEventManager.js +3 -37
  89. package/lib/commonjs/web/tools/PointerEventManager.js.map +1 -1
  90. package/lib/commonjs/web/tools/Vector.js +4 -2
  91. package/lib/commonjs/web/tools/Vector.js.map +1 -1
  92. package/lib/commonjs/web/utils.js +187 -13
  93. package/lib/commonjs/web/utils.js.map +1 -1
  94. package/lib/module/PointerType.js +2 -1
  95. package/lib/module/PointerType.js.map +1 -1
  96. package/lib/module/components/GestureButtons.js +5 -1
  97. package/lib/module/components/GestureButtons.js.map +1 -1
  98. package/lib/module/components/GestureComponents.js.map +1 -1
  99. package/lib/module/components/Pressable/Pressable.js +67 -78
  100. package/lib/module/components/Pressable/Pressable.js.map +1 -1
  101. package/lib/module/components/Pressable/index.js +0 -1
  102. package/lib/module/components/Pressable/index.js.map +1 -1
  103. package/lib/module/components/Pressable/utils.js +1 -22
  104. package/lib/module/components/Pressable/utils.js.map +1 -1
  105. package/lib/module/components/ReanimatedSwipeable.js +58 -37
  106. package/lib/module/components/ReanimatedSwipeable.js.map +1 -1
  107. package/lib/module/handlers/GestureHandlerEventPayload.js +1 -1
  108. package/lib/module/handlers/LongPressGestureHandler.js +1 -1
  109. package/lib/module/handlers/LongPressGestureHandler.js.map +1 -1
  110. package/lib/module/handlers/createHandler.js +2 -1
  111. package/lib/module/handlers/createHandler.js.map +1 -1
  112. package/lib/module/handlers/gestures/GestureDetector/utils.js +2 -2
  113. package/lib/module/handlers/gestures/GestureDetector/utils.js.map +1 -1
  114. package/lib/module/handlers/gestures/gesture.js.map +1 -1
  115. package/lib/module/handlers/gestures/hoverGesture.js.map +1 -1
  116. package/lib/module/handlers/gestures/longPressGesture.js +10 -0
  117. package/lib/module/handlers/gestures/longPressGesture.js.map +1 -1
  118. package/lib/module/jestUtils/jestUtils.js +12 -4
  119. package/lib/module/jestUtils/jestUtils.js.map +1 -1
  120. package/lib/module/mocks.js +13 -3
  121. package/lib/module/mocks.js.map +1 -1
  122. package/lib/module/utils.js +1 -0
  123. package/lib/module/utils.js.map +1 -1
  124. package/lib/module/web/constants.js +1 -1
  125. package/lib/module/web/constants.js.map +1 -1
  126. package/lib/module/web/handlers/GestureHandler.js +2 -3
  127. package/lib/module/web/handlers/GestureHandler.js.map +1 -1
  128. package/lib/module/web/handlers/HoverGestureHandler.js +18 -1
  129. package/lib/module/web/handlers/HoverGestureHandler.js.map +1 -1
  130. package/lib/module/web/handlers/LongPressGestureHandler.js +43 -9
  131. package/lib/module/web/handlers/LongPressGestureHandler.js.map +1 -1
  132. package/lib/module/web/handlers/NativeViewGestureHandler.js +14 -3
  133. package/lib/module/web/handlers/NativeViewGestureHandler.js.map +1 -1
  134. package/lib/module/web/handlers/PanGestureHandler.js +12 -1
  135. package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
  136. package/lib/module/web/interfaces.js.map +1 -1
  137. package/lib/module/web/tools/EventManager.js.map +1 -1
  138. package/lib/module/web/tools/GestureHandlerWebDelegate.js +54 -10
  139. package/lib/module/web/tools/GestureHandlerWebDelegate.js.map +1 -1
  140. package/lib/module/web/tools/KeyboardEventManager.js +96 -0
  141. package/lib/module/web/tools/KeyboardEventManager.js.map +1 -0
  142. package/lib/module/web/tools/PointerEventManager.js +4 -38
  143. package/lib/module/web/tools/PointerEventManager.js.map +1 -1
  144. package/lib/module/web/tools/Vector.js +5 -3
  145. package/lib/module/web/tools/Vector.js.map +1 -1
  146. package/lib/module/web/utils.js +184 -13
  147. package/lib/module/web/utils.js.map +1 -1
  148. package/lib/typescript/PointerType.d.ts +2 -1
  149. package/lib/typescript/components/GestureComponents.d.ts +1 -1
  150. package/lib/typescript/components/Pressable/index.d.ts +1 -1
  151. package/lib/typescript/components/Pressable/utils.d.ts +3 -5
  152. package/lib/typescript/handlers/GestureHandlerEventPayload.d.ts +35 -0
  153. package/lib/typescript/handlers/LongPressGestureHandler.d.ts +5 -1
  154. package/lib/typescript/handlers/gestures/gesture.d.ts +2 -2
  155. package/lib/typescript/handlers/gestures/hoverGesture.d.ts +1 -6
  156. package/lib/typescript/handlers/gestures/longPressGesture.d.ts +5 -0
  157. package/lib/typescript/handlers/handlersRegistry.d.ts +1 -1
  158. package/lib/typescript/jestUtils/jestUtils.d.ts +1 -1
  159. package/lib/typescript/mocks.d.ts +4 -3
  160. package/lib/typescript/utils.d.ts +1 -0
  161. package/lib/typescript/web/constants.d.ts +1 -1
  162. package/lib/typescript/web/handlers/GestureHandler.d.ts +1 -1
  163. package/lib/typescript/web/handlers/HoverGestureHandler.d.ts +2 -0
  164. package/lib/typescript/web/handlers/LongPressGestureHandler.d.ts +3 -0
  165. package/lib/typescript/web/handlers/NativeViewGestureHandler.d.ts +1 -0
  166. package/lib/typescript/web/handlers/PanGestureHandler.d.ts +3 -1
  167. package/lib/typescript/web/interfaces.d.ts +9 -4
  168. package/lib/typescript/web/tools/EventManager.d.ts +2 -2
  169. package/lib/typescript/web/tools/GestureHandlerDelegate.d.ts +1 -0
  170. package/lib/typescript/web/tools/GestureHandlerWebDelegate.d.ts +6 -0
  171. package/lib/typescript/web/tools/KeyboardEventManager.d.ts +13 -0
  172. package/lib/typescript/web/utils.d.ts +2 -1
  173. package/package.json +3 -3
  174. package/src/PointerType.ts +1 -0
  175. package/src/components/GestureButtons.tsx +2 -1
  176. package/src/components/GestureComponents.tsx +1 -1
  177. package/src/components/Pressable/Pressable.tsx +77 -70
  178. package/src/components/Pressable/index.ts +1 -1
  179. package/src/components/Pressable/utils.ts +5 -49
  180. package/src/components/ReanimatedSwipeable.tsx +70 -47
  181. package/src/handlers/GestureHandlerEventPayload.ts +42 -0
  182. package/src/handlers/LongPressGestureHandler.ts +6 -0
  183. package/src/handlers/createHandler.tsx +1 -0
  184. package/src/handlers/gestures/GestureDetector/utils.ts +2 -2
  185. package/src/handlers/gestures/gesture.ts +3 -1
  186. package/src/handlers/gestures/hoverGesture.ts +1 -7
  187. package/src/handlers/gestures/longPressGesture.ts +9 -0
  188. package/src/jestUtils/jestUtils.ts +9 -1
  189. package/src/{mocks.ts → mocks.tsx} +8 -3
  190. package/src/utils.ts +2 -0
  191. package/src/web/constants.ts +1 -1
  192. package/src/web/handlers/GestureHandler.ts +4 -2
  193. package/src/web/handlers/HoverGestureHandler.ts +16 -2
  194. package/src/web/handlers/LongPressGestureHandler.ts +49 -10
  195. package/src/web/handlers/NativeViewGestureHandler.ts +14 -4
  196. package/src/web/handlers/PanGestureHandler.ts +14 -1
  197. package/src/web/interfaces.ts +10 -4
  198. package/src/web/tools/EventManager.ts +2 -4
  199. package/src/web/tools/GestureHandlerDelegate.ts +1 -0
  200. package/src/web/tools/GestureHandlerWebDelegate.ts +67 -10
  201. package/src/web/tools/KeyboardEventManager.ts +91 -0
  202. package/src/web/tools/PointerEventManager.ts +2 -38
  203. package/src/web/tools/Vector.ts +4 -3
  204. package/src/web/utils.ts +188 -13
  205. package/lib/commonjs/web/tools/TouchEventManager.js +0 -164
  206. package/lib/commonjs/web/tools/TouchEventManager.js.map +0 -1
  207. package/lib/module/web/tools/TouchEventManager.js +0 -149
  208. package/lib/module/web/tools/TouchEventManager.js.map +0 -1
  209. package/lib/typescript/web/tools/TouchEventManager.d.ts +0 -11
  210. 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 = props.overshootLeft;
244
- const overshootRightProp = props.overshootRight;
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 && props.onSwipeableWillOpen) {
321
- props.onSwipeableWillOpen('left');
322
- } else if (toValue < 0 && props.onSwipeableWillOpen) {
323
- props.onSwipeableWillOpen('right');
324
- } else if (props.onSwipeableWillClose) {
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
- props.onSwipeableWillClose(closingDirection);
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 && props.onSwipeableOpen) {
340
- props.onSwipeableOpen('left', swipeableMethods.current);
341
- } else if (toValue < 0 && props.onSwipeableOpen) {
342
- props.onSwipeableOpen('right', swipeableMethods.current);
343
- } else if (props.onSwipeableClose) {
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
- props.onSwipeableClose(closingDirection, swipeableMethods.current);
360
+ onSwipeableClose(closingDirection, swipeableMethods.current);
346
361
  }
347
362
  },
348
- [props, props.onSwipeableClose, props.onSwipeableOpen, swipeableMethods]
363
+ [onSwipeableClose, onSwipeableOpen]
349
364
  );
350
365
 
351
- const animationOptionsProp = props.animationOptions;
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 springConfig = {
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
- springConfig,
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 ? withSpring(progressTarget, springConfig) : 0;
400
+ leftWidth.value > 0
401
+ ? withSpring(progressTarget, progressSpringConfig)
402
+ : 0;
384
403
  showRightProgress.value =
385
- rightWidth.value > 0 ? withSpring(progressTarget, springConfig) : 0;
404
+ rightWidth.value > 0
405
+ ? withSpring(progressTarget, progressSpringConfig)
406
+ : 0;
386
407
 
387
408
  runOnJS(dispatchImmediateEvents)(fromValue, toValue);
388
409
  },
389
410
  [
390
- showLeftProgress,
411
+ rowState,
412
+ animationOptionsProp,
391
413
  appliedTranslation,
392
- dispatchEndEvents,
414
+ showLeftProgress,
415
+ leftWidth.value,
416
+ showRightProgress,
417
+ rightWidth.value,
393
418
  dispatchImmediateEvents,
394
- animationOptionsProp,
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 = props.leftThreshold;
487
- const rightThresholdProp = props.rightThreshold;
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 (props.enableTrackpadTwoFingerGesture) {
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(props.enabled !== false);
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 containerStyle = props.containerStyle;
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
@@ -529,6 +529,7 @@ export default function createHandler<
529
529
  ? {
530
530
  handlerType: name,
531
531
  handlerTag: this.handlerTag,
532
+ enabled: this.props.enabled,
532
533
  }
533
534
  : {}),
534
535
  testID: this.props.testID ?? child.props.testID,
@@ -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 = TouchableNativeFeedback;
34
- const BaseButton = TouchableNativeFeedback;
35
- const RectButton = TouchableNativeFeedback;
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
@@ -98,3 +98,5 @@ export function deepEqual(obj1: any, obj2: any) {
98
98
 
99
99
  return true;
100
100
  }
101
+
102
+ export const INT32_MAX = 2 ** 31 - 1;
@@ -1,2 +1,2 @@
1
1
  export const DEFAULT_TOUCH_SLOP = 15;
2
- export const MINIMAL_FLING_VELOCITY = 0.1;
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: event.touchEventType ?? 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.addToTracker(event);
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
- this.tryBegin(event);
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(event);
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
- private tryBegin(event: AdaptedEvent): void {
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(event: AdaptedEvent): void {
116
- const dx = event.x - this.startX;
117
- const dy = event.y - this.startY;
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.style['touchAction'] = 'auto';
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 {