react-native-gesture-handler 2.16.1 → 2.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (369) hide show
  1. package/README.md +9 -3
  2. package/android/build.gradle +105 -0
  3. package/android/gradle.properties +7 -0
  4. package/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.java +7 -7
  5. package/android/src/main/java/com/swmansion/gesturehandler/core/NativeViewGestureHandler.kt +16 -8
  6. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +9 -5
  7. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerInteractionManager.kt +4 -0
  8. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt +1 -1
  9. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerTouchEvent.kt +1 -0
  10. package/apple/RNGestureHandlerButtonComponentView.mm +10 -0
  11. package/apple/RNGestureHandlerModule.mm +2 -3
  12. package/lib/commonjs/RNGestureHandlerModule.js +4 -97
  13. package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
  14. package/lib/commonjs/RNGestureHandlerModule.web.js +109 -0
  15. package/lib/commonjs/RNGestureHandlerModule.web.js.map +1 -0
  16. package/lib/commonjs/RNRenderer.js +10 -5
  17. package/lib/commonjs/RNRenderer.js.map +1 -1
  18. package/lib/commonjs/RNRenderer.web.js +11 -0
  19. package/lib/commonjs/RNRenderer.web.js.map +1 -0
  20. package/lib/commonjs/components/GestureButtons.js +27 -12
  21. package/lib/commonjs/components/GestureButtons.js.map +1 -1
  22. package/lib/commonjs/components/GestureComponents.js +82 -19
  23. package/lib/commonjs/components/GestureComponents.js.map +1 -1
  24. package/lib/commonjs/components/GestureComponents.web.js +52 -0
  25. package/lib/commonjs/components/GestureComponents.web.js.map +1 -0
  26. package/lib/commonjs/components/GestureHandlerButton.js +3 -13
  27. package/lib/commonjs/components/GestureHandlerButton.js.map +1 -1
  28. package/lib/commonjs/components/GestureHandlerButton.web.js +24 -0
  29. package/lib/commonjs/components/GestureHandlerButton.web.js.map +1 -0
  30. package/lib/commonjs/components/GestureHandlerRootView.js +6 -0
  31. package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
  32. package/lib/commonjs/components/{GestureHandlerRootView.native.js → GestureHandlerRootView.web.js} +1 -7
  33. package/lib/commonjs/components/GestureHandlerRootView.web.js.map +1 -0
  34. package/lib/commonjs/getReactNativeVersion.js +12 -1
  35. package/lib/commonjs/getReactNativeVersion.js.map +1 -1
  36. package/lib/commonjs/getReactNativeVersion.web.js +11 -0
  37. package/lib/commonjs/getReactNativeVersion.web.js.map +1 -0
  38. package/lib/commonjs/getShadowNodeFromRef.js +34 -5
  39. package/lib/commonjs/getShadowNodeFromRef.js.map +1 -1
  40. package/lib/commonjs/getShadowNodeFromRef.web.js +15 -0
  41. package/lib/commonjs/getShadowNodeFromRef.web.js.map +1 -0
  42. package/lib/commonjs/handlers/PressabilityDebugView.js +7 -5
  43. package/lib/commonjs/handlers/PressabilityDebugView.js.map +1 -1
  44. package/lib/commonjs/handlers/PressabilityDebugView.web.js +12 -0
  45. package/lib/commonjs/handlers/PressabilityDebugView.web.js.map +1 -0
  46. package/lib/commonjs/handlers/createHandler.js +1 -3
  47. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  48. package/lib/commonjs/handlers/customDirectEventTypes.js +8 -5
  49. package/lib/commonjs/handlers/customDirectEventTypes.js.map +1 -1
  50. package/lib/commonjs/handlers/customDirectEventTypes.web.js +11 -0
  51. package/lib/commonjs/handlers/customDirectEventTypes.web.js.map +1 -0
  52. package/lib/commonjs/handlers/gestureHandlerCommon.js +3 -3
  53. package/lib/commonjs/handlers/gestureHandlerCommon.js.map +1 -1
  54. package/lib/commonjs/handlers/gestures/GestureDetector/Wrap.js +42 -0
  55. package/lib/commonjs/handlers/gestures/GestureDetector/Wrap.js.map +1 -0
  56. package/lib/commonjs/handlers/gestures/GestureDetector/attachHandlers.js +83 -0
  57. package/lib/commonjs/handlers/gestures/GestureDetector/attachHandlers.js.map +1 -0
  58. package/lib/commonjs/handlers/gestures/GestureDetector/dropHandlers.js +25 -0
  59. package/lib/commonjs/handlers/gestures/GestureDetector/dropHandlers.js.map +1 -0
  60. package/lib/commonjs/handlers/gestures/GestureDetector/index.js +143 -0
  61. package/lib/commonjs/handlers/gestures/GestureDetector/index.js.map +1 -0
  62. package/lib/commonjs/handlers/gestures/GestureDetector/needsToReattach.js +25 -0
  63. package/lib/commonjs/handlers/gestures/GestureDetector/needsToReattach.js.map +1 -0
  64. package/lib/commonjs/handlers/gestures/GestureDetector/types.js +6 -0
  65. package/lib/commonjs/handlers/gestures/GestureDetector/types.js.map +1 -0
  66. package/lib/commonjs/handlers/gestures/GestureDetector/updateHandlers.js +80 -0
  67. package/lib/commonjs/handlers/gestures/GestureDetector/updateHandlers.js.map +1 -0
  68. package/lib/commonjs/handlers/gestures/GestureDetector/useAnimatedGesture.js +180 -0
  69. package/lib/commonjs/handlers/gestures/GestureDetector/useAnimatedGesture.js.map +1 -0
  70. package/lib/commonjs/handlers/gestures/GestureDetector/useDetectorUpdater.js +55 -0
  71. package/lib/commonjs/handlers/gestures/GestureDetector/useDetectorUpdater.js.map +1 -0
  72. package/lib/commonjs/handlers/gestures/GestureDetector/useViewRefHandler.js +47 -0
  73. package/lib/commonjs/handlers/gestures/GestureDetector/useViewRefHandler.js.map +1 -0
  74. package/lib/commonjs/handlers/gestures/GestureDetector/utils.js +176 -0
  75. package/lib/commonjs/handlers/gestures/GestureDetector/utils.js.map +1 -0
  76. package/lib/commonjs/handlers/gestures/gestureComposition.js +3 -1
  77. package/lib/commonjs/handlers/gestures/gestureComposition.js.map +1 -1
  78. package/lib/commonjs/handlers/gestures/gestureStateManager.js +8 -0
  79. package/lib/commonjs/handlers/gestures/gestureStateManager.js.map +1 -1
  80. package/lib/commonjs/handlers/gestures/reanimatedWrapper.js.map +1 -1
  81. package/lib/commonjs/utils.js +36 -0
  82. package/lib/commonjs/utils.js.map +1 -1
  83. package/lib/commonjs/web/detectors/RotationGestureDetector.js +6 -8
  84. package/lib/commonjs/web/detectors/RotationGestureDetector.js.map +1 -1
  85. package/lib/commonjs/web/detectors/ScaleGestureDetector.js +5 -6
  86. package/lib/commonjs/web/detectors/ScaleGestureDetector.js.map +1 -1
  87. package/lib/commonjs/web/handlers/FlingGestureHandler.js +1 -0
  88. package/lib/commonjs/web/handlers/FlingGestureHandler.js.map +1 -1
  89. package/lib/commonjs/web/handlers/GestureHandler.js +56 -64
  90. package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
  91. package/lib/commonjs/web/handlers/LongPressGestureHandler.js +1 -0
  92. package/lib/commonjs/web/handlers/LongPressGestureHandler.js.map +1 -1
  93. package/lib/commonjs/web/handlers/ManualGestureHandler.js +1 -0
  94. package/lib/commonjs/web/handlers/ManualGestureHandler.js.map +1 -1
  95. package/lib/commonjs/web/handlers/NativeViewGestureHandler.js +7 -4
  96. package/lib/commonjs/web/handlers/NativeViewGestureHandler.js.map +1 -1
  97. package/lib/commonjs/web/handlers/PanGestureHandler.js +28 -18
  98. package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
  99. package/lib/commonjs/web/handlers/PinchGestureHandler.js +1 -0
  100. package/lib/commonjs/web/handlers/PinchGestureHandler.js.map +1 -1
  101. package/lib/commonjs/web/handlers/RotationGestureHandler.js +1 -0
  102. package/lib/commonjs/web/handlers/RotationGestureHandler.js.map +1 -1
  103. package/lib/commonjs/web/handlers/TapGestureHandler.js +18 -12
  104. package/lib/commonjs/web/handlers/TapGestureHandler.js.map +1 -1
  105. package/lib/commonjs/web/interfaces.js.map +1 -1
  106. package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js +1 -6
  107. package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js.map +1 -1
  108. package/lib/commonjs/web/tools/PointerEventManager.js +7 -2
  109. package/lib/commonjs/web/tools/PointerEventManager.js.map +1 -1
  110. package/lib/commonjs/web/tools/PointerTracker.js +89 -57
  111. package/lib/commonjs/web/tools/PointerTracker.js.map +1 -1
  112. package/lib/commonjs/web/tools/TouchEventManager.js +6 -2
  113. package/lib/commonjs/web/tools/TouchEventManager.js.map +1 -1
  114. package/lib/commonjs/web/tools/Vector.js +2 -1
  115. package/lib/commonjs/web/tools/Vector.js.map +1 -1
  116. package/lib/commonjs/web/utils.js +31 -0
  117. package/lib/commonjs/web/utils.js.map +1 -1
  118. package/lib/module/RNGestureHandlerModule.js +4 -84
  119. package/lib/module/RNGestureHandlerModule.js.map +1 -1
  120. package/lib/module/RNGestureHandlerModule.web.js +85 -0
  121. package/lib/module/RNGestureHandlerModule.web.js.map +1 -0
  122. package/lib/module/RNRenderer.js +3 -3
  123. package/lib/module/RNRenderer.js.map +1 -1
  124. package/lib/module/RNRenderer.web.js +4 -0
  125. package/lib/module/RNRenderer.web.js.map +1 -0
  126. package/lib/module/components/GestureButtons.js +24 -6
  127. package/lib/module/components/GestureButtons.js.map +1 -1
  128. package/lib/module/components/GestureComponents.js +80 -18
  129. package/lib/module/components/GestureComponents.js.map +1 -1
  130. package/lib/module/components/GestureComponents.web.js +28 -0
  131. package/lib/module/components/GestureComponents.web.js.map +1 -0
  132. package/lib/module/components/GestureHandlerButton.js +2 -8
  133. package/lib/module/components/GestureHandlerButton.js.map +1 -1
  134. package/lib/module/components/GestureHandlerButton.web.js +9 -0
  135. package/lib/module/components/GestureHandlerButton.web.js.map +1 -0
  136. package/lib/module/components/GestureHandlerRootView.js +5 -0
  137. package/lib/module/components/GestureHandlerRootView.js.map +1 -1
  138. package/lib/module/components/{GestureHandlerRootView.native.js → GestureHandlerRootView.web.js} +1 -6
  139. package/lib/module/components/GestureHandlerRootView.web.js.map +1 -0
  140. package/lib/module/getReactNativeVersion.js +7 -1
  141. package/lib/module/getReactNativeVersion.js.map +1 -1
  142. package/lib/module/getReactNativeVersion.web.js +4 -0
  143. package/lib/module/getReactNativeVersion.web.js.map +1 -0
  144. package/lib/module/getShadowNodeFromRef.js +33 -4
  145. package/lib/module/getShadowNodeFromRef.js.map +1 -1
  146. package/lib/module/getShadowNodeFromRef.web.js +8 -0
  147. package/lib/module/getShadowNodeFromRef.web.js.map +1 -0
  148. package/lib/module/handlers/PressabilityDebugView.js +2 -4
  149. package/lib/module/handlers/PressabilityDebugView.js.map +1 -1
  150. package/lib/module/handlers/PressabilityDebugView.web.js +5 -0
  151. package/lib/module/handlers/PressabilityDebugView.web.js.map +1 -0
  152. package/lib/module/handlers/createHandler.js +2 -4
  153. package/lib/module/handlers/createHandler.js.map +1 -1
  154. package/lib/module/handlers/customDirectEventTypes.js +2 -4
  155. package/lib/module/handlers/customDirectEventTypes.js.map +1 -1
  156. package/lib/module/handlers/customDirectEventTypes.web.js +5 -0
  157. package/lib/module/handlers/customDirectEventTypes.web.js.map +1 -0
  158. package/lib/module/handlers/gestureHandlerCommon.js +1 -1
  159. package/lib/module/handlers/gestureHandlerCommon.js.map +1 -1
  160. package/lib/module/handlers/gestures/GestureDetector/Wrap.js +26 -0
  161. package/lib/module/handlers/gestures/GestureDetector/Wrap.js.map +1 -0
  162. package/lib/module/handlers/gestures/GestureDetector/attachHandlers.js +65 -0
  163. package/lib/module/handlers/gestures/GestureDetector/attachHandlers.js.map +1 -0
  164. package/lib/module/handlers/gestures/GestureDetector/dropHandlers.js +12 -0
  165. package/lib/module/handlers/gestures/GestureDetector/dropHandlers.js.map +1 -0
  166. package/lib/module/handlers/gestures/GestureDetector/index.js +115 -0
  167. package/lib/module/handlers/gestures/GestureDetector/index.js.map +1 -0
  168. package/lib/module/handlers/gestures/GestureDetector/needsToReattach.js +18 -0
  169. package/lib/module/handlers/gestures/GestureDetector/needsToReattach.js.map +1 -0
  170. package/lib/module/handlers/gestures/GestureDetector/types.js +2 -0
  171. package/lib/module/handlers/gestures/GestureDetector/types.js.map +1 -0
  172. package/lib/module/handlers/gestures/GestureDetector/updateHandlers.js +64 -0
  173. package/lib/module/handlers/gestures/GestureDetector/updateHandlers.js.map +1 -0
  174. package/lib/module/handlers/gestures/GestureDetector/useAnimatedGesture.js +165 -0
  175. package/lib/module/handlers/gestures/GestureDetector/useAnimatedGesture.js.map +1 -0
  176. package/lib/module/handlers/gestures/GestureDetector/useDetectorUpdater.js +41 -0
  177. package/lib/module/handlers/gestures/GestureDetector/useDetectorUpdater.js.map +1 -0
  178. package/lib/module/handlers/gestures/GestureDetector/useViewRefHandler.js +36 -0
  179. package/lib/module/handlers/gestures/GestureDetector/useViewRefHandler.js.map +1 -0
  180. package/lib/module/handlers/gestures/GestureDetector/utils.js +142 -0
  181. package/lib/module/handlers/gestures/GestureDetector/utils.js.map +1 -0
  182. package/lib/module/handlers/gestures/gestureComposition.js +3 -1
  183. package/lib/module/handlers/gestures/gestureComposition.js.map +1 -1
  184. package/lib/module/handlers/gestures/gestureStateManager.js +8 -0
  185. package/lib/module/handlers/gestures/gestureStateManager.js.map +1 -1
  186. package/lib/module/handlers/gestures/reanimatedWrapper.js.map +1 -1
  187. package/lib/module/utils.js +34 -0
  188. package/lib/module/utils.js.map +1 -1
  189. package/lib/module/web/detectors/RotationGestureDetector.js +6 -8
  190. package/lib/module/web/detectors/RotationGestureDetector.js.map +1 -1
  191. package/lib/module/web/detectors/ScaleGestureDetector.js +5 -6
  192. package/lib/module/web/detectors/ScaleGestureDetector.js.map +1 -1
  193. package/lib/module/web/handlers/FlingGestureHandler.js +1 -0
  194. package/lib/module/web/handlers/FlingGestureHandler.js.map +1 -1
  195. package/lib/module/web/handlers/GestureHandler.js +56 -64
  196. package/lib/module/web/handlers/GestureHandler.js.map +1 -1
  197. package/lib/module/web/handlers/LongPressGestureHandler.js +1 -0
  198. package/lib/module/web/handlers/LongPressGestureHandler.js.map +1 -1
  199. package/lib/module/web/handlers/ManualGestureHandler.js +1 -0
  200. package/lib/module/web/handlers/ManualGestureHandler.js.map +1 -1
  201. package/lib/module/web/handlers/NativeViewGestureHandler.js +7 -4
  202. package/lib/module/web/handlers/NativeViewGestureHandler.js.map +1 -1
  203. package/lib/module/web/handlers/PanGestureHandler.js +28 -18
  204. package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
  205. package/lib/module/web/handlers/PinchGestureHandler.js +1 -0
  206. package/lib/module/web/handlers/PinchGestureHandler.js.map +1 -1
  207. package/lib/module/web/handlers/RotationGestureHandler.js +1 -0
  208. package/lib/module/web/handlers/RotationGestureHandler.js.map +1 -1
  209. package/lib/module/web/handlers/TapGestureHandler.js +18 -12
  210. package/lib/module/web/handlers/TapGestureHandler.js.map +1 -1
  211. package/lib/module/web/interfaces.js.map +1 -1
  212. package/lib/module/web/tools/GestureHandlerOrchestrator.js +1 -6
  213. package/lib/module/web/tools/GestureHandlerOrchestrator.js.map +1 -1
  214. package/lib/module/web/tools/PointerEventManager.js +8 -3
  215. package/lib/module/web/tools/PointerEventManager.js.map +1 -1
  216. package/lib/module/web/tools/PointerTracker.js +89 -57
  217. package/lib/module/web/tools/PointerTracker.js.map +1 -1
  218. package/lib/module/web/tools/TouchEventManager.js +7 -3
  219. package/lib/module/web/tools/TouchEventManager.js.map +1 -1
  220. package/lib/module/web/tools/Vector.js +2 -1
  221. package/lib/module/web/tools/Vector.js.map +1 -1
  222. package/lib/module/web/utils.js +29 -0
  223. package/lib/module/web/utils.js.map +1 -1
  224. package/lib/typescript/RNGestureHandlerModule.d.ts +2 -15
  225. package/lib/typescript/RNGestureHandlerModule.web.d.ts +15 -0
  226. package/lib/typescript/RNRenderer.d.ts +1 -3
  227. package/lib/typescript/RNRenderer.web.d.ts +3 -0
  228. package/lib/typescript/components/GestureButtons.d.ts +3 -34
  229. package/lib/typescript/components/GestureComponents.d.ts +21 -7
  230. package/lib/typescript/components/GestureComponents.web.d.ts +8 -0
  231. package/lib/typescript/components/GestureHandlerButton.d.ts +3 -3
  232. package/lib/typescript/components/GestureHandlerButton.web.d.ts +4 -0
  233. package/lib/typescript/getReactNativeVersion.d.ts +4 -1
  234. package/lib/typescript/getReactNativeVersion.web.d.ts +1 -0
  235. package/lib/typescript/getShadowNodeFromRef.d.ts +1 -1
  236. package/lib/typescript/getShadowNodeFromRef.web.d.ts +1 -0
  237. package/lib/typescript/handlers/PressabilityDebugView.d.ts +1 -1
  238. package/lib/typescript/handlers/PressabilityDebugView.web.d.ts +1 -0
  239. package/lib/typescript/handlers/customDirectEventTypes.d.ts +1 -2
  240. package/lib/typescript/handlers/customDirectEventTypes.web.d.ts +2 -0
  241. package/lib/typescript/handlers/gestureHandlerCommon.d.ts +3 -2
  242. package/lib/typescript/handlers/gestures/GestureDetector/Wrap.d.ts +13 -0
  243. package/lib/typescript/handlers/gestures/GestureDetector/attachHandlers.d.ts +13 -0
  244. package/lib/typescript/handlers/gestures/GestureDetector/dropHandlers.d.ts +2 -0
  245. package/lib/typescript/handlers/gestures/{GestureDetector.d.ts → GestureDetector/index.d.ts} +4 -12
  246. package/lib/typescript/handlers/gestures/GestureDetector/needsToReattach.d.ts +3 -0
  247. package/lib/typescript/handlers/gestures/GestureDetector/types.d.ts +20 -0
  248. package/lib/typescript/handlers/gestures/GestureDetector/updateHandlers.d.ts +4 -0
  249. package/lib/typescript/handlers/gestures/GestureDetector/useAnimatedGesture.d.ts +2 -0
  250. package/lib/typescript/handlers/gestures/GestureDetector/useDetectorUpdater.d.ts +5 -0
  251. package/lib/typescript/handlers/gestures/GestureDetector/useViewRefHandler.d.ts +3 -0
  252. package/lib/typescript/handlers/gestures/GestureDetector/utils.d.ts +12 -0
  253. package/lib/typescript/handlers/gestures/reanimatedWrapper.d.ts +1 -1
  254. package/lib/typescript/utils.d.ts +10 -0
  255. package/lib/typescript/web/handlers/GestureHandler.d.ts +1 -0
  256. package/lib/typescript/web/interfaces.d.ts +1 -0
  257. package/lib/typescript/web/tools/PointerTracker.d.ts +34 -31
  258. package/lib/typescript/web/utils.d.ts +4 -0
  259. package/package.json +5 -5
  260. package/src/RNGestureHandlerModule.ts +4 -104
  261. package/src/RNGestureHandlerModule.web.ts +105 -0
  262. package/src/RNRenderer.ts +3 -3
  263. package/src/RNRenderer.web.ts +3 -0
  264. package/src/components/GestureButtons.tsx +36 -4
  265. package/src/components/GestureComponents.tsx +131 -24
  266. package/src/components/GestureComponents.web.tsx +41 -0
  267. package/src/components/GestureHandlerButton.tsx +4 -5
  268. package/src/components/GestureHandlerButton.web.tsx +6 -0
  269. package/src/components/GestureHandlerRootView.tsx +6 -0
  270. package/src/components/{GestureHandlerRootView.native.tsx → GestureHandlerRootView.web.tsx} +0 -6
  271. package/src/getReactNativeVersion.ts +9 -1
  272. package/src/getReactNativeVersion.web.ts +3 -0
  273. package/src/getShadowNodeFromRef.ts +41 -4
  274. package/src/getShadowNodeFromRef.web.ts +7 -0
  275. package/src/handlers/PressabilityDebugView.tsx +2 -4
  276. package/src/handlers/PressabilityDebugView.web.tsx +4 -0
  277. package/src/handlers/createHandler.tsx +1 -3
  278. package/src/handlers/customDirectEventTypes.ts +2 -5
  279. package/src/handlers/customDirectEventTypes.web.ts +5 -0
  280. package/src/handlers/gestureHandlerCommon.ts +4 -1
  281. package/src/handlers/gestures/GestureDetector/Wrap.tsx +35 -0
  282. package/src/handlers/gestures/GestureDetector/attachHandlers.ts +112 -0
  283. package/src/handlers/gestures/GestureDetector/dropHandlers.ts +14 -0
  284. package/src/handlers/gestures/GestureDetector/index.tsx +187 -0
  285. package/src/handlers/gestures/GestureDetector/needsToReattach.ts +27 -0
  286. package/src/handlers/gestures/GestureDetector/types.ts +32 -0
  287. package/src/handlers/gestures/GestureDetector/updateHandlers.ts +94 -0
  288. package/src/handlers/gestures/GestureDetector/useAnimatedGesture.ts +206 -0
  289. package/src/handlers/gestures/GestureDetector/useDetectorUpdater.ts +69 -0
  290. package/src/handlers/gestures/GestureDetector/useViewRefHandler.ts +54 -0
  291. package/src/handlers/gestures/GestureDetector/utils.ts +185 -0
  292. package/src/handlers/gestures/gestureComposition.ts +2 -0
  293. package/src/handlers/gestures/gestureStateManager.ts +12 -4
  294. package/src/handlers/gestures/reanimatedWrapper.ts +19 -17
  295. package/src/utils.ts +39 -0
  296. package/src/web/detectors/RotationGestureDetector.ts +6 -8
  297. package/src/web/detectors/ScaleGestureDetector.ts +5 -6
  298. package/src/web/handlers/FlingGestureHandler.ts +2 -0
  299. package/src/web/handlers/GestureHandler.ts +53 -62
  300. package/src/web/handlers/LongPressGestureHandler.ts +2 -0
  301. package/src/web/handlers/ManualGestureHandler.ts +2 -0
  302. package/src/web/handlers/NativeViewGestureHandler.ts +8 -4
  303. package/src/web/handlers/PanGestureHandler.ts +32 -19
  304. package/src/web/handlers/PinchGestureHandler.ts +2 -0
  305. package/src/web/handlers/RotationGestureHandler.ts +2 -0
  306. package/src/web/handlers/TapGestureHandler.ts +20 -12
  307. package/src/web/interfaces.ts +1 -0
  308. package/src/web/tools/GestureHandlerOrchestrator.ts +1 -7
  309. package/src/web/tools/PointerEventManager.ts +10 -3
  310. package/src/web/tools/PointerTracker.ts +81 -74
  311. package/src/web/tools/TouchEventManager.ts +5 -3
  312. package/src/web/tools/Vector.ts +2 -4
  313. package/src/web/utils.ts +34 -0
  314. package/lib/commonjs/RNGestureHandlerModule.native.js +0 -16
  315. package/lib/commonjs/RNGestureHandlerModule.native.js.map +0 -1
  316. package/lib/commonjs/RNRenderer.native.js +0 -16
  317. package/lib/commonjs/RNRenderer.native.js.map +0 -1
  318. package/lib/commonjs/components/GestureComponents.native.js +0 -115
  319. package/lib/commonjs/components/GestureComponents.native.js.map +0 -1
  320. package/lib/commonjs/components/GestureHandlerButton.native.js +0 -14
  321. package/lib/commonjs/components/GestureHandlerButton.native.js.map +0 -1
  322. package/lib/commonjs/components/GestureHandlerRootView.native.js.map +0 -1
  323. package/lib/commonjs/getReactNativeVersion.native.js +0 -22
  324. package/lib/commonjs/getReactNativeVersion.native.js.map +0 -1
  325. package/lib/commonjs/getShadowNodeFromRef.native.js +0 -44
  326. package/lib/commonjs/getShadowNodeFromRef.native.js.map +0 -1
  327. package/lib/commonjs/handlers/PressabilityDebugView.native.js +0 -14
  328. package/lib/commonjs/handlers/PressabilityDebugView.native.js.map +0 -1
  329. package/lib/commonjs/handlers/customDirectEventTypes.native.js +0 -14
  330. package/lib/commonjs/handlers/customDirectEventTypes.native.js.map +0 -1
  331. package/lib/commonjs/handlers/gestures/GestureDetector.js +0 -704
  332. package/lib/commonjs/handlers/gestures/GestureDetector.js.map +0 -1
  333. package/lib/module/RNGestureHandlerModule.native.js +0 -5
  334. package/lib/module/RNGestureHandlerModule.native.js.map +0 -1
  335. package/lib/module/RNRenderer.native.js +0 -4
  336. package/lib/module/RNRenderer.native.js.map +0 -1
  337. package/lib/module/components/GestureComponents.native.js +0 -90
  338. package/lib/module/components/GestureComponents.native.js.map +0 -1
  339. package/lib/module/components/GestureHandlerButton.native.js +0 -3
  340. package/lib/module/components/GestureHandlerButton.native.js.map +0 -1
  341. package/lib/module/components/GestureHandlerRootView.native.js.map +0 -1
  342. package/lib/module/getReactNativeVersion.native.js +0 -10
  343. package/lib/module/getReactNativeVersion.native.js.map +0 -1
  344. package/lib/module/getShadowNodeFromRef.native.js +0 -37
  345. package/lib/module/getShadowNodeFromRef.native.js.map +0 -1
  346. package/lib/module/handlers/PressabilityDebugView.native.js +0 -3
  347. package/lib/module/handlers/PressabilityDebugView.native.js.map +0 -1
  348. package/lib/module/handlers/customDirectEventTypes.native.js +0 -3
  349. package/lib/module/handlers/customDirectEventTypes.native.js.map +0 -1
  350. package/lib/module/handlers/gestures/GestureDetector.js +0 -654
  351. package/lib/module/handlers/gestures/GestureDetector.js.map +0 -1
  352. package/lib/typescript/RNGestureHandlerModule.native.d.ts +0 -2
  353. package/lib/typescript/RNRenderer.native.d.ts +0 -1
  354. package/lib/typescript/components/GestureComponents.native.d.ts +0 -22
  355. package/lib/typescript/components/GestureHandlerButton.native.d.ts +0 -4
  356. package/lib/typescript/getReactNativeVersion.native.d.ts +0 -4
  357. package/lib/typescript/getShadowNodeFromRef.native.d.ts +0 -1
  358. package/lib/typescript/handlers/PressabilityDebugView.native.d.ts +0 -1
  359. package/lib/typescript/handlers/customDirectEventTypes.native.d.ts +0 -1
  360. package/src/RNGestureHandlerModule.native.ts +0 -5
  361. package/src/RNRenderer.native.ts +0 -3
  362. package/src/components/GestureComponents.native.tsx +0 -148
  363. package/src/components/GestureHandlerButton.native.tsx +0 -5
  364. package/src/getReactNativeVersion.native.ts +0 -11
  365. package/src/getShadowNodeFromRef.native.ts +0 -44
  366. package/src/handlers/PressabilityDebugView.native.tsx +0 -2
  367. package/src/handlers/customDirectEventTypes.native.ts +0 -2
  368. package/src/handlers/gestures/GestureDetector.tsx +0 -894
  369. /package/lib/typescript/components/{GestureHandlerRootView.native.d.ts → GestureHandlerRootView.web.d.ts} +0 -0
@@ -1,894 +0,0 @@
1
- import React, { useContext, useEffect, useRef, useState } from 'react';
2
- import {
3
- GestureType,
4
- HandlerCallbacks,
5
- BaseGesture,
6
- GestureRef,
7
- CALLBACK_TYPE,
8
- } from './gesture';
9
- import { Reanimated, SharedValue } from './reanimatedWrapper';
10
- import { registerHandler, unregisterHandler } from '../handlersRegistry';
11
- import RNGestureHandlerModule from '../../RNGestureHandlerModule';
12
- import {
13
- baseGestureHandlerWithMonitorProps,
14
- filterConfig,
15
- findNodeHandle,
16
- GestureTouchEvent,
17
- GestureUpdateEvent,
18
- GestureStateChangeEvent,
19
- HandlerStateChangeEvent,
20
- scheduleFlushOperations,
21
- UserSelect,
22
- TouchAction,
23
- } from '../gestureHandlerCommon';
24
- import {
25
- GestureStateManager,
26
- GestureStateManagerType,
27
- } from './gestureStateManager';
28
- import { flingGestureHandlerProps } from '../FlingGestureHandler';
29
- import { forceTouchGestureHandlerProps } from '../ForceTouchGestureHandler';
30
- import { longPressGestureHandlerProps } from '../LongPressGestureHandler';
31
- import {
32
- panGestureHandlerProps,
33
- panGestureHandlerCustomNativeProps,
34
- } from '../PanGestureHandler';
35
- import { tapGestureHandlerProps } from '../TapGestureHandler';
36
- import { hoverGestureHandlerProps } from './hoverGesture';
37
- import { State } from '../../State';
38
- import { TouchEventType } from '../../TouchEventType';
39
- import { ComposedGesture } from './gestureComposition';
40
- import { ActionType } from '../../ActionType';
41
- import { isFabric, isJestEnv, tagMessage } from '../../utils';
42
- import { getReactNativeVersion } from '../../getReactNativeVersion';
43
- import { getShadowNodeFromRef } from '../../getShadowNodeFromRef';
44
- import { Platform } from 'react-native';
45
- import { onGestureHandlerEvent } from './eventReceiver';
46
- import { RNRenderer } from '../../RNRenderer';
47
- import { isNewWebImplementationEnabled } from '../../EnableNewWebImplementation';
48
- import { nativeViewGestureHandlerProps } from '../NativeViewGestureHandler';
49
- import GestureHandlerRootViewContext from '../../GestureHandlerRootViewContext';
50
- import { ghQueueMicrotask } from '../../ghQueueMicrotask';
51
-
52
- type AttachGestureHandlerWeb = (
53
- handlerTag: number,
54
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
- newView: any,
56
- _actionType: ActionType,
57
- propsRef: React.RefObject<unknown>
58
- ) => void;
59
-
60
- declare const global: {
61
- isFormsStackingContext: (node: unknown) => boolean | null; // JSI function
62
- };
63
-
64
- const ALLOWED_PROPS = [
65
- ...baseGestureHandlerWithMonitorProps,
66
- ...tapGestureHandlerProps,
67
- ...panGestureHandlerProps,
68
- ...panGestureHandlerCustomNativeProps,
69
- ...longPressGestureHandlerProps,
70
- ...forceTouchGestureHandlerProps,
71
- ...flingGestureHandlerProps,
72
- ...hoverGestureHandlerProps,
73
- ...nativeViewGestureHandlerProps,
74
- ];
75
-
76
- export type GestureConfigReference = {
77
- config: GestureType[];
78
- animatedEventHandler: unknown;
79
- animatedHandlers: SharedValue<
80
- HandlerCallbacks<Record<string, unknown>>[] | null
81
- > | null;
82
- firstExecution: boolean;
83
- useReanimatedHook: boolean;
84
- };
85
-
86
- function convertToHandlerTag(ref: GestureRef): number {
87
- if (typeof ref === 'number') {
88
- return ref;
89
- } else if (ref instanceof BaseGesture) {
90
- return ref.handlerTag;
91
- } else {
92
- // @ts-ignore in this case it should be a ref either to gesture object or
93
- // a gesture handler component, in both cases handlerTag property exists
94
- return ref.current?.handlerTag ?? -1;
95
- }
96
- }
97
-
98
- function extractValidHandlerTags(interactionGroup: GestureRef[] | undefined) {
99
- return (
100
- interactionGroup?.map(convertToHandlerTag)?.filter((tag) => tag > 0) ?? []
101
- );
102
- }
103
-
104
- function dropHandlers(preparedGesture: GestureConfigReference) {
105
- for (const handler of preparedGesture.config) {
106
- RNGestureHandlerModule.dropGestureHandler(handler.handlerTag);
107
-
108
- unregisterHandler(handler.handlerTag, handler.config.testId);
109
- }
110
-
111
- scheduleFlushOperations();
112
- }
113
-
114
- function checkGestureCallbacksForWorklets(gesture: GestureType) {
115
- // if a gesture is explicitly marked to run on the JS thread there is no need to check
116
- // if callbacks are worklets as the user is aware they will be ran on the JS thread
117
- if (gesture.config.runOnJS) {
118
- return;
119
- }
120
-
121
- const areSomeNotWorklets = gesture.handlers.isWorklet.includes(false);
122
- const areSomeWorklets = gesture.handlers.isWorklet.includes(true);
123
-
124
- // if some of the callbacks are worklets and some are not, and the gesture is not
125
- // explicitly marked with `.runOnJS(true)` show an error
126
- if (areSomeNotWorklets && areSomeWorklets) {
127
- console.error(
128
- tagMessage(
129
- `Some of the callbacks in the gesture are worklets and some are not. Either make sure that all calbacks are marked as 'worklet' if you wish to run them on the UI thread or use '.runOnJS(true)' modifier on the gesture explicitly to run all callbacks on the JS thread.`
130
- )
131
- );
132
- }
133
- }
134
-
135
- interface WebEventHandler {
136
- onGestureHandlerEvent: (event: HandlerStateChangeEvent<unknown>) => void;
137
- onGestureHandlerStateChange?: (
138
- event: HandlerStateChangeEvent<unknown>
139
- ) => void;
140
- }
141
-
142
- interface AttachHandlersConfig {
143
- preparedGesture: GestureConfigReference;
144
- gestureConfig: ComposedGesture | GestureType;
145
- gesture: GestureType[];
146
- viewTag: number;
147
- webEventHandlersRef: React.RefObject<WebEventHandler>;
148
- mountedRef: React.RefObject<boolean>;
149
- }
150
-
151
- function attachHandlers({
152
- preparedGesture,
153
- gestureConfig,
154
- gesture,
155
- viewTag,
156
- webEventHandlersRef,
157
- mountedRef,
158
- }: AttachHandlersConfig) {
159
- if (!preparedGesture.firstExecution) {
160
- gestureConfig.initialize();
161
- } else {
162
- preparedGesture.firstExecution = false;
163
- }
164
-
165
- // use queueMicrotask to extract handlerTags, because all refs should be initialized
166
- // when it's ran
167
- ghQueueMicrotask(() => {
168
- if (!mountedRef.current) {
169
- return;
170
- }
171
- gestureConfig.prepare();
172
- });
173
-
174
- for (const handler of gesture) {
175
- checkGestureCallbacksForWorklets(handler);
176
- RNGestureHandlerModule.createGestureHandler(
177
- handler.handlerName,
178
- handler.handlerTag,
179
- filterConfig(handler.config, ALLOWED_PROPS)
180
- );
181
-
182
- registerHandler(handler.handlerTag, handler, handler.config.testId);
183
- }
184
-
185
- // use queueMicrotask to extract handlerTags, because all refs should be initialized
186
- // when it's ran
187
- ghQueueMicrotask(() => {
188
- if (!mountedRef.current) {
189
- return;
190
- }
191
- for (const handler of gesture) {
192
- let requireToFail: number[] = [];
193
- if (handler.config.requireToFail) {
194
- requireToFail = extractValidHandlerTags(handler.config.requireToFail);
195
- }
196
-
197
- let simultaneousWith: number[] = [];
198
- if (handler.config.simultaneousWith) {
199
- simultaneousWith = extractValidHandlerTags(
200
- handler.config.simultaneousWith
201
- );
202
- }
203
-
204
- let blocksHandlers: number[] = [];
205
- if (handler.config.blocksHandlers) {
206
- blocksHandlers = extractValidHandlerTags(handler.config.blocksHandlers);
207
- }
208
-
209
- RNGestureHandlerModule.updateGestureHandler(
210
- handler.handlerTag,
211
- filterConfig(handler.config, ALLOWED_PROPS, {
212
- simultaneousHandlers: simultaneousWith,
213
- waitFor: requireToFail,
214
- blocksHandlers: blocksHandlers,
215
- })
216
- );
217
- }
218
-
219
- scheduleFlushOperations();
220
- });
221
-
222
- preparedGesture.config = gesture;
223
-
224
- for (const gesture of preparedGesture.config) {
225
- const actionType = gesture.shouldUseReanimated
226
- ? ActionType.REANIMATED_WORKLET
227
- : ActionType.JS_FUNCTION_NEW_API;
228
-
229
- if (Platform.OS === 'web') {
230
- (RNGestureHandlerModule.attachGestureHandler as AttachGestureHandlerWeb)(
231
- gesture.handlerTag,
232
- viewTag,
233
- ActionType.JS_FUNCTION_OLD_API, // ignored on web
234
- webEventHandlersRef
235
- );
236
- } else {
237
- RNGestureHandlerModule.attachGestureHandler(
238
- gesture.handlerTag,
239
- viewTag,
240
- actionType
241
- );
242
- }
243
- }
244
-
245
- if (preparedGesture.animatedHandlers) {
246
- const isAnimatedGesture = (g: GestureType) => g.shouldUseReanimated;
247
-
248
- preparedGesture.animatedHandlers.value = gesture
249
- .filter(isAnimatedGesture)
250
- .map((g) => g.handlers) as unknown as HandlerCallbacks<
251
- Record<string, unknown>
252
- >[];
253
- }
254
- }
255
-
256
- function updateHandlers(
257
- preparedGesture: GestureConfigReference,
258
- gestureConfig: ComposedGesture | GestureType,
259
- gesture: GestureType[],
260
- mountedRef: React.RefObject<boolean>
261
- ) {
262
- gestureConfig.prepare();
263
-
264
- for (let i = 0; i < gesture.length; i++) {
265
- const handler = preparedGesture.config[i];
266
- checkGestureCallbacksForWorklets(handler);
267
-
268
- // only update handlerTag when it's actually different, it may be the same
269
- // if gesture config object is wrapped with useMemo
270
- if (gesture[i].handlerTag !== handler.handlerTag) {
271
- gesture[i].handlerTag = handler.handlerTag;
272
- gesture[i].handlers.handlerTag = handler.handlerTag;
273
- }
274
- }
275
-
276
- // use queueMicrotask to extract handlerTags, because when it's ran, all refs should be updated
277
- // and handlerTags in BaseGesture references should be updated in the loop above (we need to wait
278
- // in case of external relations)
279
- ghQueueMicrotask(() => {
280
- if (!mountedRef.current) {
281
- return;
282
- }
283
- for (let i = 0; i < gesture.length; i++) {
284
- const handler = preparedGesture.config[i];
285
-
286
- handler.config = gesture[i].config;
287
- handler.handlers = gesture[i].handlers;
288
-
289
- const requireToFail = extractValidHandlerTags(
290
- handler.config.requireToFail
291
- );
292
-
293
- const simultaneousWith = extractValidHandlerTags(
294
- handler.config.simultaneousWith
295
- );
296
-
297
- RNGestureHandlerModule.updateGestureHandler(
298
- handler.handlerTag,
299
- filterConfig(handler.config, ALLOWED_PROPS, {
300
- simultaneousHandlers: simultaneousWith,
301
- waitFor: requireToFail,
302
- })
303
- );
304
-
305
- registerHandler(handler.handlerTag, handler, handler.config.testId);
306
- }
307
-
308
- if (preparedGesture.animatedHandlers) {
309
- const previousHandlersValue =
310
- preparedGesture.animatedHandlers.value ?? [];
311
- const newHandlersValue = preparedGesture.config
312
- .filter((g) => g.shouldUseReanimated) // ignore gestures that shouldn't run on UI
313
- .map((g) => g.handlers) as unknown as HandlerCallbacks<
314
- Record<string, unknown>
315
- >[];
316
-
317
- // if amount of gesture configs changes, we need to update the callbacks in shared value
318
- let shouldUpdateSharedValue =
319
- previousHandlersValue.length !== newHandlersValue.length;
320
-
321
- if (!shouldUpdateSharedValue) {
322
- // if the amount is the same, we need to check if any of the configs inside has changed
323
- for (let i = 0; i < newHandlersValue.length; i++) {
324
- if (
325
- // we can use the `gestureId` prop as it's unique for every config instance
326
- newHandlersValue[i].gestureId !== previousHandlersValue[i].gestureId
327
- ) {
328
- shouldUpdateSharedValue = true;
329
- break;
330
- }
331
- }
332
- }
333
-
334
- if (shouldUpdateSharedValue) {
335
- preparedGesture.animatedHandlers.value = newHandlersValue;
336
- }
337
- }
338
-
339
- scheduleFlushOperations();
340
- });
341
- }
342
-
343
- function needsToReattach(
344
- preparedGesture: GestureConfigReference,
345
- gesture: GestureType[]
346
- ) {
347
- if (gesture.length !== preparedGesture.config.length) {
348
- return true;
349
- }
350
- for (let i = 0; i < gesture.length; i++) {
351
- if (
352
- gesture[i].handlerName !== preparedGesture.config[i].handlerName ||
353
- gesture[i].shouldUseReanimated !==
354
- preparedGesture.config[i].shouldUseReanimated
355
- ) {
356
- return true;
357
- }
358
- }
359
-
360
- return false;
361
- }
362
-
363
- function isStateChangeEvent(
364
- event: GestureUpdateEvent | GestureStateChangeEvent | GestureTouchEvent
365
- ): event is GestureStateChangeEvent {
366
- 'worklet';
367
- // @ts-ignore Yes, the oldState prop is missing on GestureTouchEvent, that's the point
368
- return event.oldState != null;
369
- }
370
-
371
- function isTouchEvent(
372
- event: GestureUpdateEvent | GestureStateChangeEvent | GestureTouchEvent
373
- ): event is GestureTouchEvent {
374
- 'worklet';
375
- return event.eventType != null;
376
- }
377
-
378
- function getHandler(
379
- type: CALLBACK_TYPE,
380
- gesture: HandlerCallbacks<Record<string, unknown>>
381
- ) {
382
- 'worklet';
383
- switch (type) {
384
- case CALLBACK_TYPE.BEGAN:
385
- return gesture.onBegin;
386
- case CALLBACK_TYPE.START:
387
- return gesture.onStart;
388
- case CALLBACK_TYPE.UPDATE:
389
- return gesture.onUpdate;
390
- case CALLBACK_TYPE.CHANGE:
391
- return gesture.onChange;
392
- case CALLBACK_TYPE.END:
393
- return gesture.onEnd;
394
- case CALLBACK_TYPE.FINALIZE:
395
- return gesture.onFinalize;
396
- case CALLBACK_TYPE.TOUCHES_DOWN:
397
- return gesture.onTouchesDown;
398
- case CALLBACK_TYPE.TOUCHES_MOVE:
399
- return gesture.onTouchesMove;
400
- case CALLBACK_TYPE.TOUCHES_UP:
401
- return gesture.onTouchesUp;
402
- case CALLBACK_TYPE.TOUCHES_CANCELLED:
403
- return gesture.onTouchesCancelled;
404
- }
405
- }
406
-
407
- function touchEventTypeToCallbackType(
408
- eventType: TouchEventType
409
- ): CALLBACK_TYPE {
410
- 'worklet';
411
- switch (eventType) {
412
- case TouchEventType.TOUCHES_DOWN:
413
- return CALLBACK_TYPE.TOUCHES_DOWN;
414
- case TouchEventType.TOUCHES_MOVE:
415
- return CALLBACK_TYPE.TOUCHES_MOVE;
416
- case TouchEventType.TOUCHES_UP:
417
- return CALLBACK_TYPE.TOUCHES_UP;
418
- case TouchEventType.TOUCHES_CANCELLED:
419
- return CALLBACK_TYPE.TOUCHES_CANCELLED;
420
- }
421
- return CALLBACK_TYPE.UNDEFINED;
422
- }
423
-
424
- function runWorklet(
425
- type: CALLBACK_TYPE,
426
- gesture: HandlerCallbacks<Record<string, unknown>>,
427
- event: GestureStateChangeEvent | GestureUpdateEvent | GestureTouchEvent,
428
- ...args: any[]
429
- ) {
430
- 'worklet';
431
- const handler = getHandler(type, gesture);
432
- if (gesture.isWorklet[type]) {
433
- // @ts-ignore Logic below makes sure the correct event is send to the
434
- // correct handler.
435
- handler?.(event, ...args);
436
- } else if (handler) {
437
- console.warn(tagMessage('Animated gesture callback must be a worklet'));
438
- }
439
- }
440
-
441
- function useAnimatedGesture(
442
- preparedGesture: GestureConfigReference,
443
- needsRebuild: boolean
444
- ) {
445
- if (!Reanimated) {
446
- return;
447
- }
448
-
449
- // Hooks are called conditionally, but the condition is whether the
450
- // react-native-reanimated is installed, which shouldn't change while running
451
- // eslint-disable-next-line react-hooks/rules-of-hooks
452
- const sharedHandlersCallbacks = Reanimated.useSharedValue<
453
- HandlerCallbacks<Record<string, unknown>>[] | null
454
- >(null);
455
-
456
- // eslint-disable-next-line react-hooks/rules-of-hooks
457
- const lastUpdateEvent = Reanimated.useSharedValue<
458
- (GestureUpdateEvent | undefined)[]
459
- >([]);
460
-
461
- // not every gesture needs a state controller, init them lazily
462
- const stateControllers: GestureStateManagerType[] = [];
463
-
464
- const callback = (
465
- event: GestureStateChangeEvent | GestureUpdateEvent | GestureTouchEvent
466
- ) => {
467
- 'worklet';
468
-
469
- const currentCallback = sharedHandlersCallbacks.value;
470
- if (!currentCallback) {
471
- return;
472
- }
473
-
474
- for (let i = 0; i < currentCallback.length; i++) {
475
- const gesture = currentCallback[i];
476
-
477
- if (event.handlerTag === gesture.handlerTag) {
478
- if (isStateChangeEvent(event)) {
479
- if (
480
- event.oldState === State.UNDETERMINED &&
481
- event.state === State.BEGAN
482
- ) {
483
- runWorklet(CALLBACK_TYPE.BEGAN, gesture, event);
484
- } else if (
485
- (event.oldState === State.BEGAN ||
486
- event.oldState === State.UNDETERMINED) &&
487
- event.state === State.ACTIVE
488
- ) {
489
- runWorklet(CALLBACK_TYPE.START, gesture, event);
490
- lastUpdateEvent.value[gesture.handlerTag] = undefined;
491
- } else if (
492
- event.oldState !== event.state &&
493
- event.state === State.END
494
- ) {
495
- if (event.oldState === State.ACTIVE) {
496
- runWorklet(CALLBACK_TYPE.END, gesture, event, true);
497
- }
498
- runWorklet(CALLBACK_TYPE.FINALIZE, gesture, event, true);
499
- } else if (
500
- (event.state === State.FAILED || event.state === State.CANCELLED) &&
501
- event.state !== event.oldState
502
- ) {
503
- if (event.oldState === State.ACTIVE) {
504
- runWorklet(CALLBACK_TYPE.END, gesture, event, false);
505
- }
506
- runWorklet(CALLBACK_TYPE.FINALIZE, gesture, event, false);
507
- }
508
- } else if (isTouchEvent(event)) {
509
- if (!stateControllers[i]) {
510
- stateControllers[i] = GestureStateManager.create(event.handlerTag);
511
- }
512
-
513
- if (event.eventType !== TouchEventType.UNDETERMINED) {
514
- runWorklet(
515
- touchEventTypeToCallbackType(event.eventType),
516
- gesture,
517
- event,
518
- stateControllers[i]
519
- );
520
- }
521
- } else {
522
- runWorklet(CALLBACK_TYPE.UPDATE, gesture, event);
523
-
524
- if (gesture.onChange && gesture.changeEventCalculator) {
525
- runWorklet(
526
- CALLBACK_TYPE.CHANGE,
527
- gesture,
528
- gesture.changeEventCalculator?.(
529
- event,
530
- lastUpdateEvent.value[gesture.handlerTag]
531
- )
532
- );
533
-
534
- lastUpdateEvent.value[gesture.handlerTag] = event;
535
- }
536
- }
537
- }
538
- }
539
- };
540
-
541
- // eslint-disable-next-line react-hooks/rules-of-hooks
542
- const event = Reanimated.useEvent(
543
- callback,
544
- ['onGestureHandlerStateChange', 'onGestureHandlerEvent'],
545
- needsRebuild
546
- );
547
-
548
- preparedGesture.animatedEventHandler = event;
549
- preparedGesture.animatedHandlers = sharedHandlersCallbacks;
550
- }
551
-
552
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
553
- function validateDetectorChildren(ref: any) {
554
- // finds the first native view under the Wrap component and traverses the fiber tree upwards
555
- // to check whether there is more than one native view as a pseudo-direct child of GestureDetector
556
- // i.e. this is not ok:
557
- // Wrap
558
- // |
559
- // / \
560
- // / \
561
- // / \
562
- // / \
563
- // NativeView NativeView
564
- //
565
- // but this is fine:
566
- // Wrap
567
- // |
568
- // NativeView
569
- // |
570
- // / \
571
- // / \
572
- // / \
573
- // / \
574
- // NativeView NativeView
575
- if (__DEV__ && Platform.OS !== 'web') {
576
- const REACT_NATIVE_VERSION = getReactNativeVersion();
577
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
578
- const wrapType =
579
- REACT_NATIVE_VERSION.minor > 63 || REACT_NATIVE_VERSION.major > 0
580
- ? // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
581
- ref._reactInternals.elementType
582
- : // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
583
- ref._reactInternalFiber.elementType;
584
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
585
- let instance =
586
- RNRenderer.findHostInstance_DEPRECATED(
587
- ref
588
- )._internalFiberInstanceHandleDEV;
589
-
590
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
591
- while (instance && instance.elementType !== wrapType) {
592
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
593
- if (instance.sibling) {
594
- throw new Error(
595
- 'GestureDetector has more than one native view as its children. This can happen if you are using a custom component that renders multiple views, like React.Fragment. You should wrap content of GestureDetector with a <View> or <Animated.View>.'
596
- );
597
- }
598
-
599
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
600
- instance = instance.return;
601
- }
602
- }
603
- }
604
-
605
- const applyUserSelectProp = (
606
- userSelect: UserSelect,
607
- gesture: ComposedGesture | GestureType
608
- ): void => {
609
- for (const g of gesture.toGestureArray()) {
610
- g.config.userSelect = userSelect;
611
- }
612
- };
613
-
614
- const applyEnableContextMenuProp = (
615
- enableContextMenu: boolean,
616
- gesture: ComposedGesture | GestureType
617
- ): void => {
618
- for (const g of gesture.toGestureArray()) {
619
- g.config.enableContextMenu = enableContextMenu;
620
- }
621
- };
622
-
623
- const applyTouchActionProp = (
624
- touchAction: TouchAction,
625
- gesture: ComposedGesture | GestureType
626
- ): void => {
627
- for (const g of gesture.toGestureArray()) {
628
- g.config.touchAction = touchAction;
629
- }
630
- };
631
-
632
- interface GestureDetectorProps {
633
- /**
634
- * A gesture object containing the configuration and callbacks.
635
- * Can be any of:
636
- * - base gestures (`Tap`, `Pan`, ...)
637
- * - `ComposedGesture` (`Race`, `Simultaneous`, `Exclusive`)
638
- */
639
- gesture: ComposedGesture | GestureType;
640
- children?: React.ReactNode;
641
-
642
- /**
643
- * #### Web only
644
- * This parameter allows to specify which `userSelect` property should be applied to underlying view.
645
- * Possible values are `"none" | "auto" | "text"`. Default value is set to `"none"`.
646
- */
647
- userSelect?: UserSelect;
648
- /**
649
- * #### Web only
650
- * Specifies whether context menu should be enabled after clicking on underlying view with right mouse button.
651
- * Default value is set to `false`.
652
- */
653
- enableContextMenu?: boolean;
654
- /**
655
- * #### Web only
656
- * This parameter allows to specify which `touchAction` property should be applied to underlying view.
657
- * Supports all CSS touch-action values (e.g. `"none"`, `"pan-y"`). Default value is set to `"none"`.
658
- */
659
- touchAction?: TouchAction;
660
- }
661
- interface GestureDetectorState {
662
- firstRender: boolean;
663
- viewRef: React.Component | null;
664
- previousViewTag: number;
665
- forceReattach: boolean;
666
- }
667
-
668
- /**
669
- * `GestureDetector` is responsible for creating and updating native gesture handlers based on the config of provided gesture.
670
- *
671
- * ### Props
672
- * - `gesture`
673
- * - `userSelect` (**Web only**)
674
- * - `enableContextMenu` (**Web only**)
675
- * - `touchAction` (**Web only**)
676
- *
677
- * ### Remarks
678
- * - Gesture Detector will use first native view in its subtree to recognize gestures, however if this view is used only to group its children it may get automatically collapsed.
679
- * - Using the same instance of a gesture across multiple Gesture Detectors is not possible.
680
- *
681
- * @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/gesture-detector
682
- */
683
- export const GestureDetector = (props: GestureDetectorProps) => {
684
- const rootViewContext = useContext(GestureHandlerRootViewContext);
685
- if (__DEV__ && !rootViewContext && !isJestEnv() && Platform.OS !== 'web') {
686
- throw new Error(
687
- 'GestureDetector must be used as a descendant of GestureHandlerRootView. Otherwise the gestures will not be recognized. See https://docs.swmansion.com/react-native-gesture-handler/docs/installation for more details.'
688
- );
689
- }
690
-
691
- const gestureConfig = props.gesture;
692
-
693
- if (props.userSelect) {
694
- applyUserSelectProp(props.userSelect, gestureConfig);
695
- }
696
-
697
- if (props.enableContextMenu !== undefined) {
698
- applyEnableContextMenuProp(props.enableContextMenu, gestureConfig);
699
- }
700
-
701
- if (props.touchAction !== undefined) {
702
- applyTouchActionProp(props.touchAction, gestureConfig);
703
- }
704
-
705
- const gesture = gestureConfig.toGestureArray();
706
- const useReanimatedHook = gesture.some((g) => g.shouldUseReanimated);
707
-
708
- // store state in ref to prevent unnecessary renders
709
- const state = useRef<GestureDetectorState>({
710
- firstRender: true,
711
- viewRef: null,
712
- previousViewTag: -1,
713
- forceReattach: false,
714
- }).current;
715
- const mountedRef = useRef(false);
716
- const webEventHandlersRef = useRef<WebEventHandler>({
717
- onGestureHandlerEvent: (e: HandlerStateChangeEvent<unknown>) => {
718
- onGestureHandlerEvent(e.nativeEvent);
719
- },
720
- onGestureHandlerStateChange: isNewWebImplementationEnabled()
721
- ? (e: HandlerStateChangeEvent<unknown>) => {
722
- onGestureHandlerEvent(e.nativeEvent);
723
- }
724
- : undefined,
725
- });
726
-
727
- const [renderState, setRenderState] = useState(false);
728
- function forceRender() {
729
- setRenderState(!renderState);
730
- }
731
-
732
- const preparedGesture = React.useRef<GestureConfigReference>({
733
- config: gesture,
734
- animatedEventHandler: null,
735
- animatedHandlers: null,
736
- firstExecution: true,
737
- useReanimatedHook: useReanimatedHook,
738
- }).current;
739
-
740
- if (useReanimatedHook !== preparedGesture.useReanimatedHook) {
741
- throw new Error(
742
- tagMessage(
743
- 'You cannot change the thread the callbacks are ran on while the app is running'
744
- )
745
- );
746
- }
747
-
748
- function onHandlersUpdate(skipConfigUpdate?: boolean) {
749
- // if the underlying view has changed we need to reattach handlers to the new view
750
- const viewTag = findNodeHandle(state.viewRef) as number;
751
- const forceReattach = viewTag !== state.previousViewTag;
752
-
753
- if (forceReattach || needsToReattach(preparedGesture, gesture)) {
754
- validateDetectorChildren(state.viewRef);
755
- dropHandlers(preparedGesture);
756
- attachHandlers({
757
- preparedGesture,
758
- gestureConfig,
759
- gesture,
760
- webEventHandlersRef,
761
- viewTag,
762
- mountedRef,
763
- });
764
-
765
- state.previousViewTag = viewTag;
766
- state.forceReattach = forceReattach;
767
- if (forceReattach) {
768
- forceRender();
769
- }
770
- } else if (!skipConfigUpdate) {
771
- updateHandlers(preparedGesture, gestureConfig, gesture, mountedRef);
772
- }
773
- }
774
-
775
- // Reanimated event should be rebuilt only when gestures are reattached, otherwise
776
- // config update will be enough as all necessary items are stored in shared values anyway
777
- const needsToRebuildReanimatedEvent =
778
- preparedGesture.firstExecution ||
779
- needsToReattach(preparedGesture, gesture) ||
780
- state.forceReattach;
781
-
782
- state.forceReattach = false;
783
-
784
- if (preparedGesture.firstExecution) {
785
- gestureConfig.initialize();
786
- }
787
-
788
- if (useReanimatedHook) {
789
- // Whether animatedGesture or gesture is used shouldn't change while the app is running
790
- // eslint-disable-next-line react-hooks/rules-of-hooks
791
- useAnimatedGesture(preparedGesture, needsToRebuildReanimatedEvent);
792
- }
793
-
794
- useEffect(() => {
795
- const viewTag = findNodeHandle(state.viewRef) as number;
796
- state.firstRender = true;
797
- mountedRef.current = true;
798
-
799
- validateDetectorChildren(state.viewRef);
800
-
801
- attachHandlers({
802
- preparedGesture,
803
- gestureConfig,
804
- gesture,
805
- webEventHandlersRef,
806
- viewTag,
807
- mountedRef,
808
- });
809
-
810
- return () => {
811
- mountedRef.current = false;
812
- dropHandlers(preparedGesture);
813
- };
814
- }, []);
815
-
816
- useEffect(() => {
817
- if (!state.firstRender) {
818
- onHandlersUpdate();
819
- } else {
820
- state.firstRender = false;
821
- }
822
- }, [props]);
823
-
824
- const refFunction = (ref: unknown) => {
825
- if (ref !== null) {
826
- // @ts-ignore Just setting the view ref
827
- state.viewRef = ref;
828
-
829
- // if it's the first render, also set the previousViewTag to prevent reattaching gestures when not needed
830
- if (state.previousViewTag === -1) {
831
- state.previousViewTag = findNodeHandle(state.viewRef) as number;
832
- }
833
-
834
- // pass true as `skipConfigUpdate`, here we only want to trigger the eventual reattaching of handlers
835
- // in case the view has changed, while config update would be handled be the `useEffect` above
836
- onHandlersUpdate(true);
837
-
838
- if (isFabric() && global.isFormsStackingContext) {
839
- const node = getShadowNodeFromRef(ref);
840
- if (global.isFormsStackingContext(node) === false) {
841
- console.error(
842
- tagMessage(
843
- 'GestureDetector has received a child that may get view-flattened. ' +
844
- '\nTo prevent it from misbehaving you need to wrap the child with a `<View collapsable={false}>`.'
845
- )
846
- );
847
- }
848
- }
849
- }
850
- };
851
-
852
- if (useReanimatedHook) {
853
- return (
854
- <AnimatedWrap
855
- ref={refFunction}
856
- onGestureHandlerEvent={preparedGesture.animatedEventHandler}>
857
- {props.children}
858
- </AnimatedWrap>
859
- );
860
- } else {
861
- return <Wrap ref={refFunction}>{props.children}</Wrap>;
862
- }
863
- };
864
-
865
- class Wrap extends React.Component<{
866
- onGestureHandlerEvent?: unknown;
867
- // implicit `children` prop has been removed in @types/react^18.0.0
868
- children?: React.ReactNode;
869
- }> {
870
- render() {
871
- try {
872
- // I don't think that fighting with types over such a simple function is worth it
873
- // The only thing it does is add 'collapsable: false' to the child component
874
- // to make sure it is in the native view hierarchy so the detector can find
875
- // correct viewTag to attach to.
876
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
877
- const child: any = React.Children.only(this.props.children);
878
- return React.cloneElement(
879
- child,
880
- { collapsable: false },
881
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
882
- child.props.children
883
- );
884
- } catch (e) {
885
- throw new Error(
886
- tagMessage(
887
- `GestureDetector got more than one view as a child. If you want the gesture to work on multiple views, wrap them with a common parent and attach the gesture to that view.`
888
- )
889
- );
890
- }
891
- }
892
- }
893
-
894
- const AnimatedWrap = Reanimated?.default?.createAnimatedComponent(Wrap) ?? Wrap;