react-native-gesture-handler 2.32.0 → 2.33.1

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 (293) hide show
  1. package/android/build.gradle +27 -11
  2. package/android/gradle.properties +1 -1
  3. package/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerRootViewManagerDelegate.java +3 -0
  4. package/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerRootViewManagerInterface.java +2 -0
  5. package/android/src/main/java/com/swmansion/gesturehandler/core/FlingGestureHandler.kt +1 -1
  6. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +41 -36
  7. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +149 -23
  8. package/android/src/main/java/com/swmansion/gesturehandler/core/HoverGestureHandler.kt +1 -0
  9. package/android/src/main/java/com/swmansion/gesturehandler/core/LongPressGestureHandler.kt +6 -3
  10. package/android/src/main/java/com/swmansion/gesturehandler/core/NativeViewGestureHandler.kt +23 -0
  11. package/android/src/main/java/com/swmansion/gesturehandler/core/PanGestureHandler.kt +4 -7
  12. package/android/src/main/java/com/swmansion/gesturehandler/core/TapGestureHandler.kt +1 -1
  13. package/android/src/main/java/com/swmansion/gesturehandler/react/Extensions.kt +3 -0
  14. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +2 -0
  15. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt +11 -1
  16. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootView.kt +8 -6
  17. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootViewManager.kt +6 -0
  18. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerTouchEvent.kt +2 -7
  19. package/apple/Handlers/RNFlingHandler.m +44 -4
  20. package/apple/Handlers/RNHoverHandler.m +24 -26
  21. package/apple/Handlers/RNLongPressHandler.m +4 -0
  22. package/apple/Handlers/RNPanHandler.m +44 -7
  23. package/apple/Handlers/RNTapHandler.m +35 -4
  24. package/apple/RNGHUIKit.h +10 -10
  25. package/apple/RNGestureHandler.h +2 -0
  26. package/apple/RNGestureHandler.mm +62 -9
  27. package/apple/RNGestureHandlerButton.mm +5 -3
  28. package/apple/RNGestureHandlerButtonComponentView.mm +6 -0
  29. package/apple/RNGestureHandlerManager.mm +63 -6
  30. package/apple/RNGestureHandlerModule.mm +20 -0
  31. package/apple/RNGestureHandlerPointerTracker.m +64 -10
  32. package/apple/RNGestureHandlerPointerType.h +1 -0
  33. package/apple/RNManualActivationRecognizer.m +25 -6
  34. package/lib/commonjs/components/GestureComponents.js +21 -1
  35. package/lib/commonjs/components/GestureComponents.js.map +1 -1
  36. package/lib/commonjs/components/GestureHandlerButton.web.js +2 -1
  37. package/lib/commonjs/components/GestureHandlerButton.web.js.map +1 -1
  38. package/lib/commonjs/components/Pressable/Pressable.js +28 -3
  39. package/lib/commonjs/components/Pressable/Pressable.js.map +1 -1
  40. package/lib/commonjs/components/Pressable/index.js.map +1 -1
  41. package/lib/commonjs/components/ReanimatedDrawerLayout.js +4 -2
  42. package/lib/commonjs/components/ReanimatedDrawerLayout.js.map +1 -1
  43. package/lib/commonjs/components/ReanimatedSwipeable/ReanimatedSwipeable.js +32 -9
  44. package/lib/commonjs/components/ReanimatedSwipeable/ReanimatedSwipeable.js.map +1 -1
  45. package/lib/commonjs/components/Swipeable.js.map +1 -1
  46. package/lib/commonjs/components/Text.js.map +1 -1
  47. package/lib/commonjs/components/touchables/TouchableHighlight.js +1 -1
  48. package/lib/commonjs/components/touchables/TouchableHighlight.js.map +1 -1
  49. package/lib/commonjs/components/touchables/TouchableNativeFeedback.android.js.map +1 -1
  50. package/lib/commonjs/components/touchables/TouchableOpacity.js +1 -0
  51. package/lib/commonjs/components/touchables/TouchableOpacity.js.map +1 -1
  52. package/lib/commonjs/getShadowNodeFromRef.js +6 -2
  53. package/lib/commonjs/getShadowNodeFromRef.js.map +1 -1
  54. package/lib/commonjs/handlers/PanGestureHandler.js.map +1 -1
  55. package/lib/commonjs/handlers/createHandler.js +1 -1
  56. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  57. package/lib/commonjs/handlers/gestures/GestureDetector/Wrap.js +66 -11
  58. package/lib/commonjs/handlers/gestures/GestureDetector/Wrap.js.map +1 -1
  59. package/lib/commonjs/handlers/gestures/GestureDetector/attachHandlers.js +8 -1
  60. package/lib/commonjs/handlers/gestures/GestureDetector/attachHandlers.js.map +1 -1
  61. package/lib/commonjs/handlers/gestures/GestureDetector/index.js +7 -2
  62. package/lib/commonjs/handlers/gestures/GestureDetector/index.js.map +1 -1
  63. package/lib/commonjs/handlers/gestures/GestureDetector/updateHandlers.js +7 -0
  64. package/lib/commonjs/handlers/gestures/GestureDetector/updateHandlers.js.map +1 -1
  65. package/lib/commonjs/handlers/gestures/GestureDetector/useDetectorUpdater.js +2 -1
  66. package/lib/commonjs/handlers/gestures/GestureDetector/useDetectorUpdater.js.map +1 -1
  67. package/lib/commonjs/handlers/gestures/GestureDetector/useMountReactions.js +28 -3
  68. package/lib/commonjs/handlers/gestures/GestureDetector/useMountReactions.js.map +1 -1
  69. package/lib/commonjs/handlers/gestures/GestureDetector/useViewRefHandler.js +3 -2
  70. package/lib/commonjs/handlers/gestures/GestureDetector/useViewRefHandler.js.map +1 -1
  71. package/lib/commonjs/handlers/gestures/GestureDetector/utils.js +35 -6
  72. package/lib/commonjs/handlers/gestures/GestureDetector/utils.js.map +1 -1
  73. package/lib/commonjs/handlers/gestures/gesture.js +8 -0
  74. package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
  75. package/lib/commonjs/handlers/gestures/gestureComposition.js +14 -2
  76. package/lib/commonjs/handlers/gestures/gestureComposition.js.map +1 -1
  77. package/lib/commonjs/handlers/gestures/gestureStateManager.web.js.map +1 -1
  78. package/lib/commonjs/handlers/gestures/panGesture.js +6 -3
  79. package/lib/commonjs/handlers/gestures/panGesture.js.map +1 -1
  80. package/lib/commonjs/handlers/gestures/reanimatedWrapper.js +23 -0
  81. package/lib/commonjs/handlers/gestures/reanimatedWrapper.js.map +1 -1
  82. package/lib/commonjs/hostInstance.js +39 -0
  83. package/lib/commonjs/hostInstance.js.map +1 -0
  84. package/lib/commonjs/index.js.map +1 -1
  85. package/lib/commonjs/mocks/mocks.js +1 -0
  86. package/lib/commonjs/mocks/mocks.js.map +1 -1
  87. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -1
  88. package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.ts +16 -14
  89. package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.ts +13 -4
  90. package/lib/commonjs/web/detectors/RotationGestureDetector.js +1 -1
  91. package/lib/commonjs/web/handlers/LongPressGestureHandler.js +3 -1
  92. package/lib/commonjs/web/handlers/LongPressGestureHandler.js.map +1 -1
  93. package/lib/commonjs/web/handlers/NativeViewGestureHandler.js +9 -1
  94. package/lib/commonjs/web/handlers/NativeViewGestureHandler.js.map +1 -1
  95. package/lib/commonjs/web/handlers/PanGestureHandler.js +8 -9
  96. package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
  97. package/lib/commonjs/web/handlers/TapGestureHandler.js +1 -1
  98. package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js +14 -0
  99. package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js.map +1 -1
  100. package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js +5 -1
  101. package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js.map +1 -1
  102. package/lib/commonjs/web/tools/KeyboardEventManager.js +17 -12
  103. package/lib/commonjs/web/tools/KeyboardEventManager.js.map +1 -1
  104. package/lib/commonjs/web/tools/WheelEventManager.js +19 -5
  105. package/lib/commonjs/web/tools/WheelEventManager.js.map +1 -1
  106. package/lib/module/components/GestureComponents.js +23 -2
  107. package/lib/module/components/GestureComponents.js.map +1 -1
  108. package/lib/module/components/GestureHandlerButton.web.js +2 -1
  109. package/lib/module/components/GestureHandlerButton.web.js.map +1 -1
  110. package/lib/module/components/Pressable/Pressable.js +28 -3
  111. package/lib/module/components/Pressable/Pressable.js.map +1 -1
  112. package/lib/module/components/Pressable/index.js.map +1 -1
  113. package/lib/module/components/ReanimatedDrawerLayout.js +4 -2
  114. package/lib/module/components/ReanimatedDrawerLayout.js.map +1 -1
  115. package/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeable.js +34 -11
  116. package/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeable.js.map +1 -1
  117. package/lib/module/components/Swipeable.js.map +1 -1
  118. package/lib/module/components/Text.js.map +1 -1
  119. package/lib/module/components/touchables/TouchableHighlight.js +2 -2
  120. package/lib/module/components/touchables/TouchableHighlight.js.map +1 -1
  121. package/lib/module/components/touchables/TouchableNativeFeedback.android.js.map +1 -1
  122. package/lib/module/components/touchables/TouchableOpacity.js +1 -0
  123. package/lib/module/components/touchables/TouchableOpacity.js.map +1 -1
  124. package/lib/module/getShadowNodeFromRef.js +7 -2
  125. package/lib/module/getShadowNodeFromRef.js.map +1 -1
  126. package/lib/module/handlers/PanGestureHandler.js.map +1 -1
  127. package/lib/module/handlers/createHandler.js +1 -1
  128. package/lib/module/handlers/createHandler.js.map +1 -1
  129. package/lib/module/handlers/gestures/GestureDetector/Wrap.js +67 -12
  130. package/lib/module/handlers/gestures/GestureDetector/Wrap.js.map +1 -1
  131. package/lib/module/handlers/gestures/GestureDetector/attachHandlers.js +9 -2
  132. package/lib/module/handlers/gestures/GestureDetector/attachHandlers.js.map +1 -1
  133. package/lib/module/handlers/gestures/GestureDetector/index.js +7 -2
  134. package/lib/module/handlers/gestures/GestureDetector/index.js.map +1 -1
  135. package/lib/module/handlers/gestures/GestureDetector/updateHandlers.js +8 -1
  136. package/lib/module/handlers/gestures/GestureDetector/updateHandlers.js.map +1 -1
  137. package/lib/module/handlers/gestures/GestureDetector/useDetectorUpdater.js +2 -1
  138. package/lib/module/handlers/gestures/GestureDetector/useDetectorUpdater.js.map +1 -1
  139. package/lib/module/handlers/gestures/GestureDetector/useMountReactions.js +28 -3
  140. package/lib/module/handlers/gestures/GestureDetector/useMountReactions.js.map +1 -1
  141. package/lib/module/handlers/gestures/GestureDetector/useViewRefHandler.js +3 -2
  142. package/lib/module/handlers/gestures/GestureDetector/useViewRefHandler.js.map +1 -1
  143. package/lib/module/handlers/gestures/GestureDetector/utils.js +34 -6
  144. package/lib/module/handlers/gestures/GestureDetector/utils.js.map +1 -1
  145. package/lib/module/handlers/gestures/gesture.js +8 -0
  146. package/lib/module/handlers/gestures/gesture.js.map +1 -1
  147. package/lib/module/handlers/gestures/gestureComposition.js +14 -2
  148. package/lib/module/handlers/gestures/gestureComposition.js.map +1 -1
  149. package/lib/module/handlers/gestures/gestureStateManager.web.js.map +1 -1
  150. package/lib/module/handlers/gestures/panGesture.js +6 -3
  151. package/lib/module/handlers/gestures/panGesture.js.map +1 -1
  152. package/lib/module/handlers/gestures/reanimatedWrapper.js +22 -0
  153. package/lib/module/handlers/gestures/reanimatedWrapper.js.map +1 -1
  154. package/lib/module/hostInstance.js +32 -0
  155. package/lib/module/hostInstance.js.map +1 -0
  156. package/lib/module/index.js.map +1 -1
  157. package/lib/module/mocks/mocks.js +3 -2
  158. package/lib/module/mocks/mocks.js.map +1 -1
  159. package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -1
  160. package/lib/module/specs/RNGestureHandlerButtonNativeComponent.ts +16 -14
  161. package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.ts +13 -4
  162. package/lib/module/web/detectors/RotationGestureDetector.js +1 -1
  163. package/lib/module/web/handlers/LongPressGestureHandler.js +3 -1
  164. package/lib/module/web/handlers/LongPressGestureHandler.js.map +1 -1
  165. package/lib/module/web/handlers/NativeViewGestureHandler.js +9 -1
  166. package/lib/module/web/handlers/NativeViewGestureHandler.js.map +1 -1
  167. package/lib/module/web/handlers/PanGestureHandler.js +8 -9
  168. package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
  169. package/lib/module/web/handlers/TapGestureHandler.js +1 -1
  170. package/lib/module/web/tools/GestureHandlerOrchestrator.js +14 -0
  171. package/lib/module/web/tools/GestureHandlerOrchestrator.js.map +1 -1
  172. package/lib/module/web/tools/GestureHandlerWebDelegate.js +5 -1
  173. package/lib/module/web/tools/GestureHandlerWebDelegate.js.map +1 -1
  174. package/lib/module/web/tools/KeyboardEventManager.js +17 -12
  175. package/lib/module/web/tools/KeyboardEventManager.js.map +1 -1
  176. package/lib/module/web/tools/WheelEventManager.js +19 -5
  177. package/lib/module/web/tools/WheelEventManager.js.map +1 -1
  178. package/lib/typescript/components/GestureButtons.d.ts +3 -1
  179. package/lib/typescript/components/GestureButtons.d.ts.map +1 -1
  180. package/lib/typescript/components/GestureButtonsProps.d.ts +10 -0
  181. package/lib/typescript/components/GestureButtonsProps.d.ts.map +1 -1
  182. package/lib/typescript/components/GestureComponents.d.ts +8 -7
  183. package/lib/typescript/components/GestureComponents.d.ts.map +1 -1
  184. package/lib/typescript/components/GestureComponents.web.d.ts +12 -4
  185. package/lib/typescript/components/GestureComponents.web.d.ts.map +1 -1
  186. package/lib/typescript/components/GestureHandlerButton.web.d.ts +2 -2
  187. package/lib/typescript/components/GestureHandlerButton.web.d.ts.map +1 -1
  188. package/lib/typescript/components/Pressable/Pressable.d.ts.map +1 -1
  189. package/lib/typescript/components/Pressable/PressableProps.d.ts +1 -1
  190. package/lib/typescript/components/Pressable/PressableProps.d.ts.map +1 -1
  191. package/lib/typescript/components/Pressable/index.d.ts +1 -1
  192. package/lib/typescript/components/Pressable/index.d.ts.map +1 -1
  193. package/lib/typescript/components/ReanimatedDrawerLayout.d.ts.map +1 -1
  194. package/lib/typescript/components/ReanimatedSwipeable/ReanimatedSwipeable.d.ts.map +1 -1
  195. package/lib/typescript/components/Swipeable.d.ts.map +1 -1
  196. package/lib/typescript/components/touchables/TouchableHighlight.d.ts +1 -1
  197. package/lib/typescript/components/touchables/TouchableHighlight.d.ts.map +1 -1
  198. package/lib/typescript/components/touchables/TouchableNativeFeedback.android.d.ts +1 -1
  199. package/lib/typescript/components/touchables/TouchableNativeFeedback.android.d.ts.map +1 -1
  200. package/lib/typescript/components/touchables/TouchableOpacity.d.ts.map +1 -1
  201. package/lib/typescript/getShadowNodeFromRef.d.ts.map +1 -1
  202. package/lib/typescript/handlers/PanGestureHandler.d.ts +12 -0
  203. package/lib/typescript/handlers/PanGestureHandler.d.ts.map +1 -1
  204. package/lib/typescript/handlers/createHandler.d.ts.map +1 -1
  205. package/lib/typescript/handlers/gestures/GestureDetector/Wrap.d.ts +12 -0
  206. package/lib/typescript/handlers/gestures/GestureDetector/Wrap.d.ts.map +1 -1
  207. package/lib/typescript/handlers/gestures/GestureDetector/attachHandlers.d.ts.map +1 -1
  208. package/lib/typescript/handlers/gestures/GestureDetector/index.d.ts.map +1 -1
  209. package/lib/typescript/handlers/gestures/GestureDetector/types.d.ts +1 -0
  210. package/lib/typescript/handlers/gestures/GestureDetector/types.d.ts.map +1 -1
  211. package/lib/typescript/handlers/gestures/GestureDetector/updateHandlers.d.ts.map +1 -1
  212. package/lib/typescript/handlers/gestures/GestureDetector/useDetectorUpdater.d.ts.map +1 -1
  213. package/lib/typescript/handlers/gestures/GestureDetector/useMountReactions.d.ts.map +1 -1
  214. package/lib/typescript/handlers/gestures/GestureDetector/useViewRefHandler.d.ts.map +1 -1
  215. package/lib/typescript/handlers/gestures/GestureDetector/utils.d.ts +5 -4
  216. package/lib/typescript/handlers/gestures/GestureDetector/utils.d.ts.map +1 -1
  217. package/lib/typescript/handlers/gestures/gesture.d.ts +4 -0
  218. package/lib/typescript/handlers/gestures/gesture.d.ts.map +1 -1
  219. package/lib/typescript/handlers/gestures/gestureComposition.d.ts.map +1 -1
  220. package/lib/typescript/handlers/gestures/gestureStateManager.web.d.ts +8 -1
  221. package/lib/typescript/handlers/gestures/gestureStateManager.web.d.ts.map +1 -1
  222. package/lib/typescript/handlers/gestures/panGesture.d.ts +6 -3
  223. package/lib/typescript/handlers/gestures/panGesture.d.ts.map +1 -1
  224. package/lib/typescript/handlers/gestures/reanimatedWrapper.d.ts +1 -0
  225. package/lib/typescript/handlers/gestures/reanimatedWrapper.d.ts.map +1 -1
  226. package/lib/typescript/hostInstance.d.ts +10 -0
  227. package/lib/typescript/hostInstance.d.ts.map +1 -0
  228. package/lib/typescript/index.d.ts +1 -1
  229. package/lib/typescript/index.d.ts.map +1 -1
  230. package/lib/typescript/mocks/mocks.d.ts +67 -15
  231. package/lib/typescript/mocks/mocks.d.ts.map +1 -1
  232. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +6 -7
  233. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts.map +1 -1
  234. package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +9 -10
  235. package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts.map +1 -1
  236. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +2 -2
  237. package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts.map +1 -1
  238. package/lib/typescript/web/handlers/LongPressGestureHandler.d.ts.map +1 -1
  239. package/lib/typescript/web/handlers/NativeViewGestureHandler.d.ts +1 -0
  240. package/lib/typescript/web/handlers/NativeViewGestureHandler.d.ts.map +1 -1
  241. package/lib/typescript/web/handlers/PanGestureHandler.d.ts.map +1 -1
  242. package/lib/typescript/web/tools/GestureHandlerOrchestrator.d.ts +1 -0
  243. package/lib/typescript/web/tools/GestureHandlerOrchestrator.d.ts.map +1 -1
  244. package/lib/typescript/web/tools/GestureHandlerWebDelegate.d.ts.map +1 -1
  245. package/lib/typescript/web/tools/KeyboardEventManager.d.ts +2 -1
  246. package/lib/typescript/web/tools/KeyboardEventManager.d.ts.map +1 -1
  247. package/lib/typescript/web/tools/WheelEventManager.d.ts.map +1 -1
  248. package/package.json +7 -7
  249. package/src/components/GestureButtonsProps.ts +14 -0
  250. package/src/components/GestureComponents.tsx +38 -7
  251. package/src/components/GestureHandlerButton.web.tsx +7 -3
  252. package/src/components/Pressable/Pressable.tsx +33 -4
  253. package/src/components/Pressable/PressableProps.tsx +1 -1
  254. package/src/components/Pressable/index.ts +1 -0
  255. package/src/components/ReanimatedDrawerLayout.tsx +4 -1
  256. package/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx +49 -10
  257. package/src/components/Swipeable.tsx +6 -2
  258. package/src/components/Text.tsx +3 -3
  259. package/src/components/touchables/TouchableHighlight.tsx +4 -2
  260. package/src/components/touchables/TouchableNativeFeedback.android.tsx +8 -2
  261. package/src/components/touchables/TouchableOpacity.tsx +1 -0
  262. package/src/getShadowNodeFromRef.ts +11 -4
  263. package/src/handlers/PanGestureHandler.ts +15 -0
  264. package/src/handlers/createHandler.tsx +4 -1
  265. package/src/handlers/gestures/GestureDetector/Wrap.tsx +95 -14
  266. package/src/handlers/gestures/GestureDetector/attachHandlers.ts +11 -2
  267. package/src/handlers/gestures/GestureDetector/index.tsx +8 -1
  268. package/src/handlers/gestures/GestureDetector/types.ts +3 -0
  269. package/src/handlers/gestures/GestureDetector/updateHandlers.ts +8 -0
  270. package/src/handlers/gestures/GestureDetector/useDetectorUpdater.ts +4 -1
  271. package/src/handlers/gestures/GestureDetector/useMountReactions.ts +35 -4
  272. package/src/handlers/gestures/GestureDetector/useViewRefHandler.ts +5 -2
  273. package/src/handlers/gestures/GestureDetector/utils.ts +42 -10
  274. package/src/handlers/gestures/gesture.ts +11 -0
  275. package/src/handlers/gestures/gestureComposition.ts +15 -2
  276. package/src/handlers/gestures/gestureStateManager.web.ts +9 -1
  277. package/src/handlers/gestures/panGesture.ts +6 -3
  278. package/src/handlers/gestures/reanimatedWrapper.ts +23 -0
  279. package/src/hostInstance.ts +57 -0
  280. package/src/index.ts +1 -0
  281. package/src/mocks/mocks.tsx +6 -2
  282. package/src/specs/NativeRNGestureHandlerModule.ts +16 -10
  283. package/src/specs/RNGestureHandlerButtonNativeComponent.ts +16 -14
  284. package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +13 -4
  285. package/src/web/detectors/RotationGestureDetector.ts +1 -1
  286. package/src/web/handlers/LongPressGestureHandler.ts +3 -1
  287. package/src/web/handlers/NativeViewGestureHandler.ts +11 -2
  288. package/src/web/handlers/PanGestureHandler.ts +8 -11
  289. package/src/web/handlers/TapGestureHandler.ts +1 -1
  290. package/src/web/tools/GestureHandlerOrchestrator.ts +19 -0
  291. package/src/web/tools/GestureHandlerWebDelegate.ts +6 -1
  292. package/src/web/tools/KeyboardEventManager.ts +20 -18
  293. package/src/web/tools/WheelEventManager.ts +15 -5
@@ -1,5 +1,15 @@
1
1
  import React from 'react';
2
- import { Reanimated } from '../reanimatedWrapper';
2
+ import type { WrapRef } from '../../../hostInstance';
3
+ import {
4
+ assignRef,
5
+ isHostInstance,
6
+ preferHostInstance,
7
+ resolveHostInstance,
8
+ } from '../../../hostInstance';
9
+ import {
10
+ Reanimated,
11
+ reanimatedRefreshesAnimatableRef,
12
+ } from '../reanimatedWrapper';
3
13
  import { tagMessage } from '../../../utils';
4
14
 
5
15
  export class Wrap extends React.Component<{
@@ -7,20 +17,81 @@ export class Wrap extends React.Component<{
7
17
  // Implicit `children` prop has been removed in @types/react^18.0.0
8
18
  children?: React.ReactNode;
9
19
  }> {
10
- render() {
20
+ private childInstance: unknown = null;
21
+ private hostInstance: unknown = null;
22
+ private childRef: WrapRef = undefined;
23
+ private attachedChildRef: WrapRef = undefined;
24
+ private childRefCleanup: (() => void) | undefined = undefined;
25
+
26
+ // eslint-disable-next-line @eslint-react/no-unused-class-component-members
27
+ public getHostInstance() {
28
+ return this.hostInstance;
29
+ }
30
+
31
+ // Used by Reanimated's `createAnimatedComponent` (`AnimatedWrap`). Without it,
32
+ // Reanimated calls `findHostInstance_DEPRECATED` on this class instance, which
33
+ // warns under StrictMode. Reanimated caches the result, so the child's host
34
+ // instance is only safe to hand out when it re-resolves the ref on update;
35
+ // otherwise return the instance itself, which keeps the deprecated lookup.
36
+ // eslint-disable-next-line @eslint-react/no-unused-class-component-members
37
+ public getAnimatableRef() {
38
+ return reanimatedRefreshesAnimatableRef()
39
+ ? resolveHostInstance(this)
40
+ : this;
41
+ }
42
+
43
+ private detachChildRef() {
44
+ if (this.childRefCleanup !== undefined) {
45
+ this.childRefCleanup();
46
+ } else if (this.attachedChildRef) {
47
+ assignRef(this.attachedChildRef, null);
48
+ }
49
+
50
+ this.childRefCleanup = undefined;
51
+ this.attachedChildRef = undefined;
52
+ }
53
+
54
+ private attachChildRef(instance: unknown) {
55
+ this.attachedChildRef = this.childRef;
56
+
57
+ this.childRefCleanup = assignRef(this.attachedChildRef, instance);
58
+ }
59
+
60
+ private handleChildRef = (instance: unknown) => {
61
+ this.childInstance = instance;
62
+
63
+ const resolved = preferHostInstance(instance);
64
+ this.hostInstance = isHostInstance(resolved) ? resolved : null;
65
+
66
+ this.detachChildRef();
67
+
68
+ if (instance !== null && instance !== undefined) {
69
+ this.attachChildRef(instance);
70
+ }
71
+ };
72
+
73
+ override componentDidUpdate() {
74
+ if (
75
+ this.childRef === this.attachedChildRef ||
76
+ this.childInstance === null
77
+ ) {
78
+ return;
79
+ }
80
+
81
+ this.detachChildRef();
82
+ this.attachChildRef(this.childInstance);
83
+ }
84
+
85
+ override render() {
86
+ // I don't think that fighting with types over such a simple function is worth it
87
+ // The only thing it does is add 'collapsable: false' to the child component
88
+ // to make sure it is in the native view hierarchy so the detector can find
89
+ // correct viewTag to attach to.
90
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
+ let child: any;
92
+
11
93
  try {
12
- // I don't think that fighting with types over such a simple function is worth it
13
- // The only thing it does is add 'collapsable: false' to the child component
14
- // to make sure it is in the native view hierarchy so the detector can find
15
- // correct viewTag to attach to.
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
- const child: any = React.Children.only(this.props.children);
18
- return React.cloneElement(
19
- child,
20
- { collapsable: false },
21
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
22
- child.props.children
23
- );
94
+ child = React.Children.only(this.props.children);
24
95
  } catch (e) {
25
96
  throw new Error(
26
97
  tagMessage(
@@ -28,6 +99,16 @@ export class Wrap extends React.Component<{
28
99
  )
29
100
  );
30
101
  }
102
+
103
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
104
+ this.childRef = child.props.ref as WrapRef;
105
+
106
+ return React.cloneElement(
107
+ child,
108
+ { collapsable: false, ref: this.handleChildRef },
109
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
110
+ child.props.children
111
+ );
31
112
  }
32
113
  }
33
114
 
@@ -13,6 +13,7 @@ import {
13
13
  extractGestureRelations,
14
14
  checkGestureCallbacksForWorklets,
15
15
  ALLOWED_PROPS,
16
+ hasExternalRelations,
16
17
  } from './utils';
17
18
  import { MountRegistry } from '../../../mountRegistry';
18
19
 
@@ -53,6 +54,9 @@ export function attachHandlers({
53
54
  registerHandler(handler.handlerTag, handler, handler.config.testId);
54
55
  }
55
56
 
57
+ // React to every mount until the microtask below classifies the new gesture set
58
+ preparedGesture.hasExternalRelations = true;
59
+
56
60
  // Use queueMicrotask to extract handlerTags, because all refs should be initialized
57
61
  // when it's ran
58
62
  ghQueueMicrotask(() => {
@@ -70,9 +74,16 @@ export function attachHandlers({
70
74
  );
71
75
  }
72
76
 
77
+ preparedGesture.hasExternalRelations =
78
+ hasExternalRelations(gesturesToAttach);
79
+
73
80
  scheduleFlushOperations();
74
81
  });
75
82
 
83
+ // Set before the mount events below fire, so this detector's own mount
84
+ // listener can tell its gestures apart from external ones
85
+ preparedGesture.attachedGestures = gesturesToAttach;
86
+
76
87
  for (const gesture of gesturesToAttach) {
77
88
  const actionType = gesture.shouldUseReanimated
78
89
  ? ActionType.REANIMATED_WORKLET
@@ -98,8 +109,6 @@ export function attachHandlers({
98
109
  MountRegistry.gestureWillMount(gesture);
99
110
  }
100
111
 
101
- preparedGesture.attachedGestures = gesturesToAttach;
102
-
103
112
  if (preparedGesture.animatedHandlers) {
104
113
  const isAnimatedGesture = (g: GestureType) => g.shouldUseReanimated;
105
114
 
@@ -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';
@@ -126,6 +127,10 @@ export const GestureDetector = (props: GestureDetectorProps) => {
126
127
  animatedHandlers: null,
127
128
  shouldUseReanimated: shouldUseReanimated,
128
129
  isMounted: false,
130
+ // The real value is computed in the attach microtask, which runs after
131
+ // this commit's effects. Until then react to every mount, so a relation
132
+ // to a gesture mounting in the same commit is never skipped.
133
+ hasExternalRelations: true,
129
134
  }).current;
130
135
 
131
136
  const updateAttachedGestures = useDetectorUpdater(
@@ -149,7 +154,9 @@ export const GestureDetector = (props: GestureDetectorProps) => {
149
154
  useAnimatedGesture(preparedGesture, needsToRebuildReanimatedEvent);
150
155
 
151
156
  useIsomorphicLayoutEffect(() => {
152
- const viewTag = findNodeHandle(state.viewRef) as number;
157
+ const viewTag = findNodeHandle(
158
+ resolveHostInstance(state.viewRef)
159
+ ) as number;
153
160
  preparedGesture.isMounted = true;
154
161
 
155
162
  attachHandlers({
@@ -15,6 +15,9 @@ export interface AttachedGestureState {
15
15
  shouldUseReanimated: boolean;
16
16
  // Whether the GestureDetector is mounted
17
17
  isMounted: boolean;
18
+ // Whether any attached gesture has a relation to a gesture outside this
19
+ // detector (a ref or a gesture object), which may resolve on a later mount
20
+ hasExternalRelations: boolean;
18
21
  }
19
22
 
20
23
  export interface GestureDetectorState {
@@ -9,6 +9,7 @@ import {
9
9
  extractGestureRelations,
10
10
  checkGestureCallbacksForWorklets,
11
11
  ALLOWED_PROPS,
12
+ hasExternalRelations,
12
13
  } from './utils';
13
14
 
14
15
  export function updateHandlers(
@@ -33,6 +34,9 @@ export function updateHandlers(
33
34
  // Store attached gestures to avoid crash when gestures changed after queueing micro task
34
35
  const attachedGestures = preparedGesture.attachedGestures;
35
36
 
37
+ // React to every mount until the microtask below classifies the new gesture set
38
+ preparedGesture.hasExternalRelations = true;
39
+
36
40
  // Use queueMicrotask to extract handlerTags, because when it's ran, all refs should be updated
37
41
  // and handlerTags in BaseGesture references should be updated in the loop above (we need to wait
38
42
  // in case of external relations)
@@ -77,6 +81,10 @@ export function updateHandlers(
77
81
  registerHandler(handler.handlerTag, handler, handler.config.testId);
78
82
  }
79
83
 
84
+ // Classify the new instances: their configs reference the new siblings,
85
+ // which the old attached objects would mistake for external gestures
86
+ preparedGesture.hasExternalRelations = hasExternalRelations(newGestures);
87
+
80
88
  if (preparedGesture.animatedHandlers && shouldUpdateSharedValueIfUsed) {
81
89
  const newHandlersValue = attachedGestures
82
90
  .filter((g) => g.shouldUseReanimated) // Ignore gestures that shouldn't run on UI
@@ -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 (
@@ -1,19 +1,33 @@
1
- import { transformIntoHandlerTags } from '../../utils';
1
+ import type { GestureMountListener } from '../../../mountRegistry';
2
2
  import { MountRegistry } from '../../../mountRegistry';
3
3
  import { AttachedGestureState } from './types';
4
4
  import { useEffect } from 'react';
5
5
  import { GestureRef } from '../gesture';
6
6
 
7
+ type MountedGesture = Parameters<GestureMountListener>[0];
8
+
7
9
  function shouldUpdateDetector(
8
10
  relation: GestureRef[] | undefined,
9
- gesture: { handlerTag: number }
11
+ gesture: MountedGesture
10
12
  ) {
11
13
  if (relation === undefined) {
12
14
  return false;
13
15
  }
14
16
 
15
- for (const tag of transformIntoHandlerTags(relation)) {
16
- if (tag === gesture.handlerTag) {
17
+ for (const entry of relation) {
18
+ // A gesture object gets its tag in `initialize`, when its own detector
19
+ // attaches. The mount event carries that very object, so identity is enough.
20
+ if (entry === gesture) {
21
+ return true;
22
+ }
23
+
24
+ if (entry === null || typeof entry !== 'object' || !('current' in entry)) {
25
+ continue;
26
+ }
27
+
28
+ const current = entry.current as { handlerTag?: number } | null | undefined;
29
+
30
+ if (current?.handlerTag === gesture.handlerTag) {
17
31
  return true;
18
32
  }
19
33
  }
@@ -27,6 +41,23 @@ export function useMountReactions(
27
41
  ) {
28
42
  useEffect(() => {
29
43
  return MountRegistry.addMountListener((gesture) => {
44
+ // The detector may already be unmounted when this fires; bail out to avoid
45
+ // updating a detached detector.
46
+ if (!state.isMounted) {
47
+ return;
48
+ }
49
+
50
+ // Nothing here can resolve late, skip the scan (most detectors)
51
+ if (!state.hasExternalRelations) {
52
+ return;
53
+ }
54
+
55
+ // Own gestures are resolved by the attach microtask, and on a reattach
56
+ // they would match the sibling entries added by composition
57
+ if (state.attachedGestures.includes(gesture as never)) {
58
+ return;
59
+ }
60
+
30
61
  // At this point the ref in the gesture config should be updated, so we can check if one of the gestures
31
62
  // set in a relation with the gesture got mounted. If so, we need to update the detector to propagate
32
63
  // 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(
@@ -64,21 +64,53 @@ function extractValidHandlerTags(interactionGroup: GestureRef[] | undefined) {
64
64
  );
65
65
  }
66
66
 
67
+ // Relations that may resolve to a different handler after this detector attached:
68
+ // refs (filled when the target mounts) and gesture objects attached by another
69
+ // detector (they get a tag in `initialize`). Siblings added by composition are
70
+ // attached together with the gesture, so they never resolve late.
71
+ export function hasExternalRelations(gestures: GestureType[]) {
72
+ const ownGestures = new Set(gestures);
73
+
74
+ for (const gesture of gestures) {
75
+ const relations = [
76
+ gesture.config.blocksHandlers,
77
+ gesture.config.requireToFail,
78
+ gesture.config.simultaneousWith,
79
+ ];
80
+
81
+ for (const relation of relations) {
82
+ if (relation === undefined) {
83
+ continue;
84
+ }
85
+
86
+ for (const entry of relation) {
87
+ if (typeof entry === 'number') {
88
+ continue;
89
+ }
90
+
91
+ // Anything but our own gesture object is external: a ref, or a gesture
92
+ // attached by another detector
93
+ if (!(entry instanceof BaseGesture) || !ownGestures.has(entry)) {
94
+ return true;
95
+ }
96
+ }
97
+ }
98
+ }
99
+
100
+ return false;
101
+ }
102
+
67
103
  export function extractGestureRelations(gesture: GestureType) {
68
- gesture.config.requireToFail = extractValidHandlerTags(
69
- gesture.config.requireToFail
70
- );
71
- gesture.config.simultaneousWith = extractValidHandlerTags(
104
+ const requireToFail = extractValidHandlerTags(gesture.config.requireToFail);
105
+ const simultaneousWith = extractValidHandlerTags(
72
106
  gesture.config.simultaneousWith
73
107
  );
74
- gesture.config.blocksHandlers = extractValidHandlerTags(
75
- gesture.config.blocksHandlers
76
- );
108
+ const blocksHandlers = extractValidHandlerTags(gesture.config.blocksHandlers);
77
109
 
78
110
  return {
79
- waitFor: gesture.config.requireToFail,
80
- simultaneousHandlers: gesture.config.simultaneousWith,
81
- blocksHandlers: gesture.config.blocksHandlers,
111
+ waitFor: requireToFail,
112
+ simultaneousHandlers: simultaneousWith,
113
+ blocksHandlers: blocksHandlers,
82
114
  };
83
115
  }
84
116
 
@@ -131,6 +131,17 @@ export abstract class BaseGesture<
131
131
  public handlerTag = -1;
132
132
  public handlerName = '';
133
133
  public config: BaseGestureConfig = {};
134
+ // Snapshot of the relations defined directly on this gesture (e.g. via
135
+ // `simultaneousWithExternalGesture`), captured before any composition extends
136
+ // them. Composition rebuilds the relation config from this snapshot on every
137
+ // `prepare`, so repeated renders don't accumulate references to gestures from
138
+ // previous renders (memory leak, see #3763), while keeping the original
139
+ // references so relations stay re-resolvable after a remount, such as a
140
+ // `react-freeze` unfreeze (see #4238).
141
+ public relationsSnapshot?: {
142
+ simultaneousWith: GestureRef[] | undefined;
143
+ requireToFail: GestureRef[] | undefined;
144
+ };
134
145
  public handlers: HandlerCallbacks<EventPayloadT> = {
135
146
  gestureId: -1,
136
147
  handlerTag: -1,
@@ -27,16 +27,29 @@ export class ComposedGesture extends Gesture {
27
27
  requireGesturesToFail: GestureType[]
28
28
  ) {
29
29
  if (gesture instanceof BaseGesture) {
30
+ // Capture the relations defined directly on the gesture before composition
31
+ // extends them, then always rebuild from that snapshot. Otherwise, when the
32
+ // gesture is stable (e.g. wrapped in `useMemo`) but the composition is
33
+ // recreated on every render, the relations would keep accumulating
34
+ // references to gestures from previous renders, leaking memory (see #3763).
35
+ // We keep the original references (instead of collapsing them to handler
36
+ // tags) so relations can still be re-resolved after a remount, such as a
37
+ // `react-freeze` unfreeze (see #4238).
38
+ gesture.relationsSnapshot ??= {
39
+ simultaneousWith: gesture.config.simultaneousWith,
40
+ requireToFail: gesture.config.requireToFail,
41
+ };
42
+
30
43
  const newConfig = { ...gesture.config };
31
44
 
32
45
  // No need to extend `blocksHandlers` here, because it's not changed in composition.
33
46
  // The same effect is achieved by reversing the order of 2 gestures in `Exclusive`
34
47
  newConfig.simultaneousWith = extendRelation(
35
- newConfig.simultaneousWith,
48
+ gesture.relationsSnapshot.simultaneousWith,
36
49
  simultaneousGestures
37
50
  );
38
51
  newConfig.requireToFail = extendRelation(
39
- newConfig.requireToFail,
52
+ gesture.relationsSnapshot.requireToFail,
40
53
  requireGesturesToFail
41
54
  );
42
55
 
@@ -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) {
@@ -54,4 +54,27 @@ if (Reanimated !== undefined && !Reanimated.setGestureState) {
54
54
  };
55
55
  }
56
56
 
57
+ // Reanimated resolves `getAnimatableRef()` once, when its ref to the wrapped
58
+ // component attaches. Only versions that re-resolve it on update (their
59
+ // `AnimatedComponent` has `_refreshComponentRef`) can be handed a child's host
60
+ // instance that may change, as the legacy `Wrap` does. The class is not
61
+ // exported, so probe it by subpath, as the v3 detector does for
62
+ // `NativeEventsManager`.
63
+ let refreshesAnimatableRef = false;
64
+ try {
65
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
66
+ const AnimatedComponent =
67
+ // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-member-access
68
+ require('react-native-reanimated/src/createAnimatedComponent/AnimatedComponent').default;
69
+ refreshesAnimatableRef =
70
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
71
+ typeof AnimatedComponent?.prototype?._refreshComponentRef === 'function';
72
+ } catch {
73
+ // Reanimated is missing or older; keep handing Reanimated the Wrap itself.
74
+ }
75
+
76
+ export function reanimatedRefreshesAnimatableRef() {
77
+ return refreshesAnimatableRef;
78
+ }
79
+
57
80
  export { Reanimated };
@@ -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
  }