react-native-gesture-handler 2.2.0 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (260) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +5 -1
  3. package/RNGestureHandler.podspec +27 -3
  4. package/android/build.gradle +81 -8
  5. package/android/lib/src/main/java/com/swmansion/gesturehandler/GestureHandler.kt +5 -1
  6. package/android/lib/src/main/java/com/swmansion/gesturehandler/GestureHandlerOrchestrator.kt +14 -12
  7. package/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt +2 -4
  8. package/android/lib/src/main/java/com/swmansion/gesturehandler/ScaleGestureDetector.java +558 -0
  9. package/android/src/fabric/java/com/swmansion/gesturehandler/RNGestureHandlerComponentsRegistry.java +29 -0
  10. package/android/src/fabric/java/com/swmansion/gesturehandler/ReactContextExtensions.kt +12 -0
  11. package/android/src/main/AndroidManifest.xml +1 -1
  12. package/android/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerPackage.kt +29 -0
  13. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +40 -13
  14. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +111 -47
  15. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRegistry.kt +9 -4
  16. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt +1 -1
  17. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootViewManager.kt +17 -2
  18. package/android/src/main/jni/Android.mk +53 -0
  19. package/android/src/main/jni/OnLoad.cpp +9 -0
  20. package/android/src/main/jni/RNGestureHandlerComponentsRegistry.cpp +71 -0
  21. package/android/src/main/jni/RNGestureHandlerComponentsRegistry.h +34 -0
  22. package/android/src/main/jni/cpp-adapter.cpp +41 -0
  23. package/android/src/paper/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.java +47 -0
  24. package/android/src/paper/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerInterface.java +22 -0
  25. package/android/src/paper/java/com/facebook/react/viewmanagers/RNGestureHandlerRootViewManagerDelegate.java +25 -0
  26. package/android/src/paper/java/com/facebook/react/viewmanagers/RNGestureHandlerRootViewManagerInterface.java +16 -0
  27. package/android/src/paper/java/com/swmansion/gesturehandler/ReactContextExtensions.kt +13 -0
  28. package/ios/Handlers/RNFlingHandler.m +2 -0
  29. package/ios/Handlers/RNPanHandler.m +2 -0
  30. package/ios/Handlers/RNPinchHandler.m +2 -0
  31. package/ios/Handlers/RNRotationHandler.m +2 -0
  32. package/ios/RNGestureHandler.h +3 -8
  33. package/ios/RNGestureHandler.m +2 -10
  34. package/ios/RNGestureHandler.xcodeproj/project.xcworkspace/xcuserdata/jakubpiasecki.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  35. package/ios/RNGestureHandlerActionType.h +8 -0
  36. package/ios/RNGestureHandlerButtonComponentView.h +17 -0
  37. package/ios/RNGestureHandlerButtonComponentView.mm +48 -0
  38. package/ios/RNGestureHandlerButtonManager.h +5 -0
  39. package/ios/RNGestureHandlerButtonManager.m +30 -0
  40. package/ios/RNGestureHandlerManager.h +2 -4
  41. package/ios/{RNGestureHandlerManager.m → RNGestureHandlerManager.mm} +92 -20
  42. package/ios/{RNGestureHandlerModule.m → RNGestureHandlerModule.mm} +91 -36
  43. package/ios/RNGestureHandlerRegistry.h +1 -2
  44. package/ios/RNGestureHandlerRegistry.m +2 -11
  45. package/ios/RNGestureHandlerRootViewComponentView.mm +21 -0
  46. package/jest-utils/package.json +6 -0
  47. package/lib/commonjs/ActionType.js +15 -0
  48. package/lib/commonjs/ActionType.js.map +1 -0
  49. package/lib/commonjs/GestureHandlerRootView.android.js +6 -6
  50. package/lib/commonjs/GestureHandlerRootView.android.js.map +1 -1
  51. package/lib/commonjs/GestureHandlerRootView.js +2 -3
  52. package/lib/commonjs/GestureHandlerRootView.js.map +1 -1
  53. package/lib/commonjs/RNGestureHandlerModule.js +4 -2
  54. package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
  55. package/lib/commonjs/RNGestureHandlerModule.web.js +1 -1
  56. package/lib/commonjs/RNGestureHandlerModule.web.js.map +1 -1
  57. package/lib/commonjs/components/DrawerLayout.js +2 -2
  58. package/lib/commonjs/components/DrawerLayout.js.map +1 -1
  59. package/lib/commonjs/components/GestureHandlerButton.js +5 -2
  60. package/lib/commonjs/components/GestureHandlerButton.js.map +1 -1
  61. package/lib/commonjs/components/Swipeable.js +22 -20
  62. package/lib/commonjs/components/Swipeable.js.map +1 -1
  63. package/lib/commonjs/components/touchables/TouchableOpacity.js +3 -1
  64. package/lib/commonjs/components/touchables/TouchableOpacity.js.map +1 -1
  65. package/lib/commonjs/fabric/RNGestureHandlerButtonNativeComponent.js +21 -0
  66. package/lib/commonjs/fabric/RNGestureHandlerButtonNativeComponent.js.map +1 -0
  67. package/lib/commonjs/fabric/RNGestureHandlerRootViewNativeComponent.js +21 -0
  68. package/lib/commonjs/fabric/RNGestureHandlerRootViewNativeComponent.js.map +1 -0
  69. package/lib/commonjs/getShadowNodeFromRef.js +24 -0
  70. package/lib/commonjs/getShadowNodeFromRef.js.map +1 -0
  71. package/lib/commonjs/getShadowNodeFromRef.web.js +15 -0
  72. package/lib/commonjs/getShadowNodeFromRef.web.js.map +1 -0
  73. package/lib/commonjs/handlers/FlingGestureHandler.js +4 -2
  74. package/lib/commonjs/handlers/FlingGestureHandler.js.map +1 -1
  75. package/lib/commonjs/handlers/ForceTouchGestureHandler.js +8 -4
  76. package/lib/commonjs/handlers/ForceTouchGestureHandler.js.map +1 -1
  77. package/lib/commonjs/handlers/LongPressGestureHandler.js +4 -2
  78. package/lib/commonjs/handlers/LongPressGestureHandler.js.map +1 -1
  79. package/lib/commonjs/handlers/NativeViewGestureHandler.js +4 -2
  80. package/lib/commonjs/handlers/NativeViewGestureHandler.js.map +1 -1
  81. package/lib/commonjs/handlers/PanGestureHandler.js +4 -2
  82. package/lib/commonjs/handlers/PanGestureHandler.js.map +1 -1
  83. package/lib/commonjs/handlers/PinchGestureHandler.js +4 -2
  84. package/lib/commonjs/handlers/PinchGestureHandler.js.map +1 -1
  85. package/lib/commonjs/handlers/RotationGestureHandler.js +4 -2
  86. package/lib/commonjs/handlers/RotationGestureHandler.js.map +1 -1
  87. package/lib/commonjs/handlers/TapGestureHandler.js +4 -2
  88. package/lib/commonjs/handlers/TapGestureHandler.js.map +1 -1
  89. package/lib/commonjs/handlers/createHandler.js +63 -9
  90. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  91. package/lib/commonjs/handlers/createNativeWrapper.js +6 -2
  92. package/lib/commonjs/handlers/createNativeWrapper.js.map +1 -1
  93. package/lib/commonjs/handlers/gestureHandlerCommon.js.map +1 -1
  94. package/lib/commonjs/handlers/gestures/GestureDetector.js +84 -32
  95. package/lib/commonjs/handlers/gestures/GestureDetector.js.map +1 -1
  96. package/lib/commonjs/handlers/gestures/eventReceiver.js +25 -8
  97. package/lib/commonjs/handlers/gestures/eventReceiver.js.map +1 -1
  98. package/lib/commonjs/handlers/gestures/forceTouchGesture.js.map +1 -1
  99. package/lib/commonjs/handlers/gestures/gesture.js +16 -1
  100. package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
  101. package/lib/commonjs/handlers/gestures/gestureStateManager.js +7 -4
  102. package/lib/commonjs/handlers/gestures/gestureStateManager.js.map +1 -1
  103. package/lib/commonjs/handlers/gestures/panGesture.js.map +1 -1
  104. package/lib/commonjs/handlers/gestures/pinchGesture.js.map +1 -1
  105. package/lib/commonjs/handlers/gestures/reanimatedWrapper.js +4 -1
  106. package/lib/commonjs/handlers/gestures/reanimatedWrapper.js.map +1 -1
  107. package/lib/commonjs/handlers/handlersRegistry.js +42 -6
  108. package/lib/commonjs/handlers/handlersRegistry.js.map +1 -1
  109. package/lib/commonjs/index.js.map +1 -1
  110. package/lib/commonjs/init.js +10 -0
  111. package/lib/commonjs/init.js.map +1 -1
  112. package/lib/commonjs/jestUtils/index.js +20 -0
  113. package/lib/commonjs/jestUtils/index.js.map +1 -0
  114. package/lib/commonjs/jestUtils/jestUtils.js +375 -0
  115. package/lib/commonjs/jestUtils/jestUtils.js.map +1 -0
  116. package/lib/commonjs/utils.js +38 -0
  117. package/lib/commonjs/utils.js.map +1 -1
  118. package/lib/module/ActionType.js +7 -0
  119. package/lib/module/ActionType.js.map +1 -0
  120. package/lib/module/GestureHandlerRootView.android.js +5 -6
  121. package/lib/module/GestureHandlerRootView.android.js.map +1 -1
  122. package/lib/module/GestureHandlerRootView.js +2 -3
  123. package/lib/module/GestureHandlerRootView.js.map +1 -1
  124. package/lib/module/RNGestureHandlerModule.js +3 -2
  125. package/lib/module/RNGestureHandlerModule.js.map +1 -1
  126. package/lib/module/RNGestureHandlerModule.web.js +1 -1
  127. package/lib/module/RNGestureHandlerModule.web.js.map +1 -1
  128. package/lib/module/components/DrawerLayout.js +2 -2
  129. package/lib/module/components/DrawerLayout.js.map +1 -1
  130. package/lib/module/components/GestureHandlerButton.js +4 -2
  131. package/lib/module/components/GestureHandlerButton.js.map +1 -1
  132. package/lib/module/components/Swipeable.js +22 -20
  133. package/lib/module/components/Swipeable.js.map +1 -1
  134. package/lib/module/components/touchables/TouchableOpacity.js +4 -2
  135. package/lib/module/components/touchables/TouchableOpacity.js.map +1 -1
  136. package/lib/module/fabric/RNGestureHandlerButtonNativeComponent.js +9 -0
  137. package/lib/module/fabric/RNGestureHandlerButtonNativeComponent.js.map +1 -0
  138. package/lib/module/fabric/RNGestureHandlerRootViewNativeComponent.js +9 -0
  139. package/lib/module/fabric/RNGestureHandlerRootViewNativeComponent.js.map +1 -0
  140. package/lib/module/getShadowNodeFromRef.js +17 -0
  141. package/lib/module/getShadowNodeFromRef.js.map +1 -0
  142. package/lib/module/getShadowNodeFromRef.web.js +8 -0
  143. package/lib/module/getShadowNodeFromRef.web.js.map +1 -0
  144. package/lib/module/handlers/FlingGestureHandler.js +2 -1
  145. package/lib/module/handlers/FlingGestureHandler.js.map +1 -1
  146. package/lib/module/handlers/ForceTouchGestureHandler.js +5 -3
  147. package/lib/module/handlers/ForceTouchGestureHandler.js.map +1 -1
  148. package/lib/module/handlers/LongPressGestureHandler.js +2 -1
  149. package/lib/module/handlers/LongPressGestureHandler.js.map +1 -1
  150. package/lib/module/handlers/NativeViewGestureHandler.js +2 -1
  151. package/lib/module/handlers/NativeViewGestureHandler.js.map +1 -1
  152. package/lib/module/handlers/PanGestureHandler.js +2 -1
  153. package/lib/module/handlers/PanGestureHandler.js.map +1 -1
  154. package/lib/module/handlers/PinchGestureHandler.js +2 -1
  155. package/lib/module/handlers/PinchGestureHandler.js.map +1 -1
  156. package/lib/module/handlers/RotationGestureHandler.js +2 -1
  157. package/lib/module/handlers/RotationGestureHandler.js.map +1 -1
  158. package/lib/module/handlers/TapGestureHandler.js +2 -1
  159. package/lib/module/handlers/TapGestureHandler.js.map +1 -1
  160. package/lib/module/handlers/createHandler.js +62 -10
  161. package/lib/module/handlers/createHandler.js.map +1 -1
  162. package/lib/module/handlers/createNativeWrapper.js +6 -2
  163. package/lib/module/handlers/createNativeWrapper.js.map +1 -1
  164. package/lib/module/handlers/gestureHandlerCommon.js.map +1 -1
  165. package/lib/module/handlers/gestures/GestureDetector.js +79 -32
  166. package/lib/module/handlers/gestures/GestureDetector.js.map +1 -1
  167. package/lib/module/handlers/gestures/eventReceiver.js +25 -7
  168. package/lib/module/handlers/gestures/eventReceiver.js.map +1 -1
  169. package/lib/module/handlers/gestures/forceTouchGesture.js.map +1 -1
  170. package/lib/module/handlers/gestures/gesture.js +16 -1
  171. package/lib/module/handlers/gestures/gesture.js.map +1 -1
  172. package/lib/module/handlers/gestures/gestureStateManager.js +6 -4
  173. package/lib/module/handlers/gestures/gestureStateManager.js.map +1 -1
  174. package/lib/module/handlers/gestures/panGesture.js.map +1 -1
  175. package/lib/module/handlers/gestures/pinchGesture.js.map +1 -1
  176. package/lib/module/handlers/gestures/reanimatedWrapper.js +2 -1
  177. package/lib/module/handlers/gestures/reanimatedWrapper.js.map +1 -1
  178. package/lib/module/handlers/handlersRegistry.js +34 -6
  179. package/lib/module/handlers/handlersRegistry.js.map +1 -1
  180. package/lib/module/index.js.map +1 -1
  181. package/lib/module/init.js +6 -0
  182. package/lib/module/init.js.map +1 -1
  183. package/lib/module/jestUtils/index.js +2 -0
  184. package/lib/module/jestUtils/index.js.map +1 -0
  185. package/lib/module/jestUtils/jestUtils.js +350 -0
  186. package/lib/module/jestUtils/jestUtils.js.map +1 -0
  187. package/lib/module/utils.js +28 -0
  188. package/lib/module/utils.js.map +1 -1
  189. package/lib/typescript/ActionType.d.ts +7 -0
  190. package/lib/typescript/GestureHandlerRootView.android.d.ts +5 -2
  191. package/lib/typescript/GestureHandlerRootView.d.ts +1 -1
  192. package/lib/typescript/RNGestureHandlerModule.d.ts +3 -1
  193. package/lib/typescript/RNGestureHandlerModule.web.d.ts +2 -1
  194. package/lib/typescript/components/GestureHandlerButton.d.ts +2 -2
  195. package/lib/typescript/components/Swipeable.d.ts +12 -4
  196. package/lib/typescript/components/touchables/TouchableOpacity.d.ts +5 -1
  197. package/lib/typescript/getShadowNodeFromRef.d.ts +1 -0
  198. package/lib/typescript/getShadowNodeFromRef.web.d.ts +1 -0
  199. package/lib/typescript/handlers/FlingGestureHandler.d.ts +1 -0
  200. package/lib/typescript/handlers/ForceTouchGestureHandler.d.ts +2 -1
  201. package/lib/typescript/handlers/LongPressGestureHandler.d.ts +1 -0
  202. package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +1 -0
  203. package/lib/typescript/handlers/PanGestureHandler.d.ts +1 -0
  204. package/lib/typescript/handlers/PinchGestureHandler.d.ts +1 -0
  205. package/lib/typescript/handlers/RotationGestureHandler.d.ts +1 -0
  206. package/lib/typescript/handlers/TapGestureHandler.d.ts +1 -0
  207. package/lib/typescript/handlers/gestureHandlerCommon.d.ts +2 -4
  208. package/lib/typescript/handlers/gestures/GestureDetector.d.ts +4 -1
  209. package/lib/typescript/handlers/gestures/forceTouchGesture.d.ts +1 -2
  210. package/lib/typescript/handlers/gestures/gesture.d.ts +5 -0
  211. package/lib/typescript/handlers/gestures/panGesture.d.ts +1 -2
  212. package/lib/typescript/handlers/gestures/pinchGesture.d.ts +1 -2
  213. package/lib/typescript/handlers/handlersRegistry.d.ts +11 -3
  214. package/lib/typescript/index.d.ts +3 -0
  215. package/lib/typescript/jestUtils/index.d.ts +1 -0
  216. package/lib/typescript/jestUtils/jestUtils.d.ts +28 -0
  217. package/lib/typescript/utils.d.ts +6 -0
  218. package/lib/typescript/web/constants.d.ts +0 -1
  219. package/package.json +40 -16
  220. package/src/ActionType.ts +9 -0
  221. package/src/GestureHandlerRootView.android.tsx +14 -14
  222. package/src/GestureHandlerRootView.tsx +4 -4
  223. package/src/RNGestureHandlerModule.ts +11 -6
  224. package/src/RNGestureHandlerModule.web.ts +2 -1
  225. package/src/components/DrawerLayout.tsx +8 -2
  226. package/src/components/GestureHandlerButton.tsx +7 -4
  227. package/src/components/Swipeable.tsx +28 -22
  228. package/src/components/touchables/TouchableOpacity.tsx +6 -2
  229. package/src/fabric/RNGestureHandlerButtonNativeComponent.js +27 -0
  230. package/src/fabric/RNGestureHandlerRootViewNativeComponent.js +19 -0
  231. package/src/getShadowNodeFromRef.ts +19 -0
  232. package/src/getShadowNodeFromRef.web.ts +7 -0
  233. package/src/handlers/FlingGestureHandler.ts +3 -1
  234. package/src/handlers/ForceTouchGestureHandler.ts +8 -2
  235. package/src/handlers/LongPressGestureHandler.ts +3 -1
  236. package/src/handlers/NativeViewGestureHandler.ts +3 -1
  237. package/src/handlers/PanGestureHandler.ts +3 -1
  238. package/src/handlers/PinchGestureHandler.ts +3 -1
  239. package/src/handlers/RotationGestureHandler.ts +3 -1
  240. package/src/handlers/TapGestureHandler.ts +3 -1
  241. package/src/handlers/createHandler.ts +69 -7
  242. package/src/handlers/createNativeWrapper.tsx +7 -1
  243. package/src/handlers/gestureHandlerCommon.ts +2 -5
  244. package/src/handlers/gestures/GestureDetector.tsx +110 -37
  245. package/src/handlers/gestures/eventReceiver.ts +23 -19
  246. package/src/handlers/gestures/forceTouchGesture.ts +1 -1
  247. package/src/handlers/gestures/gesture.ts +21 -1
  248. package/src/handlers/gestures/gestureStateManager.ts +9 -12
  249. package/src/handlers/gestures/panGesture.ts +1 -1
  250. package/src/handlers/gestures/pinchGesture.ts +1 -1
  251. package/src/handlers/gestures/reanimatedWrapper.ts +4 -1
  252. package/src/handlers/handlersRegistry.ts +44 -6
  253. package/src/index.ts +3 -0
  254. package/src/init.ts +6 -0
  255. package/src/jestUtils/index.ts +1 -0
  256. package/src/jestUtils/jestUtils.ts +506 -0
  257. package/src/utils.ts +38 -0
  258. package/android/lib/src/main/java/com/swmansion/gesturehandler/BaseGestureHandlerInteractionController.kt +0 -18
  259. package/android/lib/src/main/java/com/swmansion/gesturehandler/GestureHandlerRegistryImpl.kt +0 -21
  260. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerPackage.kt +0 -17
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @flow strict-local
3
+ * @format
4
+ */
5
+ /* eslint-disable */
6
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
7
+ import type { HostComponent } from 'react-native';
8
+ import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';
9
+
10
+ type NativeProps = $ReadOnly<{|
11
+ ...ViewProps, // This is required.
12
+ |}>;
13
+
14
+ type ComponentType = HostComponent<NativeProps>;
15
+
16
+ export default (codegenNativeComponent<NativeProps>(
17
+ 'RNGestureHandlerRootView',
18
+ {}
19
+ ): ComponentType);
@@ -0,0 +1,19 @@
1
+ // Used by GestureDetector (unsupported on web at the moment) to check whether the
2
+ // attached view may get flattened on Fabric. This implementation causes errors
3
+ // on web due to the static resolution of `require` statements by webpack breaking
4
+ // the conditional importing. Solved by making .web file.
5
+ let findHostInstance_DEPRECATED = (_ref: any) => null;
6
+
7
+ try {
8
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
9
+ findHostInstance_DEPRECATED = require('react-native/Libraries/Renderer/shims/ReactFabric')
10
+ .findHostInstance_DEPRECATED;
11
+ } catch (e) {
12
+ // do nothing
13
+ }
14
+
15
+ export function getShadowNodeFromRef(ref: any) {
16
+ // @ts-ignore Fabric
17
+ return findHostInstance_DEPRECATED(ref)._internalInstanceHandle.stateNode
18
+ .node;
19
+ }
@@ -0,0 +1,7 @@
1
+ // Used by GestureDetector (unsupported on web at the moment) to check whether the
2
+ // attached view may get flattened on Fabric. Original implementation causes errors
3
+ // on web due to the static resolution of `require` statements by webpack breaking
4
+ // the conditional importing.
5
+ export function getShadowNodeFromRef(_ref: any) {
6
+ return null;
7
+ }
@@ -42,13 +42,15 @@ export interface FlingGestureHandlerProps
42
42
  extends BaseGestureHandlerProps<FlingGestureHandlerEventPayload>,
43
43
  FlingGestureConfig {}
44
44
 
45
+ export const flingHandlerName = 'FlingGestureHandler';
46
+
45
47
  export type FlingGestureHandler = typeof FlingGestureHandler;
46
48
  // eslint-disable-next-line @typescript-eslint/no-redeclare -- backward compatibility; see description on the top of gestureHandlerCommon.ts file
47
49
  export const FlingGestureHandler = createHandler<
48
50
  FlingGestureHandlerProps,
49
51
  FlingGestureHandlerEventPayload
50
52
  >({
51
- name: 'FlingGestureHandler',
53
+ name: flingHandlerName,
52
54
  allowedProps: [
53
55
  ...baseGestureHandlerProps,
54
56
  ...flingGestureHandlerProps,
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { tagMessage } from '../utils';
2
3
  import PlatformConstants from '../PlatformConstants';
3
4
  import createHandler from './createHandler';
4
5
  import {
@@ -16,7 +17,9 @@ class ForceTouchFallback extends React.Component {
16
17
  static forceTouchAvailable = false;
17
18
  componentDidMount() {
18
19
  console.warn(
19
- 'ForceTouchGestureHandler is not available on this platform. Please use ForceTouchGestureHandler.forceTouchAvailable to conditionally render other components that would provide a fallback behavior specific to your usecase'
20
+ tagMessage(
21
+ 'ForceTouchGestureHandler is not available on this platform. Please use ForceTouchGestureHandler.forceTouchAvailable to conditionally render other components that would provide a fallback behavior specific to your usecase'
22
+ )
20
23
  );
21
24
  }
22
25
  render() {
@@ -64,13 +67,16 @@ export interface ForceTouchGestureHandlerProps
64
67
  export type ForceTouchGestureHandler = typeof ForceTouchGestureHandler & {
65
68
  forceTouchAvailable: boolean;
66
69
  };
70
+
71
+ export const forceTouchHandlerName = 'ForceTouchGestureHandler';
72
+
67
73
  // eslint-disable-next-line @typescript-eslint/no-redeclare -- backward compatibility; see description on the top of gestureHandlerCommon.ts file
68
74
  export const ForceTouchGestureHandler = PlatformConstants?.forceTouchAvailable
69
75
  ? createHandler<
70
76
  ForceTouchGestureHandlerProps,
71
77
  ForceTouchGestureHandlerEventPayload
72
78
  >({
73
- name: 'ForceTouchGestureHandler',
79
+ name: forceTouchHandlerName,
74
80
  allowedProps: [
75
81
  ...baseGestureHandlerProps,
76
82
  ...forceTouchGestureHandlerProps,
@@ -69,13 +69,15 @@ export interface LongPressGestureHandlerProps
69
69
  extends BaseGestureHandlerProps<LongPressGestureHandlerEventPayload>,
70
70
  LongPressGestureConfig {}
71
71
 
72
+ export const longPressHandlerName = 'LongPressGestureHandler';
73
+
72
74
  export type LongPressGestureHandler = typeof LongPressGestureHandler;
73
75
  // eslint-disable-next-line @typescript-eslint/no-redeclare -- backward compatibility; see description on the top of gestureHandlerCommon.ts file
74
76
  export const LongPressGestureHandler = createHandler<
75
77
  LongPressGestureHandlerProps,
76
78
  LongPressGestureHandlerEventPayload
77
79
  >({
78
- name: 'LongPressGestureHandler',
80
+ name: longPressHandlerName,
79
81
  allowedProps: [
80
82
  ...baseGestureHandlerProps,
81
83
  ...longPressGestureHandlerProps,
@@ -41,13 +41,15 @@ export const nativeViewProps = [
41
41
  ...nativeViewGestureHandlerProps,
42
42
  ] as const;
43
43
 
44
+ export const nativeViewHandlerName = 'NativeViewGestureHandler';
45
+
44
46
  export type NativeViewGestureHandler = typeof NativeViewGestureHandler;
45
47
  // eslint-disable-next-line @typescript-eslint/no-redeclare -- backward compatibility; see description on the top of gestureHandlerCommon.ts file
46
48
  export const NativeViewGestureHandler = createHandler<
47
49
  NativeViewGestureHandlerProps,
48
50
  NativeViewGestureHandlerPayload
49
51
  >({
50
- name: 'NativeViewGestureHandler',
52
+ name: nativeViewHandlerName,
51
53
  allowedProps: nativeViewProps,
52
54
  config: {},
53
55
  });
@@ -181,13 +181,15 @@ export interface PanGestureHandlerProps
181
181
  failOffsetX?: number | number[];
182
182
  }
183
183
 
184
+ export const panHandlerName = 'PanGestureHandler';
185
+
184
186
  export type PanGestureHandler = typeof PanGestureHandler;
185
187
  // eslint-disable-next-line @typescript-eslint/no-redeclare -- backward compatibility; see description on the top of gestureHandlerCommon.ts file
186
188
  export const PanGestureHandler = createHandler<
187
189
  PanGestureHandlerProps,
188
190
  PanGestureHandlerEventPayload
189
191
  >({
190
- name: 'PanGestureHandler',
192
+ name: panHandlerName,
191
193
  allowedProps: [
192
194
  ...baseGestureHandlerProps,
193
195
  ...panGestureHandlerProps,
@@ -34,13 +34,15 @@ export type PinchGestureHandlerEventPayload = {
34
34
  export interface PinchGestureHandlerProps
35
35
  extends BaseGestureHandlerProps<PinchGestureHandlerEventPayload> {}
36
36
 
37
+ export const pinchHandlerName = 'PinchGestureHandler';
38
+
37
39
  export type PinchGestureHandler = typeof PinchGestureHandler;
38
40
  // eslint-disable-next-line @typescript-eslint/no-redeclare -- backward compatibility; see description on the top of gestureHandlerCommon.ts file
39
41
  export const PinchGestureHandler = createHandler<
40
42
  PinchGestureHandlerProps,
41
43
  PinchGestureHandlerEventPayload
42
44
  >({
43
- name: 'PinchGestureHandler',
45
+ name: pinchHandlerName,
44
46
  allowedProps: baseGestureHandlerProps,
45
47
  config: {},
46
48
  });
@@ -34,13 +34,15 @@ export type RotationGestureHandlerEventPayload = {
34
34
  export interface RotationGestureHandlerProps
35
35
  extends BaseGestureHandlerProps<RotationGestureHandlerEventPayload> {}
36
36
 
37
+ export const rotationHandlerName = 'RotationGestureHandler';
38
+
37
39
  export type RotationGestureHandler = typeof RotationGestureHandler;
38
40
  // eslint-disable-next-line @typescript-eslint/no-redeclare -- backward compatibility; see description on the top of gestureHandlerCommon.ts file
39
41
  export const RotationGestureHandler = createHandler<
40
42
  RotationGestureHandlerProps,
41
43
  RotationGestureHandlerEventPayload
42
44
  >({
43
- name: 'RotationGestureHandler',
45
+ name: rotationHandlerName,
44
46
  allowedProps: baseGestureHandlerProps,
45
47
  config: {},
46
48
  });
@@ -75,13 +75,15 @@ export interface TapGestureHandlerProps
75
75
  extends BaseGestureHandlerProps<TapGestureHandlerEventPayload>,
76
76
  TapGestureConfig {}
77
77
 
78
+ export const tapHandlerName = 'TapGestureHandler';
79
+
78
80
  export type TapGestureHandler = typeof TapGestureHandler;
79
81
  // eslint-disable-next-line @typescript-eslint/no-redeclare -- backward compatibility; see description on the top of gestureHandlerCommon.ts file
80
82
  export const TapGestureHandler = createHandler<
81
83
  TapGestureHandlerProps,
82
84
  TapGestureHandlerEventPayload
83
85
  >({
84
- name: 'TapGestureHandler',
86
+ name: tapHandlerName,
85
87
  allowedProps: [
86
88
  ...baseGestureHandlerProps,
87
89
  ...tapGestureHandlerProps,
@@ -11,7 +11,11 @@ import deepEqual from 'lodash/isEqual';
11
11
  import RNGestureHandlerModule from '../RNGestureHandlerModule';
12
12
  import type RNGestureHandlerModuleWeb from '../RNGestureHandlerModule.web';
13
13
  import { State } from '../State';
14
- import { handlerIDToTag, getNextHandlerTag } from './handlersRegistry';
14
+ import {
15
+ handlerIDToTag,
16
+ getNextHandlerTag,
17
+ registerOldGestureHandler,
18
+ } from './handlersRegistry';
15
19
 
16
20
  import {
17
21
  BaseGestureHandlerProps,
@@ -21,14 +25,35 @@ import {
21
25
  findNodeHandle,
22
26
  } from './gestureHandlerCommon';
23
27
  import { ValueOf } from '../typeUtils';
28
+ import { isFabric, isJestEnv, tagMessage } from '../utils';
29
+ import { ActionType } from '../ActionType';
24
30
 
25
31
  const UIManagerAny = UIManager as any;
26
32
 
33
+ const customGHEventsConfigFabricAndroid = {
34
+ topOnGestureHandlerEvent: { registrationName: 'onGestureHandlerEvent' },
35
+ topOnGestureHandlerStateChange: {
36
+ registrationName: 'onGestureHandlerStateChange',
37
+ },
38
+ };
39
+
27
40
  const customGHEventsConfig = {
28
41
  onGestureHandlerEvent: { registrationName: 'onGestureHandlerEvent' },
29
42
  onGestureHandlerStateChange: {
30
43
  registrationName: 'onGestureHandlerStateChange',
31
44
  },
45
+
46
+ // When using React Native Gesture Handler for Animated.event with useNativeDriver: true
47
+ // on Android with Fabric enabled, the native part still sends the native events to JS
48
+ // but prefixed with "top". We cannot simply rename the events above so they are prefixed
49
+ // with "top" instead of "on" because in such case Animated.events would not be registered.
50
+ // That's why we need to register another pair of event names.
51
+ // The incoming events will be queued but never handled.
52
+ // Without this piece of code below, you'll get the following JS error:
53
+ // Unsupported top level event type "topOnGestureHandlerEvent" dispatched
54
+ ...(isFabric() &&
55
+ Platform.OS === 'android' &&
56
+ customGHEventsConfigFabricAndroid),
32
57
  };
33
58
 
34
59
  // Add gesture specific events to genericDirectEventTypes object exported from UIManager
@@ -126,7 +151,9 @@ let showedRngh2Notice = false;
126
151
  function showRngh2NoticeIfNeeded() {
127
152
  if (!showedRngh2Notice) {
128
153
  console.warn(
129
- "[react-native-gesture-handler] Seems like you're using an old API with gesture components, check out new Gestures system!"
154
+ tagMessage(
155
+ "Seems like you're using an old API with gesture components, check out new Gestures system!"
156
+ )
130
157
  );
131
158
  showedRngh2Notice = true;
132
159
  }
@@ -172,7 +199,7 @@ export default function createHandler<
172
199
  }
173
200
  handlerIDToTag[props.id] = this.handlerTag;
174
201
  }
175
- if (__DEV__) {
202
+ if (__DEV__ && !isJestEnv()) {
176
203
  showRngh2NoticeIfNeeded();
177
204
  }
178
205
  }
@@ -237,7 +264,9 @@ export default function createHandler<
237
264
 
238
265
  private onGestureHandlerEvent = (event: GestureEvent<U>) => {
239
266
  if (event.nativeEvent.handlerTag === this.handlerTag) {
240
- this.props.onGestureEvent?.(event);
267
+ if (typeof this.props.onGestureEvent === 'function') {
268
+ this.props.onGestureEvent?.(event);
269
+ }
241
270
  } else {
242
271
  this.props.onGestureHandlerEvent?.(event);
243
272
  }
@@ -248,7 +277,9 @@ export default function createHandler<
248
277
  event: HandlerStateChangeEvent<U>
249
278
  ) => {
250
279
  if (event.nativeEvent.handlerTag === this.handlerTag) {
251
- this.props.onHandlerStateChange?.(event);
280
+ if (typeof this.props.onHandlerStateChange === 'function') {
281
+ this.props.onHandlerStateChange?.(event);
282
+ }
252
283
 
253
284
  const state: ValueOf<typeof State> = event.nativeEvent.state;
254
285
  const stateEventName = stateToPropMappings[state];
@@ -296,14 +327,38 @@ export default function createHandler<
296
327
  (RNGestureHandlerModule.attachGestureHandler as typeof RNGestureHandlerModuleWeb.attachGestureHandler)(
297
328
  this.handlerTag,
298
329
  newViewTag,
299
- false,
330
+ ActionType.JS_FUNCTION_OLD_API, // ignored on web
300
331
  this.propsRef
301
332
  );
302
333
  } else {
334
+ registerOldGestureHandler(this.handlerTag, {
335
+ onGestureEvent: this.onGestureHandlerEvent,
336
+ onGestureStateChange: this.onGestureHandlerStateChange,
337
+ });
338
+
339
+ const actionType = (() => {
340
+ if (
341
+ this.props?.onGestureEvent &&
342
+ 'current' in this.props.onGestureEvent
343
+ ) {
344
+ // Reanimated worklet
345
+ return ActionType.REANIMATED_WORKLET;
346
+ } else if (
347
+ this.props?.onGestureEvent &&
348
+ '__isNative' in this.props.onGestureEvent
349
+ ) {
350
+ // Animated.event with useNativeDriver: true
351
+ return ActionType.NATIVE_ANIMATED_EVENT;
352
+ } else {
353
+ // JS callback or Animated.event with useNativeDriver: false
354
+ return ActionType.JS_FUNCTION_OLD_API;
355
+ }
356
+ })();
357
+
303
358
  RNGestureHandlerModule.attachGestureHandler(
304
359
  this.handlerTag,
305
360
  newViewTag,
306
- false
361
+ actionType
307
362
  );
308
363
  }
309
364
  };
@@ -433,6 +488,13 @@ export default function createHandler<
433
488
  {
434
489
  ref: this.refHandler,
435
490
  collapsable: false,
491
+ ...(isJestEnv()
492
+ ? {
493
+ handlerType: name,
494
+ handlerTag: this.handlerTag,
495
+ }
496
+ : {}),
497
+ testID: this.props.testID ?? child.props.testID,
436
498
  ...events,
437
499
  },
438
500
  grandChildren
@@ -68,7 +68,13 @@ export default function createNativeWrapper<P>(
68
68
  );
69
69
  });
70
70
 
71
- ComponentWrapper.displayName = Component.displayName || 'ComponentWrapper';
71
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
72
+ ComponentWrapper.displayName =
73
+ Component?.displayName ||
74
+ // @ts-ignore if render doesn't exist it will return undefined and go further
75
+ Component?.render?.name ||
76
+ (typeof Component === 'string' && Component) ||
77
+ 'ComponentWrapper';
72
78
 
73
79
  return ComponentWrapper;
74
80
  }
@@ -43,11 +43,7 @@ export interface GestureEventPayload {
43
43
  numberOfPointers: number;
44
44
  state: ValueOf<typeof State>;
45
45
  }
46
-
47
- export interface HandlerStateChangeEventPayload {
48
- handlerTag: number;
49
- numberOfPointers: number;
50
- state: ValueOf<typeof State>;
46
+ export interface HandlerStateChangeEventPayload extends GestureEventPayload {
51
47
  oldState: ValueOf<typeof State>;
52
48
  }
53
49
 
@@ -114,6 +110,7 @@ export type BaseGestureHandlerProps<
114
110
  id?: string;
115
111
  waitFor?: React.Ref<unknown> | React.Ref<unknown>[];
116
112
  simultaneousHandlers?: React.Ref<unknown> | React.Ref<unknown>[];
113
+ testID?: string;
117
114
  // TODO(TS) - fix event types
118
115
  onBegan?: (event: HandlerStateChangeEvent) => void;
119
116
  onFailed?: (event: HandlerStateChangeEvent) => void;