react-native-gesture-handler 2.29.0 → 2.30.0-20251030-c99169d35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.java +1 -0
  2. package/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerRootViewManagerDelegate.java +8 -1
  3. package/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerRootViewManagerInterface.java +1 -1
  4. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +73 -41
  5. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +0 -3
  6. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootView.kt +12 -4
  7. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootViewManager.kt +6 -0
  8. package/lib/commonjs/components/GestureHandlerRootView.android.js.map +1 -1
  9. package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
  10. package/lib/commonjs/components/Pressable/Pressable.js +3 -1
  11. package/lib/commonjs/components/Pressable/Pressable.js.map +1 -1
  12. package/lib/commonjs/components/ReanimatedSwipeable/ReanimatedSwipeable.js +4 -2
  13. package/lib/commonjs/components/ReanimatedSwipeable/ReanimatedSwipeable.js.map +1 -1
  14. package/lib/commonjs/handlers/gestures/GestureDetector/index.js +2 -1
  15. package/lib/commonjs/handlers/gestures/GestureDetector/index.js.map +1 -1
  16. package/lib/commonjs/handlers/gestures/GestureDetector/utils.js +7 -7
  17. package/lib/commonjs/handlers/gestures/GestureDetector/utils.js.map +1 -1
  18. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -2
  19. package/lib/commonjs/useIsomorphicLayoutEffect.js +20 -0
  20. package/lib/commonjs/useIsomorphicLayoutEffect.js.map +1 -0
  21. package/lib/module/components/GestureHandlerRootView.android.js.map +1 -1
  22. package/lib/module/components/GestureHandlerRootView.js.map +1 -1
  23. package/lib/module/components/Pressable/Pressable.js +3 -1
  24. package/lib/module/components/Pressable/Pressable.js.map +1 -1
  25. package/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeable.js +5 -3
  26. package/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeable.js.map +1 -1
  27. package/lib/module/handlers/gestures/GestureDetector/index.js +3 -2
  28. package/lib/module/handlers/gestures/GestureDetector/index.js.map +1 -1
  29. package/lib/module/handlers/gestures/GestureDetector/utils.js +7 -7
  30. package/lib/module/handlers/gestures/GestureDetector/utils.js.map +1 -1
  31. package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -2
  32. package/lib/module/useIsomorphicLayoutEffect.js +15 -0
  33. package/lib/module/useIsomorphicLayoutEffect.js.map +1 -0
  34. package/lib/typescript/components/GestureHandlerRootView.android.d.ts +2 -2
  35. package/lib/typescript/components/GestureHandlerRootView.android.d.ts.map +1 -1
  36. package/lib/typescript/components/GestureHandlerRootView.d.ts +2 -2
  37. package/lib/typescript/components/GestureHandlerRootView.d.ts.map +1 -1
  38. package/lib/typescript/components/Pressable/Pressable.d.ts.map +1 -1
  39. package/lib/typescript/components/ReanimatedSwipeable/ReanimatedSwipeable.d.ts.map +1 -1
  40. package/lib/typescript/handlers/gestures/GestureDetector/index.d.ts.map +1 -1
  41. package/lib/typescript/handlers/gestures/GestureDetector/utils.d.ts +4 -4
  42. package/lib/typescript/handlers/gestures/GestureDetector/utils.d.ts.map +1 -1
  43. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +3 -2
  44. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts.map +1 -1
  45. package/lib/typescript/useIsomorphicLayoutEffect.d.ts +3 -0
  46. package/lib/typescript/useIsomorphicLayoutEffect.d.ts.map +1 -0
  47. package/package.json +1 -1
  48. package/src/components/GestureHandlerRootView.android.tsx +3 -2
  49. package/src/components/GestureHandlerRootView.tsx +3 -2
  50. package/src/components/Pressable/Pressable.tsx +4 -1
  51. package/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx +12 -3
  52. package/src/handlers/gestures/GestureDetector/index.tsx +3 -8
  53. package/src/handlers/gestures/GestureDetector/utils.ts +14 -8
  54. package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -2
  55. package/src/useIsomorphicLayoutEffect.tsx +19 -0
@@ -1,4 +1,10 @@
1
- import { useMemo, useCallback, useImperativeHandle, ForwardedRef } from 'react';
1
+ import {
2
+ useMemo,
3
+ useCallback,
4
+ useImperativeHandle,
5
+ ForwardedRef,
6
+ useState,
7
+ } from 'react';
2
8
  import { LayoutChangeEvent, View, I18nManager, StyleSheet } from 'react-native';
3
9
  import Animated, {
4
10
  useSharedValue,
@@ -82,6 +88,7 @@ const Swipeable = (props: SwipeableProps) => {
82
88
  ]
83
89
  );
84
90
 
91
+ const [shouldEnableTap, setShouldEnableTap] = useState(false);
85
92
  const rowState = useSharedValue<number>(0);
86
93
 
87
94
  const userDrag = useSharedValue<number>(0);
@@ -255,6 +262,8 @@ const Swipeable = (props: SwipeableProps) => {
255
262
  dispatchImmediateEvents(frozenRowState, toValue);
256
263
 
257
264
  rowState.value = Math.sign(toValue);
265
+
266
+ runOnJS(setShouldEnableTap)(rowState.value !== 0);
258
267
  },
259
268
  [
260
269
  rowState,
@@ -472,6 +481,7 @@ const Swipeable = (props: SwipeableProps) => {
472
481
  const tapGesture = useMemo(() => {
473
482
  const tap = Gesture.Tap()
474
483
  .shouldCancelWhenOutside(true)
484
+ .enabled(shouldEnableTap)
475
485
  .onStart(() => {
476
486
  if (rowState.value !== 0) {
477
487
  close();
@@ -485,9 +495,8 @@ const Swipeable = (props: SwipeableProps) => {
485
495
  relation as RelationPropType
486
496
  );
487
497
  });
488
-
489
498
  return tap;
490
- }, [close, relationProps, rowState]);
499
+ }, [close, relationProps, rowState, shouldEnableTap]);
491
500
 
492
501
  const panGesture = useMemo(() => {
493
502
  const pan = Gesture.Pan()
@@ -1,11 +1,5 @@
1
1
  /* eslint-disable react/no-unused-prop-types */
2
- import React, {
3
- useContext,
4
- useEffect,
5
- useLayoutEffect,
6
- useMemo,
7
- useRef,
8
- } from 'react';
2
+ import React, { useContext, useEffect, useMemo, useRef } from 'react';
9
3
  import { Platform } from 'react-native';
10
4
  import findNodeHandle from '../../../findNodeHandle';
11
5
  import { GestureType } from '../gesture';
@@ -24,6 +18,7 @@ import { Wrap, AnimatedWrap } from './Wrap';
24
18
  import { useDetectorUpdater } from './useDetectorUpdater';
25
19
  import { useViewRefHandler } from './useViewRefHandler';
26
20
  import { useMountReactions } from './useMountReactions';
21
+ import { useIsomorphicLayoutEffect } from '../../../useIsomorphicLayoutEffect';
27
22
 
28
23
  function propagateDetectorConfig(
29
24
  props: GestureDetectorProps,
@@ -149,7 +144,7 @@ export const GestureDetector = (props: GestureDetectorProps) => {
149
144
 
150
145
  useAnimatedGesture(preparedGesture, needsToRebuildReanimatedEvent);
151
146
 
152
- useLayoutEffect(() => {
147
+ useIsomorphicLayoutEffect(() => {
153
148
  const viewTag = findNodeHandle(state.viewRef) as number;
154
149
  preparedGesture.isMounted = true;
155
150
 
@@ -49,22 +49,28 @@ function convertToHandlerTag(ref: GestureRef): number {
49
49
  }
50
50
 
51
51
  function extractValidHandlerTags(interactionGroup: GestureRef[] | undefined) {
52
- return (
53
- interactionGroup?.map(convertToHandlerTag)?.filter((tag) => tag > 0) ?? []
52
+ return Array.from(
53
+ new Set(
54
+ interactionGroup?.map(convertToHandlerTag)?.filter((tag) => tag > 0) ?? []
55
+ )
54
56
  );
55
57
  }
56
58
 
57
59
  export function extractGestureRelations(gesture: GestureType) {
58
- const requireToFail = extractValidHandlerTags(gesture.config.requireToFail);
59
- const simultaneousWith = extractValidHandlerTags(
60
+ gesture.config.requireToFail = extractValidHandlerTags(
61
+ gesture.config.requireToFail
62
+ );
63
+ gesture.config.simultaneousWith = extractValidHandlerTags(
60
64
  gesture.config.simultaneousWith
61
65
  );
62
- const blocksHandlers = extractValidHandlerTags(gesture.config.blocksHandlers);
66
+ gesture.config.blocksHandlers = extractValidHandlerTags(
67
+ gesture.config.blocksHandlers
68
+ );
63
69
 
64
70
  return {
65
- waitFor: requireToFail,
66
- simultaneousHandlers: simultaneousWith,
67
- blocksHandlers: blocksHandlers,
71
+ waitFor: gesture.config.requireToFail,
72
+ simultaneousHandlers: gesture.config.simultaneousWith,
73
+ blocksHandlers: gesture.config.blocksHandlers,
68
74
  };
69
75
  }
70
76
 
@@ -1,6 +1,10 @@
1
1
  import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
2
2
  import type { ViewProps } from 'react-native';
3
3
 
4
- interface NativeProps extends ViewProps {}
4
+ export interface RootViewNativeProps extends ViewProps {
5
+ unstable_forceActive?: boolean;
6
+ }
5
7
 
6
- export default codegenNativeComponent<NativeProps>('RNGestureHandlerRootView');
8
+ export default codegenNativeComponent<RootViewNativeProps>(
9
+ 'RNGestureHandlerRootView'
10
+ );
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ // code below is modified version of the code found in:
3
+ // https://github.com/reduxjs/react-redux/blob/7e2fdd4ee2021e4282e12ba9fc722f09124e30cd/src/utils/useIsomorphicLayoutEffect.ts#L36
4
+ // React currently throws a warning when using useLayoutEffect on the server.
5
+ // To get around it, we can conditionally useEffect on the server (no-op) and
6
+
7
+ // useLayoutEffect in the browser.
8
+ const isDOM = !!(
9
+ typeof window !== 'undefined' &&
10
+ typeof window.document !== 'undefined' &&
11
+ typeof window.document.createElement !== 'undefined'
12
+ );
13
+
14
+ // Under React Native, we know that we always want to use useLayoutEffect
15
+ const isReactNative =
16
+ typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
17
+
18
+ export const useIsomorphicLayoutEffect =
19
+ isDOM || isReactNative ? React.useLayoutEffect : React.useEffect;