react-native-gesture-handler 2.32.0 → 2.33.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.
Files changed (227) hide show
  1. package/android/build.gradle +27 -11
  2. package/android/gradle.properties +1 -1
  3. package/android/src/main/java/com/swmansion/gesturehandler/core/FlingGestureHandler.kt +1 -1
  4. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +32 -33
  5. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +144 -15
  6. package/android/src/main/java/com/swmansion/gesturehandler/core/LongPressGestureHandler.kt +6 -3
  7. package/android/src/main/java/com/swmansion/gesturehandler/core/NativeViewGestureHandler.kt +23 -0
  8. package/android/src/main/java/com/swmansion/gesturehandler/core/PanGestureHandler.kt +4 -7
  9. package/android/src/main/java/com/swmansion/gesturehandler/core/TapGestureHandler.kt +1 -1
  10. package/android/src/main/java/com/swmansion/gesturehandler/react/Extensions.kt +3 -0
  11. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +2 -0
  12. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt +9 -0
  13. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootView.kt +8 -6
  14. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerTouchEvent.kt +2 -7
  15. package/apple/Handlers/RNFlingHandler.m +44 -4
  16. package/apple/Handlers/RNHoverHandler.m +24 -26
  17. package/apple/Handlers/RNLongPressHandler.m +4 -0
  18. package/apple/Handlers/RNPanHandler.m +44 -7
  19. package/apple/Handlers/RNTapHandler.m +35 -4
  20. package/apple/RNGHUIKit.h +10 -10
  21. package/apple/RNGestureHandler.h +2 -0
  22. package/apple/RNGestureHandler.mm +47 -6
  23. package/apple/RNGestureHandlerButton.mm +5 -3
  24. package/apple/RNGestureHandlerManager.mm +63 -6
  25. package/apple/RNGestureHandlerModule.mm +20 -0
  26. package/apple/RNGestureHandlerPointerTracker.m +64 -10
  27. package/apple/RNGestureHandlerPointerType.h +1 -0
  28. package/apple/RNManualActivationRecognizer.m +25 -6
  29. package/lib/commonjs/components/GestureComponents.js +21 -1
  30. package/lib/commonjs/components/GestureComponents.js.map +1 -1
  31. package/lib/commonjs/components/GestureHandlerButton.web.js +2 -1
  32. package/lib/commonjs/components/GestureHandlerButton.web.js.map +1 -1
  33. package/lib/commonjs/components/Pressable/Pressable.js +28 -3
  34. package/lib/commonjs/components/Pressable/Pressable.js.map +1 -1
  35. package/lib/commonjs/components/Pressable/index.js.map +1 -1
  36. package/lib/commonjs/components/ReanimatedDrawerLayout.js +4 -2
  37. package/lib/commonjs/components/ReanimatedDrawerLayout.js.map +1 -1
  38. package/lib/commonjs/components/ReanimatedSwipeable/ReanimatedSwipeable.js +32 -9
  39. package/lib/commonjs/components/ReanimatedSwipeable/ReanimatedSwipeable.js.map +1 -1
  40. package/lib/commonjs/components/Swipeable.js.map +1 -1
  41. package/lib/commonjs/components/Text.js.map +1 -1
  42. package/lib/commonjs/components/touchables/TouchableHighlight.js +1 -1
  43. package/lib/commonjs/components/touchables/TouchableHighlight.js.map +1 -1
  44. package/lib/commonjs/components/touchables/TouchableNativeFeedback.android.js.map +1 -1
  45. package/lib/commonjs/components/touchables/TouchableOpacity.js +1 -0
  46. package/lib/commonjs/components/touchables/TouchableOpacity.js.map +1 -1
  47. package/lib/commonjs/getShadowNodeFromRef.js +6 -2
  48. package/lib/commonjs/getShadowNodeFromRef.js.map +1 -1
  49. package/lib/commonjs/handlers/PanGestureHandler.js.map +1 -1
  50. package/lib/commonjs/handlers/gestures/GestureDetector/Wrap.js +56 -11
  51. package/lib/commonjs/handlers/gestures/GestureDetector/Wrap.js.map +1 -1
  52. package/lib/commonjs/handlers/gestures/GestureDetector/index.js +2 -1
  53. package/lib/commonjs/handlers/gestures/GestureDetector/index.js.map +1 -1
  54. package/lib/commonjs/handlers/gestures/GestureDetector/useDetectorUpdater.js +2 -1
  55. package/lib/commonjs/handlers/gestures/GestureDetector/useDetectorUpdater.js.map +1 -1
  56. package/lib/commonjs/handlers/gestures/GestureDetector/useMountReactions.js +6 -0
  57. package/lib/commonjs/handlers/gestures/GestureDetector/useMountReactions.js.map +1 -1
  58. package/lib/commonjs/handlers/gestures/GestureDetector/useViewRefHandler.js +3 -2
  59. package/lib/commonjs/handlers/gestures/GestureDetector/useViewRefHandler.js.map +1 -1
  60. package/lib/commonjs/handlers/gestures/gestureStateManager.web.js.map +1 -1
  61. package/lib/commonjs/handlers/gestures/panGesture.js +6 -3
  62. package/lib/commonjs/handlers/gestures/panGesture.js.map +1 -1
  63. package/lib/commonjs/hostInstance.js +39 -0
  64. package/lib/commonjs/hostInstance.js.map +1 -0
  65. package/lib/commonjs/index.js.map +1 -1
  66. package/lib/commonjs/mocks/mocks.js +1 -0
  67. package/lib/commonjs/mocks/mocks.js.map +1 -1
  68. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -1
  69. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.ts +16 -14
  70. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.ts +3 -3
  71. package/lib/commonjs/web/detectors/RotationGestureDetector.js +1 -1
  72. package/lib/commonjs/web/handlers/LongPressGestureHandler.js +3 -1
  73. package/lib/commonjs/web/handlers/LongPressGestureHandler.js.map +1 -1
  74. package/lib/commonjs/web/handlers/NativeViewGestureHandler.js +9 -1
  75. package/lib/commonjs/web/handlers/NativeViewGestureHandler.js.map +1 -1
  76. package/lib/commonjs/web/handlers/PanGestureHandler.js +8 -9
  77. package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
  78. package/lib/commonjs/web/handlers/TapGestureHandler.js +1 -1
  79. package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js +14 -0
  80. package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js.map +1 -1
  81. package/lib/commonjs/web/tools/WheelEventManager.js +4 -0
  82. package/lib/commonjs/web/tools/WheelEventManager.js.map +1 -1
  83. package/lib/module/components/GestureComponents.js +23 -2
  84. package/lib/module/components/GestureComponents.js.map +1 -1
  85. package/lib/module/components/GestureHandlerButton.web.js +2 -1
  86. package/lib/module/components/GestureHandlerButton.web.js.map +1 -1
  87. package/lib/module/components/Pressable/Pressable.js +28 -3
  88. package/lib/module/components/Pressable/Pressable.js.map +1 -1
  89. package/lib/module/components/Pressable/index.js.map +1 -1
  90. package/lib/module/components/ReanimatedDrawerLayout.js +4 -2
  91. package/lib/module/components/ReanimatedDrawerLayout.js.map +1 -1
  92. package/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeable.js +34 -11
  93. package/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeable.js.map +1 -1
  94. package/lib/module/components/Swipeable.js.map +1 -1
  95. package/lib/module/components/Text.js.map +1 -1
  96. package/lib/module/components/touchables/TouchableHighlight.js +2 -2
  97. package/lib/module/components/touchables/TouchableHighlight.js.map +1 -1
  98. package/lib/module/components/touchables/TouchableNativeFeedback.android.js.map +1 -1
  99. package/lib/module/components/touchables/TouchableOpacity.js +1 -0
  100. package/lib/module/components/touchables/TouchableOpacity.js.map +1 -1
  101. package/lib/module/getShadowNodeFromRef.js +7 -2
  102. package/lib/module/getShadowNodeFromRef.js.map +1 -1
  103. package/lib/module/handlers/PanGestureHandler.js.map +1 -1
  104. package/lib/module/handlers/gestures/GestureDetector/Wrap.js +56 -11
  105. package/lib/module/handlers/gestures/GestureDetector/Wrap.js.map +1 -1
  106. package/lib/module/handlers/gestures/GestureDetector/index.js +2 -1
  107. package/lib/module/handlers/gestures/GestureDetector/index.js.map +1 -1
  108. package/lib/module/handlers/gestures/GestureDetector/useDetectorUpdater.js +2 -1
  109. package/lib/module/handlers/gestures/GestureDetector/useDetectorUpdater.js.map +1 -1
  110. package/lib/module/handlers/gestures/GestureDetector/useMountReactions.js +6 -0
  111. package/lib/module/handlers/gestures/GestureDetector/useMountReactions.js.map +1 -1
  112. package/lib/module/handlers/gestures/GestureDetector/useViewRefHandler.js +3 -2
  113. package/lib/module/handlers/gestures/GestureDetector/useViewRefHandler.js.map +1 -1
  114. package/lib/module/handlers/gestures/gestureStateManager.web.js.map +1 -1
  115. package/lib/module/handlers/gestures/panGesture.js +6 -3
  116. package/lib/module/handlers/gestures/panGesture.js.map +1 -1
  117. package/lib/module/hostInstance.js +32 -0
  118. package/lib/module/hostInstance.js.map +1 -0
  119. package/lib/module/index.js.map +1 -1
  120. package/lib/module/mocks/mocks.js +3 -2
  121. package/lib/module/mocks/mocks.js.map +1 -1
  122. package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -1
  123. package/lib/module/specs/RNGestureHandlerButtonNativeComponent.ts +16 -14
  124. package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.ts +3 -3
  125. package/lib/module/web/detectors/RotationGestureDetector.js +1 -1
  126. package/lib/module/web/handlers/LongPressGestureHandler.js +3 -1
  127. package/lib/module/web/handlers/LongPressGestureHandler.js.map +1 -1
  128. package/lib/module/web/handlers/NativeViewGestureHandler.js +9 -1
  129. package/lib/module/web/handlers/NativeViewGestureHandler.js.map +1 -1
  130. package/lib/module/web/handlers/PanGestureHandler.js +8 -9
  131. package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
  132. package/lib/module/web/handlers/TapGestureHandler.js +1 -1
  133. package/lib/module/web/tools/GestureHandlerOrchestrator.js +14 -0
  134. package/lib/module/web/tools/GestureHandlerOrchestrator.js.map +1 -1
  135. package/lib/module/web/tools/WheelEventManager.js +4 -0
  136. package/lib/module/web/tools/WheelEventManager.js.map +1 -1
  137. package/lib/typescript/components/GestureButtons.d.ts +3 -1
  138. package/lib/typescript/components/GestureButtons.d.ts.map +1 -1
  139. package/lib/typescript/components/GestureButtonsProps.d.ts +10 -0
  140. package/lib/typescript/components/GestureButtonsProps.d.ts.map +1 -1
  141. package/lib/typescript/components/GestureComponents.d.ts +8 -7
  142. package/lib/typescript/components/GestureComponents.d.ts.map +1 -1
  143. package/lib/typescript/components/GestureComponents.web.d.ts +12 -4
  144. package/lib/typescript/components/GestureComponents.web.d.ts.map +1 -1
  145. package/lib/typescript/components/GestureHandlerButton.web.d.ts +2 -2
  146. package/lib/typescript/components/GestureHandlerButton.web.d.ts.map +1 -1
  147. package/lib/typescript/components/Pressable/Pressable.d.ts.map +1 -1
  148. package/lib/typescript/components/Pressable/PressableProps.d.ts +1 -1
  149. package/lib/typescript/components/Pressable/PressableProps.d.ts.map +1 -1
  150. package/lib/typescript/components/Pressable/index.d.ts +1 -1
  151. package/lib/typescript/components/Pressable/index.d.ts.map +1 -1
  152. package/lib/typescript/components/ReanimatedDrawerLayout.d.ts.map +1 -1
  153. package/lib/typescript/components/ReanimatedSwipeable/ReanimatedSwipeable.d.ts.map +1 -1
  154. package/lib/typescript/components/Swipeable.d.ts.map +1 -1
  155. package/lib/typescript/components/touchables/TouchableHighlight.d.ts +1 -1
  156. package/lib/typescript/components/touchables/TouchableHighlight.d.ts.map +1 -1
  157. package/lib/typescript/components/touchables/TouchableNativeFeedback.android.d.ts +1 -1
  158. package/lib/typescript/components/touchables/TouchableNativeFeedback.android.d.ts.map +1 -1
  159. package/lib/typescript/components/touchables/TouchableOpacity.d.ts.map +1 -1
  160. package/lib/typescript/getShadowNodeFromRef.d.ts.map +1 -1
  161. package/lib/typescript/handlers/PanGestureHandler.d.ts +12 -0
  162. package/lib/typescript/handlers/PanGestureHandler.d.ts.map +1 -1
  163. package/lib/typescript/handlers/gestures/GestureDetector/Wrap.d.ts +11 -0
  164. package/lib/typescript/handlers/gestures/GestureDetector/Wrap.d.ts.map +1 -1
  165. package/lib/typescript/handlers/gestures/GestureDetector/index.d.ts.map +1 -1
  166. package/lib/typescript/handlers/gestures/GestureDetector/useDetectorUpdater.d.ts.map +1 -1
  167. package/lib/typescript/handlers/gestures/GestureDetector/useMountReactions.d.ts.map +1 -1
  168. package/lib/typescript/handlers/gestures/GestureDetector/useViewRefHandler.d.ts.map +1 -1
  169. package/lib/typescript/handlers/gestures/gestureStateManager.web.d.ts +8 -1
  170. package/lib/typescript/handlers/gestures/gestureStateManager.web.d.ts.map +1 -1
  171. package/lib/typescript/handlers/gestures/panGesture.d.ts +6 -3
  172. package/lib/typescript/handlers/gestures/panGesture.d.ts.map +1 -1
  173. package/lib/typescript/hostInstance.d.ts +10 -0
  174. package/lib/typescript/hostInstance.d.ts.map +1 -0
  175. package/lib/typescript/index.d.ts +1 -1
  176. package/lib/typescript/index.d.ts.map +1 -1
  177. package/lib/typescript/mocks/mocks.d.ts +67 -15
  178. package/lib/typescript/mocks/mocks.d.ts.map +1 -1
  179. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +6 -7
  180. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts.map +1 -1
  181. package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +9 -10
  182. package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts.map +1 -1
  183. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +2 -2
  184. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts.map +1 -1
  185. package/lib/typescript/web/handlers/LongPressGestureHandler.d.ts.map +1 -1
  186. package/lib/typescript/web/handlers/NativeViewGestureHandler.d.ts +1 -0
  187. package/lib/typescript/web/handlers/NativeViewGestureHandler.d.ts.map +1 -1
  188. package/lib/typescript/web/handlers/PanGestureHandler.d.ts.map +1 -1
  189. package/lib/typescript/web/tools/GestureHandlerOrchestrator.d.ts +1 -0
  190. package/lib/typescript/web/tools/GestureHandlerOrchestrator.d.ts.map +1 -1
  191. package/lib/typescript/web/tools/WheelEventManager.d.ts.map +1 -1
  192. package/package.json +7 -7
  193. package/src/components/GestureButtonsProps.ts +14 -0
  194. package/src/components/GestureComponents.tsx +38 -7
  195. package/src/components/GestureHandlerButton.web.tsx +7 -3
  196. package/src/components/Pressable/Pressable.tsx +33 -4
  197. package/src/components/Pressable/PressableProps.tsx +1 -1
  198. package/src/components/Pressable/index.ts +1 -0
  199. package/src/components/ReanimatedDrawerLayout.tsx +4 -1
  200. package/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx +49 -10
  201. package/src/components/Swipeable.tsx +6 -2
  202. package/src/components/Text.tsx +3 -3
  203. package/src/components/touchables/TouchableHighlight.tsx +4 -2
  204. package/src/components/touchables/TouchableNativeFeedback.android.tsx +8 -2
  205. package/src/components/touchables/TouchableOpacity.tsx +1 -0
  206. package/src/getShadowNodeFromRef.ts +11 -4
  207. package/src/handlers/PanGestureHandler.ts +15 -0
  208. package/src/handlers/gestures/GestureDetector/Wrap.tsx +78 -13
  209. package/src/handlers/gestures/GestureDetector/index.tsx +4 -1
  210. package/src/handlers/gestures/GestureDetector/useDetectorUpdater.ts +4 -1
  211. package/src/handlers/gestures/GestureDetector/useMountReactions.ts +6 -0
  212. package/src/handlers/gestures/GestureDetector/useViewRefHandler.ts +5 -2
  213. package/src/handlers/gestures/gestureStateManager.web.ts +9 -1
  214. package/src/handlers/gestures/panGesture.ts +6 -3
  215. package/src/hostInstance.ts +57 -0
  216. package/src/index.ts +1 -0
  217. package/src/mocks/mocks.tsx +6 -2
  218. package/src/specs/NativeRNGestureHandlerModule.ts +16 -10
  219. package/src/specs/RNGestureHandlerButtonNativeComponent.ts +16 -14
  220. package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +3 -3
  221. package/src/web/detectors/RotationGestureDetector.ts +1 -1
  222. package/src/web/handlers/LongPressGestureHandler.ts +3 -1
  223. package/src/web/handlers/NativeViewGestureHandler.ts +11 -2
  224. package/src/web/handlers/PanGestureHandler.ts +8 -11
  225. package/src/web/handlers/TapGestureHandler.ts +1 -1
  226. package/src/web/tools/GestureHandlerOrchestrator.ts +19 -0
  227. package/src/web/tools/WheelEventManager.ts +1 -0
@@ -6,6 +6,7 @@ import { GestureType } from '../gesture';
6
6
  import { UserSelect, TouchAction } from '../../gestureHandlerCommon';
7
7
  import { ComposedGesture } from '../gestureComposition';
8
8
  import { isTestEnv } from '../../../utils';
9
+ import { resolveHostInstance } from '../../../hostInstance';
9
10
 
10
11
  import GestureHandlerRootViewContext from '../../../GestureHandlerRootViewContext';
11
12
  import { AttachedGestureState, GestureDetectorState } from './types';
@@ -149,7 +150,9 @@ export const GestureDetector = (props: GestureDetectorProps) => {
149
150
  useAnimatedGesture(preparedGesture, needsToRebuildReanimatedEvent);
150
151
 
151
152
  useIsomorphicLayoutEffect(() => {
152
- const viewTag = findNodeHandle(state.viewRef) as number;
153
+ const viewTag = findNodeHandle(
154
+ resolveHostInstance(state.viewRef)
155
+ ) as number;
153
156
  preparedGesture.isMounted = true;
154
157
 
155
158
  attachHandlers({
@@ -2,6 +2,7 @@ import React, { useCallback } from 'react';
2
2
  import { GestureType } from '../gesture';
3
3
  import { ComposedGesture } from '../gestureComposition';
4
4
 
5
+ import { resolveHostInstance } from '../../../hostInstance';
5
6
  import {
6
7
  AttachedGestureState,
7
8
  GestureDetectorState,
@@ -29,7 +30,9 @@ export function useDetectorUpdater(
29
30
  // skipConfigUpdate is used to prevent unnecessary updates when only checking if the view has changed
30
31
  (skipConfigUpdate?: boolean) => {
31
32
  // If the underlying view has changed we need to reattach handlers to the new view
32
- const viewTag = findNodeHandle(state.viewRef) as number;
33
+ const viewTag = findNodeHandle(
34
+ resolveHostInstance(state.viewRef)
35
+ ) as number;
33
36
  const didUnderlyingViewChange = viewTag !== state.previousViewTag;
34
37
 
35
38
  if (
@@ -27,6 +27,12 @@ export function useMountReactions(
27
27
  ) {
28
28
  useEffect(() => {
29
29
  return MountRegistry.addMountListener((gesture) => {
30
+ // The detector may already be unmounted when this fires; bail out to avoid
31
+ // updating a detached detector.
32
+ if (!state.isMounted) {
33
+ return;
34
+ }
35
+
30
36
  // At this point the ref in the gesture config should be updated, so we can check if one of the gestures
31
37
  // set in a relation with the gesture got mounted. If so, we need to update the detector to propagate
32
38
  // the changes to the native side.
@@ -4,6 +4,7 @@ import { getShadowNodeFromRef } from '../../../getShadowNodeFromRef';
4
4
  import { GestureDetectorState } from './types';
5
5
  import React, { useCallback } from 'react';
6
6
  import findNodeHandle from '../../../findNodeHandle';
7
+ import { resolveHostInstance } from '../../../hostInstance';
7
8
 
8
9
  declare const global: {
9
10
  isViewFlatteningDisabled: (node: unknown) => boolean | null; // JSI function
@@ -26,7 +27,9 @@ export function useViewRefHandler(
26
27
 
27
28
  // if it's the first render, also set the previousViewTag to prevent reattaching gestures when not needed
28
29
  if (state.previousViewTag === -1) {
29
- state.previousViewTag = findNodeHandle(state.viewRef) as number;
30
+ state.previousViewTag = findNodeHandle(
31
+ resolveHostInstance(state.viewRef)
32
+ ) as number;
30
33
  }
31
34
 
32
35
  // Pass true as `skipConfigUpdate`. Here we only want to trigger the eventual reattaching of handlers
@@ -36,7 +39,7 @@ export function useViewRefHandler(
36
39
  }
37
40
 
38
41
  if (__DEV__ && isFabric() && global.isViewFlatteningDisabled) {
39
- const node = getShadowNodeFromRef(ref);
42
+ const node = getShadowNodeFromRef(resolveHostInstance(ref));
40
43
  if (global.isViewFlatteningDisabled(node) === false) {
41
44
  console.error(
42
45
  tagMessage(
@@ -1,5 +1,13 @@
1
1
  import NodeManager from '../../web/tools/NodeManager';
2
- import { GestureStateManagerType } from './gestureStateManager';
2
+
3
+ export interface GestureStateManagerType {
4
+ begin: () => void;
5
+ activate: () => void;
6
+ fail: () => void;
7
+ end: () => void;
8
+ /** @internal */
9
+ handlerTag: number;
10
+ }
3
11
 
4
12
  export const GestureStateManager = {
5
13
  create(handlerTag: number): GestureStateManagerType {
@@ -147,7 +147,8 @@ export class PanGesture extends ContinousBaseGesture<
147
147
  }
148
148
 
149
149
  /**
150
- * Minimum velocity the finger has to reach in order to activate handler.
150
+ * Minimum speed the pointer has to reach in order to activate handler.
151
+ * Expressed in points per second.
151
152
  * @param velocity
152
153
  */
153
154
  minVelocity(velocity: number) {
@@ -156,7 +157,8 @@ export class PanGesture extends ContinousBaseGesture<
156
157
  }
157
158
 
158
159
  /**
159
- * Minimum velocity along X axis the finger has to reach in order to activate handler.
160
+ * Minimum speed along X axis the pointer has to reach in order to activate handler.
161
+ * Expressed in points per second.
160
162
  * @param velocity
161
163
  */
162
164
  minVelocityX(velocity: number) {
@@ -165,7 +167,8 @@ export class PanGesture extends ContinousBaseGesture<
165
167
  }
166
168
 
167
169
  /**
168
- * Minimum velocity along Y axis the finger has to reach in order to activate handler.
170
+ * Minimum speed along Y axis the pointer has to reach in order to activate handler.
171
+ * Expressed in points per second.
169
172
  * @param velocity
170
173
  */
171
174
  minVelocityY(velocity: number) {
@@ -0,0 +1,57 @@
1
+ import type { Ref } from 'react';
2
+
3
+ export type WrapRef = Ref<unknown> | undefined;
4
+
5
+ export function assignRef(
6
+ ref: WrapRef,
7
+ instance: unknown
8
+ ): (() => void) | undefined {
9
+ if (typeof ref === 'function') {
10
+ const cleanup = ref(instance as never);
11
+ return typeof cleanup === 'function' ? cleanup : undefined;
12
+ }
13
+
14
+ if (ref) {
15
+ ref.current = instance;
16
+ }
17
+
18
+ return undefined;
19
+ }
20
+
21
+ export function isHostInstance(instance: unknown) {
22
+ return (
23
+ (instance as { __internalInstanceHandle?: unknown } | null | undefined)
24
+ ?.__internalInstanceHandle !== undefined
25
+ );
26
+ }
27
+
28
+ export function preferHostInstance(instance: unknown) {
29
+ if (instance === null || instance === undefined || isHostInstance(instance)) {
30
+ return instance;
31
+ }
32
+
33
+ const nativeRef = (
34
+ instance as { getNativeScrollRef?: () => unknown }
35
+ ).getNativeScrollRef?.();
36
+
37
+ return isHostInstance(nativeRef) ? nativeRef : instance;
38
+ }
39
+
40
+ export interface HostInstanceProvider {
41
+ getHostInstance: () => unknown;
42
+ }
43
+
44
+ function providesHostInstance(ref: unknown): ref is HostInstanceProvider {
45
+ return (
46
+ typeof (ref as HostInstanceProvider | null | undefined)?.getHostInstance ===
47
+ 'function'
48
+ );
49
+ }
50
+
51
+ export function resolveHostInstance<T>(ref: T): T {
52
+ if (!providesHostInstance(ref)) {
53
+ return ref;
54
+ }
55
+
56
+ return (ref.getHostInstance() ?? ref) as T;
57
+ }
package/src/index.ts CHANGED
@@ -146,6 +146,7 @@ export type {
146
146
  export type { SwipeableProps } from './components/Swipeable';
147
147
  export { default as Swipeable } from './components/Swipeable';
148
148
  export type {
149
+ PressableEvent,
149
150
  PressableProps,
150
151
  PressableStateCallbackType,
151
152
  } from './components/Pressable';
@@ -8,7 +8,9 @@ import {
8
8
  FlatList,
9
9
  Switch,
10
10
  TextInput,
11
+ TextInputProps,
11
12
  DrawerLayoutAndroid,
13
+ DrawerLayoutAndroidProps,
12
14
  View,
13
15
  } from 'react-native';
14
16
  import { State } from '../State';
@@ -48,8 +50,10 @@ export default {
48
50
  ScrollView,
49
51
  FlatList,
50
52
  Switch,
51
- TextInput,
52
- DrawerLayoutAndroid,
53
+ // Explicit types keep the emitted declaration portable under TS 6.
54
+ TextInput: TextInput as React.ComponentType<TextInputProps>,
55
+ DrawerLayoutAndroid:
56
+ DrawerLayoutAndroid as React.ComponentType<DrawerLayoutAndroidProps>,
53
57
  NativeViewGestureHandler,
54
58
  TapGestureHandler,
55
59
  ForceTouchGestureHandler,
@@ -1,24 +1,30 @@
1
- import { TurboModuleRegistry, TurboModule } from 'react-native';
2
- import { Double } from 'react-native/Libraries/Types/CodegenTypes';
1
+ import type { CodegenTypes, TurboModule } from 'react-native';
2
+ import { TurboModuleRegistry } from 'react-native';
3
3
 
4
4
  export interface Spec extends TurboModule {
5
- handleSetJSResponder: (tag: Double, blockNativeResponder: boolean) => void;
5
+ handleSetJSResponder: (
6
+ tag: CodegenTypes.Double,
7
+ blockNativeResponder: boolean
8
+ ) => void;
6
9
  handleClearJSResponder: () => void;
7
10
  createGestureHandler: (
8
11
  handlerName: string,
9
- handlerTag: Double,
12
+ handlerTag: CodegenTypes.Double,
10
13
  // Record<> is not supported by codegen
11
14
  // eslint-disable-next-line @typescript-eslint/ban-types
12
15
  config: Object
13
16
  ) => void;
14
17
  attachGestureHandler: (
15
- handlerTag: Double,
16
- newView: Double,
17
- actionType: Double
18
+ handlerTag: CodegenTypes.Double,
19
+ newView: CodegenTypes.Double,
20
+ actionType: CodegenTypes.Double
21
+ ) => void;
22
+ updateGestureHandler: (
23
+ handlerTag: CodegenTypes.Double,
24
+ // eslint-disable-next-line @typescript-eslint/ban-types
25
+ newConfig: Object
18
26
  ) => void;
19
- // eslint-disable-next-line @typescript-eslint/ban-types
20
- updateGestureHandler: (handlerTag: Double, newConfig: Object) => void;
21
- dropGestureHandler: (handlerTag: Double) => void;
27
+ dropGestureHandler: (handlerTag: CodegenTypes.Double) => void;
22
28
  install: () => boolean;
23
29
  flushOperations: () => void;
24
30
  }
@@ -1,27 +1,29 @@
1
- import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
1
+ import { codegenNativeComponent } from 'react-native';
2
2
  import type {
3
- Int32,
4
- WithDefault,
5
- Float,
6
- } from 'react-native/Libraries/Types/CodegenTypes';
7
- import type { ViewProps, ColorValue } from 'react-native';
3
+ CodegenTypes,
4
+ HostComponent,
5
+ ViewProps,
6
+ ColorValue,
7
+ } from 'react-native';
8
8
 
9
9
  // @ts-ignore - Redefining pointerEvents with WithDefault for codegen, conflicts with ViewProps type but codegen needs it
10
10
  interface NativeProps extends ViewProps {
11
- exclusive?: WithDefault<boolean, true>;
11
+ exclusive?: CodegenTypes.WithDefault<boolean, true>;
12
12
  foreground?: boolean;
13
13
  borderless?: boolean;
14
- enabled?: WithDefault<boolean, true>;
14
+ enabled?: CodegenTypes.WithDefault<boolean, true>;
15
15
  rippleColor?: ColorValue;
16
- rippleRadius?: Int32;
17
- touchSoundDisabled?: WithDefault<boolean, false>;
18
- borderWidth?: Float;
16
+ rippleRadius?: CodegenTypes.Int32;
17
+ touchSoundDisabled?: CodegenTypes.WithDefault<boolean, false>;
18
+ borderWidth?: CodegenTypes.Float;
19
19
  borderColor?: ColorValue;
20
- borderStyle?: WithDefault<string, 'solid'>;
21
- pointerEvents?: WithDefault<
20
+ borderStyle?: CodegenTypes.WithDefault<string, 'solid'>;
21
+ pointerEvents?: CodegenTypes.WithDefault<
22
22
  'box-none' | 'none' | 'box-only' | 'auto',
23
23
  'auto'
24
24
  >;
25
25
  }
26
26
 
27
- export default codegenNativeComponent<NativeProps>('RNGestureHandlerButton');
27
+ export default codegenNativeComponent<NativeProps>(
28
+ 'RNGestureHandlerButton'
29
+ ) as HostComponent<NativeProps>;
@@ -1,5 +1,5 @@
1
- import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
2
- import type { ViewProps } from 'react-native';
1
+ import { codegenNativeComponent } from 'react-native';
2
+ import type { HostComponent, ViewProps } from 'react-native';
3
3
 
4
4
  export interface RootViewNativeProps extends ViewProps {
5
5
  unstable_forceActive?: boolean;
@@ -7,4 +7,4 @@ export interface RootViewNativeProps extends ViewProps {
7
7
 
8
8
  export default codegenNativeComponent<RootViewNativeProps>(
9
9
  'RNGestureHandlerRootView'
10
- );
10
+ ) as HostComponent<RootViewNativeProps>;
@@ -163,6 +163,6 @@ export default class RotationGestureDetector
163
163
  }
164
164
 
165
165
  public get timeDelta() {
166
- return this.currentTime + this.previousTime;
166
+ return this.currentTime - this.previousTime;
167
167
  }
168
168
  }
@@ -5,6 +5,7 @@ import GestureHandler from './GestureHandler';
5
5
 
6
6
  const DEFAULT_MIN_DURATION_MS = 500;
7
7
  const DEFAULT_MAX_DIST_DP = 10;
8
+ const DEFAULT_NUMBER_OF_POINTERS = 1;
8
9
  const SCALING_FACTOR = 10;
9
10
 
10
11
  export default class LongPressGestureHandler extends GestureHandler {
@@ -12,7 +13,7 @@ export default class LongPressGestureHandler extends GestureHandler {
12
13
  private defaultMaxDistSq = DEFAULT_MAX_DIST_DP * SCALING_FACTOR;
13
14
 
14
15
  private maxDistSq = this.defaultMaxDistSq;
15
- private numberOfPointers = 1;
16
+ private numberOfPointers = DEFAULT_NUMBER_OF_POINTERS;
16
17
  private startX = 0;
17
18
  private startY = 0;
18
19
 
@@ -56,6 +57,7 @@ export default class LongPressGestureHandler extends GestureHandler {
56
57
  super.resetConfig();
57
58
  this.minDurationMs = DEFAULT_MIN_DURATION_MS;
58
59
  this.maxDistSq = this.defaultMaxDistSq;
60
+ this.numberOfPointers = DEFAULT_NUMBER_OF_POINTERS;
59
61
  }
60
62
 
61
63
  protected onStateChange(_newState: State, _oldState: State): void {
@@ -20,8 +20,6 @@ export default class NativeViewGestureHandler extends GestureHandler {
20
20
  public init(ref: number, propsRef: React.RefObject<unknown>): void {
21
21
  super.init(ref, propsRef);
22
22
 
23
- this.shouldCancelWhenOutside = true;
24
-
25
23
  if (Platform.OS !== 'web') {
26
24
  return;
27
25
  }
@@ -33,6 +31,9 @@ export default class NativeViewGestureHandler extends GestureHandler {
33
31
  }
34
32
 
35
33
  public updateGestureConfig({ enabled = true, ...props }: Config): void {
34
+ // Config updates are full replaces, so restore the defaults first - the
35
+ // module never calls `resetConfig` on its own.
36
+ this.resetConfig();
36
37
  super.updateGestureConfig({ enabled: enabled, ...props });
37
38
 
38
39
  if (this.config.shouldActivateOnStart !== undefined) {
@@ -46,6 +47,14 @@ export default class NativeViewGestureHandler extends GestureHandler {
46
47
  this.restoreViewStyles(view);
47
48
  }
48
49
 
50
+ protected override resetConfig(): void {
51
+ super.resetConfig();
52
+
53
+ this.shouldCancelWhenOutside = true;
54
+ this.shouldActivateOnStart = false;
55
+ this.disallowInterruption = false;
56
+ }
57
+
49
58
  private restoreViewStyles(view: HTMLElement) {
50
59
  if (!view) {
51
60
  return;
@@ -82,8 +82,7 @@ export default class PanGestureHandler extends GestureHandler {
82
82
  }
83
83
 
84
84
  if (this.config.minVelocity !== undefined) {
85
- this.minVelocityX = this.config.minVelocity;
86
- this.minVelocityY = this.config.minVelocity;
85
+ this.minVelocitySq = this.config.minVelocity * this.config.minVelocity;
87
86
  }
88
87
 
89
88
  if (this.config.minVelocityX !== undefined) {
@@ -191,6 +190,7 @@ export default class PanGestureHandler extends GestureHandler {
191
190
  this.maxPointers = DEFAULT_MAX_POINTERS;
192
191
 
193
192
  this.activateAfterLongPress = 0;
193
+ this.enableTrackpadTwoFingerGesture = false;
194
194
  }
195
195
 
196
196
  protected transformNativeEvent() {
@@ -354,14 +354,13 @@ export default class PanGestureHandler extends GestureHandler {
354
354
  }
355
355
  }
356
356
 
357
- private scheduleWheelEnd(event: AdaptedEvent) {
357
+ private scheduleWheelEnd() {
358
358
  clearTimeout(this.endWheelTimeout);
359
359
 
360
360
  this.endWheelTimeout = setTimeout(() => {
361
361
  if (this.state === State.ACTIVE) {
362
362
  this.end();
363
- this.tracker.removeFromTracker(event.pointerId);
364
- this.state = State.UNDETERMINED;
363
+ this.reset();
365
364
  }
366
365
 
367
366
  this.wheelDevice = WheelDevice.UNDETERMINED;
@@ -383,7 +382,7 @@ export default class PanGestureHandler extends GestureHandler {
383
382
  : WheelDevice.MOUSE;
384
383
 
385
384
  if (this.wheelDevice === WheelDevice.MOUSE) {
386
- this.scheduleWheelEnd(event);
385
+ this.scheduleWheelEnd();
387
386
  return;
388
387
  }
389
388
 
@@ -403,7 +402,7 @@ export default class PanGestureHandler extends GestureHandler {
403
402
  this.updateVelocity(event.pointerId);
404
403
 
405
404
  this.tryToSendMoveEvent(false, event);
406
- this.scheduleWheelEnd(event);
405
+ this.scheduleWheelEnd();
407
406
  }
408
407
 
409
408
  private shouldActivate(): boolean {
@@ -452,8 +451,7 @@ export default class PanGestureHandler extends GestureHandler {
452
451
 
453
452
  if (
454
453
  this.minVelocityX !== Number.MAX_SAFE_INTEGER &&
455
- ((this.minVelocityX < 0 && vx <= this.minVelocityX) ||
456
- (this.minVelocityX >= 0 && this.minVelocityX <= vx))
454
+ Math.abs(vx) >= Math.abs(this.minVelocityX)
457
455
  ) {
458
456
  return true;
459
457
  }
@@ -461,8 +459,7 @@ export default class PanGestureHandler extends GestureHandler {
461
459
  const vy: number = this.velocityY;
462
460
  if (
463
461
  this.minVelocityY !== Number.MAX_SAFE_INTEGER &&
464
- ((this.minVelocityY < 0 && vy <= this.minVelocityY) ||
465
- (this.minVelocityY >= 0 && this.minVelocityY <= vy))
462
+ Math.abs(vy) >= Math.abs(this.minVelocityY)
466
463
  ) {
467
464
  return true;
468
465
  }
@@ -159,7 +159,7 @@ export default class TapGestureHandler extends GestureHandler {
159
159
  this.tracker.removeFromTracker(event.pointerId);
160
160
 
161
161
  this.offsetX += this.lastX - this.startX;
162
- this.offsetY += this.lastY = this.startY;
162
+ this.offsetY += this.lastY - this.startY;
163
163
 
164
164
  this.updateLastCoords();
165
165
 
@@ -264,7 +264,26 @@ export default class GestureHandlerOrchestrator {
264
264
  handler.activationIndex = this.activationIndex++;
265
265
  }
266
266
 
267
+ // A handler whose pointer sequence ended before it began (e.g. a press
268
+ // outside a negative hit slop) never reaches a finished state, so
269
+ // `cleanupFinishedHandlers` never drops it and it would block or park every
270
+ // later gesture. Drop such idle entries before a new gesture consults them.
271
+ private dropIdleHandlers(): void {
272
+ for (let i = this.gestureHandlers.length - 1; i >= 0; --i) {
273
+ const handler = this.gestureHandlers[i];
274
+
275
+ if (
276
+ handler.state === State.UNDETERMINED &&
277
+ handler.tracker.trackedPointersCount === 0
278
+ ) {
279
+ this.removeHandlerFromOrchestrator(handler);
280
+ }
281
+ }
282
+ }
283
+
267
284
  public recordHandlerIfNotPresent(handler: IGestureHandler): void {
285
+ this.dropIdleHandlers();
286
+
268
287
  if (this.gestureHandlers.includes(handler)) {
269
288
  return;
270
289
  }
@@ -44,5 +44,6 @@ export default class WheelEventManager extends EventManager<HTMLElement> {
44
44
 
45
45
  public resetManager(): void {
46
46
  super.resetManager();
47
+ this.wheelDelta = { x: 0, y: 0 };
47
48
  }
48
49
  }