react-native-gesture-handler 2.1.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (250) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +8 -3
  3. package/RNGestureHandler.podspec +27 -3
  4. package/android/build.gradle +82 -9
  5. package/android/lib/src/main/java/com/swmansion/gesturehandler/GestureHandler.kt +47 -12
  6. package/android/lib/src/main/java/com/swmansion/gesturehandler/GestureHandlerOrchestrator.kt +50 -14
  7. package/android/lib/src/main/java/com/swmansion/gesturehandler/PanGestureHandler.kt +7 -4
  8. package/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt +8 -8
  9. package/android/lib/src/main/java/com/swmansion/gesturehandler/RotationGestureHandler.kt +6 -4
  10. package/android/lib/src/main/java/com/swmansion/gesturehandler/ScaleGestureDetector.java +558 -0
  11. package/android/src/fabric/java/com/swmansion/gesturehandler/RNGestureHandlerComponentsRegistry.java +29 -0
  12. package/android/src/fabric/java/com/swmansion/gesturehandler/ReactContextExtensions.kt +12 -0
  13. package/android/src/main/AndroidManifest.xml +1 -1
  14. package/android/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerPackage.kt +29 -0
  15. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +29 -10
  16. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +119 -55
  17. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRegistry.kt +9 -4
  18. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt +1 -1
  19. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootViewManager.kt +17 -2
  20. package/android/src/main/jni/Android.mk +53 -0
  21. package/android/src/main/jni/OnLoad.cpp +9 -0
  22. package/android/src/main/jni/RNGestureHandlerComponentsRegistry.cpp +71 -0
  23. package/android/src/main/jni/RNGestureHandlerComponentsRegistry.h +34 -0
  24. package/android/src/main/jni/cpp-adapter.cpp +41 -0
  25. package/android/src/paper/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.java +47 -0
  26. package/android/src/paper/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerInterface.java +22 -0
  27. package/android/src/paper/java/com/facebook/react/viewmanagers/RNGestureHandlerRootViewManagerDelegate.java +25 -0
  28. package/android/src/paper/java/com/facebook/react/viewmanagers/RNGestureHandlerRootViewManagerInterface.java +16 -0
  29. package/android/src/paper/java/com/swmansion/gesturehandler/ReactContextExtensions.kt +13 -0
  30. package/ios/Handlers/RNFlingHandler.m +2 -0
  31. package/ios/Handlers/RNPanHandler.m +2 -0
  32. package/ios/Handlers/RNPinchHandler.m +2 -0
  33. package/ios/Handlers/RNRotationHandler.m +2 -0
  34. package/ios/RNGestureHandler.h +3 -8
  35. package/ios/RNGestureHandler.m +2 -10
  36. package/ios/RNGestureHandlerActionType.h +8 -0
  37. package/ios/RNGestureHandlerButtonComponentView.h +17 -0
  38. package/ios/RNGestureHandlerButtonComponentView.mm +48 -0
  39. package/ios/RNGestureHandlerButtonManager.h +5 -0
  40. package/ios/RNGestureHandlerButtonManager.m +30 -0
  41. package/ios/RNGestureHandlerManager.h +2 -4
  42. package/ios/{RNGestureHandlerManager.m → RNGestureHandlerManager.mm} +92 -20
  43. package/ios/{RNGestureHandlerModule.m → RNGestureHandlerModule.mm} +91 -36
  44. package/ios/RNGestureHandlerRegistry.h +1 -2
  45. package/ios/RNGestureHandlerRegistry.m +2 -11
  46. package/ios/RNGestureHandlerRootViewComponentView.mm +21 -0
  47. package/lib/commonjs/ActionType.js +15 -0
  48. package/lib/commonjs/ActionType.js.map +1 -0
  49. package/lib/commonjs/GestureHandlerRootView.android.js +6 -6
  50. package/lib/commonjs/GestureHandlerRootView.android.js.map +1 -1
  51. package/lib/commonjs/GestureHandlerRootView.js +2 -3
  52. package/lib/commonjs/GestureHandlerRootView.js.map +1 -1
  53. package/lib/commonjs/RNGestureHandlerModule.js +4 -2
  54. package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
  55. package/lib/commonjs/RNGestureHandlerModule.web.js +1 -1
  56. package/lib/commonjs/RNGestureHandlerModule.web.js.map +1 -1
  57. package/lib/commonjs/components/DrawerLayout.js +2 -2
  58. package/lib/commonjs/components/DrawerLayout.js.map +1 -1
  59. package/lib/commonjs/components/GestureHandlerButton.js +5 -2
  60. package/lib/commonjs/components/GestureHandlerButton.js.map +1 -1
  61. package/lib/commonjs/components/Swipeable.js +22 -20
  62. package/lib/commonjs/components/Swipeable.js.map +1 -1
  63. package/lib/commonjs/fabric/RNGestureHandlerButtonNativeComponent.js +21 -0
  64. package/lib/commonjs/fabric/RNGestureHandlerButtonNativeComponent.js.map +1 -0
  65. package/lib/commonjs/fabric/RNGestureHandlerRootViewNativeComponent.js +21 -0
  66. package/lib/commonjs/fabric/RNGestureHandlerRootViewNativeComponent.js.map +1 -0
  67. package/lib/commonjs/getShadowNodeFromRef.js +24 -0
  68. package/lib/commonjs/getShadowNodeFromRef.js.map +1 -0
  69. package/lib/commonjs/getShadowNodeFromRef.web.js +15 -0
  70. package/lib/commonjs/getShadowNodeFromRef.web.js.map +1 -0
  71. package/lib/commonjs/handlers/FlingGestureHandler.js +4 -2
  72. package/lib/commonjs/handlers/FlingGestureHandler.js.map +1 -1
  73. package/lib/commonjs/handlers/ForceTouchGestureHandler.js +8 -4
  74. package/lib/commonjs/handlers/ForceTouchGestureHandler.js.map +1 -1
  75. package/lib/commonjs/handlers/LongPressGestureHandler.js +4 -2
  76. package/lib/commonjs/handlers/LongPressGestureHandler.js.map +1 -1
  77. package/lib/commonjs/handlers/NativeViewGestureHandler.js +4 -2
  78. package/lib/commonjs/handlers/NativeViewGestureHandler.js.map +1 -1
  79. package/lib/commonjs/handlers/PanGestureHandler.js +4 -2
  80. package/lib/commonjs/handlers/PanGestureHandler.js.map +1 -1
  81. package/lib/commonjs/handlers/PinchGestureHandler.js +4 -2
  82. package/lib/commonjs/handlers/PinchGestureHandler.js.map +1 -1
  83. package/lib/commonjs/handlers/RotationGestureHandler.js +4 -2
  84. package/lib/commonjs/handlers/RotationGestureHandler.js.map +1 -1
  85. package/lib/commonjs/handlers/TapGestureHandler.js +4 -2
  86. package/lib/commonjs/handlers/TapGestureHandler.js.map +1 -1
  87. package/lib/commonjs/handlers/createHandler.js +72 -8
  88. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  89. package/lib/commonjs/handlers/createNativeWrapper.js +6 -2
  90. package/lib/commonjs/handlers/createNativeWrapper.js.map +1 -1
  91. package/lib/commonjs/handlers/gestureHandlerCommon.js.map +1 -1
  92. package/lib/commonjs/handlers/gestures/GestureDetector.js +84 -32
  93. package/lib/commonjs/handlers/gestures/GestureDetector.js.map +1 -1
  94. package/lib/commonjs/handlers/gestures/eventReceiver.js +25 -8
  95. package/lib/commonjs/handlers/gestures/eventReceiver.js.map +1 -1
  96. package/lib/commonjs/handlers/gestures/forceTouchGesture.js.map +1 -1
  97. package/lib/commonjs/handlers/gestures/gesture.js +16 -1
  98. package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
  99. package/lib/commonjs/handlers/gestures/gestureStateManager.js +7 -4
  100. package/lib/commonjs/handlers/gestures/gestureStateManager.js.map +1 -1
  101. package/lib/commonjs/handlers/gestures/panGesture.js.map +1 -1
  102. package/lib/commonjs/handlers/gestures/pinchGesture.js.map +1 -1
  103. package/lib/commonjs/handlers/gestures/reanimatedWrapper.js +4 -1
  104. package/lib/commonjs/handlers/gestures/reanimatedWrapper.js.map +1 -1
  105. package/lib/commonjs/handlers/handlersRegistry.js +42 -6
  106. package/lib/commonjs/handlers/handlersRegistry.js.map +1 -1
  107. package/lib/commonjs/index.js +14 -106
  108. package/lib/commonjs/index.js.map +1 -1
  109. package/lib/commonjs/init.js +10 -0
  110. package/lib/commonjs/init.js.map +1 -1
  111. package/lib/commonjs/jestUtils.js +375 -0
  112. package/lib/commonjs/jestUtils.js.map +1 -0
  113. package/lib/commonjs/utils.js +38 -0
  114. package/lib/commonjs/utils.js.map +1 -1
  115. package/lib/module/ActionType.js +7 -0
  116. package/lib/module/ActionType.js.map +1 -0
  117. package/lib/module/GestureHandlerRootView.android.js +5 -6
  118. package/lib/module/GestureHandlerRootView.android.js.map +1 -1
  119. package/lib/module/GestureHandlerRootView.js +2 -3
  120. package/lib/module/GestureHandlerRootView.js.map +1 -1
  121. package/lib/module/RNGestureHandlerModule.js +3 -2
  122. package/lib/module/RNGestureHandlerModule.js.map +1 -1
  123. package/lib/module/RNGestureHandlerModule.web.js +1 -1
  124. package/lib/module/RNGestureHandlerModule.web.js.map +1 -1
  125. package/lib/module/components/DrawerLayout.js +2 -2
  126. package/lib/module/components/DrawerLayout.js.map +1 -1
  127. package/lib/module/components/GestureHandlerButton.js +4 -2
  128. package/lib/module/components/GestureHandlerButton.js.map +1 -1
  129. package/lib/module/components/Swipeable.js +22 -20
  130. package/lib/module/components/Swipeable.js.map +1 -1
  131. package/lib/module/fabric/RNGestureHandlerButtonNativeComponent.js +9 -0
  132. package/lib/module/fabric/RNGestureHandlerButtonNativeComponent.js.map +1 -0
  133. package/lib/module/fabric/RNGestureHandlerRootViewNativeComponent.js +9 -0
  134. package/lib/module/fabric/RNGestureHandlerRootViewNativeComponent.js.map +1 -0
  135. package/lib/module/getShadowNodeFromRef.js +17 -0
  136. package/lib/module/getShadowNodeFromRef.js.map +1 -0
  137. package/lib/module/getShadowNodeFromRef.web.js +8 -0
  138. package/lib/module/getShadowNodeFromRef.web.js.map +1 -0
  139. package/lib/module/handlers/FlingGestureHandler.js +2 -1
  140. package/lib/module/handlers/FlingGestureHandler.js.map +1 -1
  141. package/lib/module/handlers/ForceTouchGestureHandler.js +5 -3
  142. package/lib/module/handlers/ForceTouchGestureHandler.js.map +1 -1
  143. package/lib/module/handlers/LongPressGestureHandler.js +2 -1
  144. package/lib/module/handlers/LongPressGestureHandler.js.map +1 -1
  145. package/lib/module/handlers/NativeViewGestureHandler.js +2 -1
  146. package/lib/module/handlers/NativeViewGestureHandler.js.map +1 -1
  147. package/lib/module/handlers/PanGestureHandler.js +2 -1
  148. package/lib/module/handlers/PanGestureHandler.js.map +1 -1
  149. package/lib/module/handlers/PinchGestureHandler.js +2 -1
  150. package/lib/module/handlers/PinchGestureHandler.js.map +1 -1
  151. package/lib/module/handlers/RotationGestureHandler.js +2 -1
  152. package/lib/module/handlers/RotationGestureHandler.js.map +1 -1
  153. package/lib/module/handlers/TapGestureHandler.js +2 -1
  154. package/lib/module/handlers/TapGestureHandler.js.map +1 -1
  155. package/lib/module/handlers/createHandler.js +72 -9
  156. package/lib/module/handlers/createHandler.js.map +1 -1
  157. package/lib/module/handlers/createNativeWrapper.js +6 -2
  158. package/lib/module/handlers/createNativeWrapper.js.map +1 -1
  159. package/lib/module/handlers/gestureHandlerCommon.js.map +1 -1
  160. package/lib/module/handlers/gestures/GestureDetector.js +79 -32
  161. package/lib/module/handlers/gestures/GestureDetector.js.map +1 -1
  162. package/lib/module/handlers/gestures/eventReceiver.js +25 -7
  163. package/lib/module/handlers/gestures/eventReceiver.js.map +1 -1
  164. package/lib/module/handlers/gestures/forceTouchGesture.js.map +1 -1
  165. package/lib/module/handlers/gestures/gesture.js +16 -1
  166. package/lib/module/handlers/gestures/gesture.js.map +1 -1
  167. package/lib/module/handlers/gestures/gestureStateManager.js +6 -4
  168. package/lib/module/handlers/gestures/gestureStateManager.js.map +1 -1
  169. package/lib/module/handlers/gestures/panGesture.js.map +1 -1
  170. package/lib/module/handlers/gestures/pinchGesture.js.map +1 -1
  171. package/lib/module/handlers/gestures/reanimatedWrapper.js +2 -1
  172. package/lib/module/handlers/gestures/reanimatedWrapper.js.map +1 -1
  173. package/lib/module/handlers/handlersRegistry.js +34 -6
  174. package/lib/module/handlers/handlersRegistry.js.map +1 -1
  175. package/lib/module/index.js +1 -11
  176. package/lib/module/index.js.map +1 -1
  177. package/lib/module/init.js +6 -0
  178. package/lib/module/init.js.map +1 -1
  179. package/lib/module/jestUtils.js +350 -0
  180. package/lib/module/jestUtils.js.map +1 -0
  181. package/lib/module/utils.js +28 -0
  182. package/lib/module/utils.js.map +1 -1
  183. package/lib/typescript/ActionType.d.ts +7 -0
  184. package/lib/typescript/GestureHandlerRootView.android.d.ts +5 -2
  185. package/lib/typescript/GestureHandlerRootView.d.ts +1 -1
  186. package/lib/typescript/RNGestureHandlerModule.d.ts +3 -1
  187. package/lib/typescript/RNGestureHandlerModule.web.d.ts +2 -1
  188. package/lib/typescript/components/GestureHandlerButton.d.ts +2 -2
  189. package/lib/typescript/components/Swipeable.d.ts +12 -4
  190. package/lib/typescript/getShadowNodeFromRef.d.ts +1 -0
  191. package/lib/typescript/getShadowNodeFromRef.web.d.ts +1 -0
  192. package/lib/typescript/handlers/FlingGestureHandler.d.ts +1 -0
  193. package/lib/typescript/handlers/ForceTouchGestureHandler.d.ts +2 -1
  194. package/lib/typescript/handlers/LongPressGestureHandler.d.ts +3 -2
  195. package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +1 -0
  196. package/lib/typescript/handlers/PanGestureHandler.d.ts +3 -2
  197. package/lib/typescript/handlers/PinchGestureHandler.d.ts +1 -0
  198. package/lib/typescript/handlers/RotationGestureHandler.d.ts +1 -0
  199. package/lib/typescript/handlers/TapGestureHandler.d.ts +1 -0
  200. package/lib/typescript/handlers/gestureHandlerCommon.d.ts +2 -4
  201. package/lib/typescript/handlers/gestures/GestureDetector.d.ts +4 -1
  202. package/lib/typescript/handlers/gestures/forceTouchGesture.d.ts +1 -2
  203. package/lib/typescript/handlers/gestures/gesture.d.ts +5 -0
  204. package/lib/typescript/handlers/gestures/panGesture.d.ts +1 -2
  205. package/lib/typescript/handlers/gestures/pinchGesture.d.ts +1 -2
  206. package/lib/typescript/handlers/handlersRegistry.d.ts +11 -3
  207. package/lib/typescript/index.d.ts +15 -11
  208. package/lib/typescript/jestUtils.d.ts +28 -0
  209. package/lib/typescript/utils.d.ts +6 -0
  210. package/lib/typescript/web/constants.d.ts +0 -1
  211. package/package.json +39 -16
  212. package/src/ActionType.ts +9 -0
  213. package/src/GestureHandlerRootView.android.tsx +14 -14
  214. package/src/GestureHandlerRootView.tsx +4 -4
  215. package/src/RNGestureHandlerModule.ts +11 -6
  216. package/src/RNGestureHandlerModule.web.ts +2 -1
  217. package/src/components/DrawerLayout.tsx +8 -2
  218. package/src/components/GestureHandlerButton.tsx +7 -4
  219. package/src/components/Swipeable.tsx +28 -22
  220. package/src/fabric/RNGestureHandlerButtonNativeComponent.js +27 -0
  221. package/src/fabric/RNGestureHandlerRootViewNativeComponent.js +19 -0
  222. package/src/getShadowNodeFromRef.ts +19 -0
  223. package/src/getShadowNodeFromRef.web.ts +7 -0
  224. package/src/handlers/FlingGestureHandler.ts +3 -1
  225. package/src/handlers/ForceTouchGestureHandler.ts +8 -2
  226. package/src/handlers/LongPressGestureHandler.ts +5 -3
  227. package/src/handlers/NativeViewGestureHandler.ts +3 -1
  228. package/src/handlers/PanGestureHandler.ts +5 -3
  229. package/src/handlers/PinchGestureHandler.ts +3 -1
  230. package/src/handlers/RotationGestureHandler.ts +3 -1
  231. package/src/handlers/TapGestureHandler.ts +3 -1
  232. package/src/handlers/createHandler.ts +80 -5
  233. package/src/handlers/createNativeWrapper.tsx +7 -1
  234. package/src/handlers/gestureHandlerCommon.ts +2 -5
  235. package/src/handlers/gestures/GestureDetector.tsx +110 -37
  236. package/src/handlers/gestures/eventReceiver.ts +23 -19
  237. package/src/handlers/gestures/forceTouchGesture.ts +1 -1
  238. package/src/handlers/gestures/gesture.ts +21 -1
  239. package/src/handlers/gestures/gestureStateManager.ts +9 -12
  240. package/src/handlers/gestures/panGesture.ts +1 -1
  241. package/src/handlers/gestures/pinchGesture.ts +1 -1
  242. package/src/handlers/gestures/reanimatedWrapper.ts +4 -1
  243. package/src/handlers/handlersRegistry.ts +44 -6
  244. package/src/index.ts +15 -11
  245. package/src/init.ts +6 -0
  246. package/src/jestUtils.ts +506 -0
  247. package/src/utils.ts +38 -0
  248. package/android/lib/src/main/java/com/swmansion/gesturehandler/BaseGestureHandlerInteractionController.kt +0 -18
  249. package/android/lib/src/main/java/com/swmansion/gesturehandler/GestureHandlerRegistryImpl.kt +0 -21
  250. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerPackage.kt +0 -17
@@ -17,32 +17,43 @@ import android.view.View.OnClickListener
17
17
  import android.view.ViewGroup
18
18
  import androidx.core.view.children
19
19
  import com.facebook.react.bridge.SoftAssertions
20
+ import com.facebook.react.module.annotations.ReactModule
20
21
  import com.facebook.react.uimanager.PixelUtil
21
22
  import com.facebook.react.uimanager.ThemedReactContext
22
23
  import com.facebook.react.uimanager.ViewGroupManager
24
+ import com.facebook.react.uimanager.ViewManagerDelegate
23
25
  import com.facebook.react.uimanager.ViewProps
24
26
  import com.facebook.react.uimanager.annotations.ReactProp
27
+ import com.facebook.react.viewmanagers.RNGestureHandlerButtonManagerDelegate
28
+ import com.facebook.react.viewmanagers.RNGestureHandlerButtonManagerInterface
25
29
  import com.swmansion.gesturehandler.NativeViewGestureHandler
26
30
  import com.swmansion.gesturehandler.react.RNGestureHandlerButtonViewManager.ButtonViewGroup
27
31
 
28
- class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>() {
29
- override fun getName() = "RNGestureHandlerButton"
32
+ @ReactModule(name = RNGestureHandlerButtonViewManager.REACT_CLASS)
33
+ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>(), RNGestureHandlerButtonManagerInterface<ButtonViewGroup> {
34
+ private val mDelegate: ViewManagerDelegate<ButtonViewGroup>
35
+
36
+ init {
37
+ mDelegate = RNGestureHandlerButtonManagerDelegate<ButtonViewGroup, RNGestureHandlerButtonViewManager>(this)
38
+ }
39
+
40
+ override fun getName() = REACT_CLASS
30
41
 
31
42
  public override fun createViewInstance(context: ThemedReactContext) = ButtonViewGroup(context)
32
43
 
33
44
  @TargetApi(Build.VERSION_CODES.M)
34
45
  @ReactProp(name = "foreground")
35
- fun setForeground(view: ButtonViewGroup, useDrawableOnForeground: Boolean) {
46
+ override fun setForeground(view: ButtonViewGroup, useDrawableOnForeground: Boolean) {
36
47
  view.useDrawableOnForeground = useDrawableOnForeground
37
48
  }
38
49
 
39
50
  @ReactProp(name = "borderless")
40
- fun setBorderless(view: ButtonViewGroup, useBorderlessDrawable: Boolean) {
51
+ override fun setBorderless(view: ButtonViewGroup, useBorderlessDrawable: Boolean) {
41
52
  view.useBorderlessDrawable = useBorderlessDrawable
42
53
  }
43
54
 
44
55
  @ReactProp(name = "enabled")
45
- fun setEnabled(view: ButtonViewGroup, enabled: Boolean) {
56
+ override fun setEnabled(view: ButtonViewGroup, enabled: Boolean) {
46
57
  view.isEnabled = enabled
47
58
  }
48
59
 
@@ -52,17 +63,17 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>() {
52
63
  }
53
64
 
54
65
  @ReactProp(name = "rippleColor")
55
- fun setRippleColor(view: ButtonViewGroup, rippleColor: Int?) {
66
+ override fun setRippleColor(view: ButtonViewGroup, rippleColor: Int?) {
56
67
  view.rippleColor = rippleColor
57
68
  }
58
69
 
59
70
  @ReactProp(name = "rippleRadius")
60
- fun setRippleRadius(view: ButtonViewGroup, rippleRadius: Int?) {
71
+ override fun setRippleRadius(view: ButtonViewGroup, rippleRadius: Int) {
61
72
  view.rippleRadius = rippleRadius
62
73
  }
63
74
 
64
75
  @ReactProp(name = "exclusive")
65
- fun setExclusive(view: ButtonViewGroup, exclusive: Boolean = true) {
76
+ override fun setExclusive(view: ButtonViewGroup, exclusive: Boolean) {
66
77
  view.exclusive = exclusive
67
78
  }
68
79
 
@@ -70,6 +81,10 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>() {
70
81
  view.updateBackground()
71
82
  }
72
83
 
84
+ override fun getDelegate(): ViewManagerDelegate<ButtonViewGroup>? {
85
+ return mDelegate
86
+ }
87
+
73
88
  class ButtonViewGroup(context: Context?) : ViewGroup(context),
74
89
  NativeViewGestureHandler.StateChangeHook {
75
90
  // Using object because of handling null representing no value set.
@@ -333,10 +348,10 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>() {
333
348
  SoftAssertions.assertNotNull(attr)
334
349
  return when (attr) {
335
350
  SELECTABLE_ITEM_BACKGROUND -> {
336
- R.attr.selectableItemBackground
351
+ android.R.attr.selectableItemBackground
337
352
  }
338
353
  SELECTABLE_ITEM_BACKGROUND_BORDERLESS -> {
339
- R.attr.selectableItemBackgroundBorderless
354
+ android.R.attr.selectableItemBackgroundBorderless
340
355
  }
341
356
  else -> {
342
357
  context.resources.getIdentifier(attr, "attr", "android")
@@ -345,4 +360,8 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>() {
345
360
  }
346
361
  }
347
362
  }
363
+
364
+ companion object {
365
+ const val REACT_CLASS = "RNGestureHandlerButton"
366
+ }
348
367
  }
@@ -1,6 +1,7 @@
1
1
  package com.swmansion.gesturehandler.react
2
2
 
3
3
  import android.content.Context
4
+ import android.util.Log
4
5
  import android.view.MotionEvent
5
6
  import android.view.ViewGroup
6
7
  import com.facebook.react.ReactRootView
@@ -8,6 +9,8 @@ import com.facebook.react.bridge.*
8
9
  import com.facebook.react.module.annotations.ReactModule
9
10
  import com.facebook.react.uimanager.PixelUtil
10
11
  import com.facebook.react.uimanager.UIBlock
12
+ import com.facebook.react.uimanager.events.Event
13
+ import com.facebook.soloader.SoLoader
11
14
  import com.swmansion.common.GestureHandlerStateManager
12
15
  import com.swmansion.gesturehandler.*
13
16
  import java.util.*
@@ -106,8 +109,8 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?)
106
109
  with(eventData) {
107
110
  putDouble("x", PixelUtil.toDIPFromPixel(handler.lastRelativePositionX).toDouble())
108
111
  putDouble("y", PixelUtil.toDIPFromPixel(handler.lastRelativePositionY).toDouble())
109
- putDouble("absoluteX", PixelUtil.toDIPFromPixel(handler.lastAbsolutePositionX).toDouble())
110
- putDouble("absoluteY", PixelUtil.toDIPFromPixel(handler.lastAbsolutePositionY).toDouble())
112
+ putDouble("absoluteX", PixelUtil.toDIPFromPixel(handler.lastPositionInWindowX).toDouble())
113
+ putDouble("absoluteY", PixelUtil.toDIPFromPixel(handler.lastPositionInWindowY).toDouble())
111
114
  }
112
115
  }
113
116
  }
@@ -135,8 +138,8 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?)
135
138
  with(eventData) {
136
139
  putDouble("x", PixelUtil.toDIPFromPixel(handler.lastRelativePositionX).toDouble())
137
140
  putDouble("y", PixelUtil.toDIPFromPixel(handler.lastRelativePositionY).toDouble())
138
- putDouble("absoluteX", PixelUtil.toDIPFromPixel(handler.lastAbsolutePositionX).toDouble())
139
- putDouble("absoluteY", PixelUtil.toDIPFromPixel(handler.lastAbsolutePositionY).toDouble())
141
+ putDouble("absoluteX", PixelUtil.toDIPFromPixel(handler.lastPositionInWindowX).toDouble())
142
+ putDouble("absoluteY", PixelUtil.toDIPFromPixel(handler.lastPositionInWindowY).toDouble())
140
143
  putInt("duration", handler.duration)
141
144
  }
142
145
  }
@@ -223,8 +226,8 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?)
223
226
  with(eventData) {
224
227
  putDouble("x", PixelUtil.toDIPFromPixel(handler.lastRelativePositionX).toDouble())
225
228
  putDouble("y", PixelUtil.toDIPFromPixel(handler.lastRelativePositionY).toDouble())
226
- putDouble("absoluteX", PixelUtil.toDIPFromPixel(handler.lastAbsolutePositionX).toDouble())
227
- putDouble("absoluteY", PixelUtil.toDIPFromPixel(handler.lastAbsolutePositionY).toDouble())
229
+ putDouble("absoluteX", PixelUtil.toDIPFromPixel(handler.lastPositionInWindowX).toDouble())
230
+ putDouble("absoluteY", PixelUtil.toDIPFromPixel(handler.lastPositionInWindowY).toDouble())
228
231
  putDouble("translationX", PixelUtil.toDIPFromPixel(handler.translationX).toDouble())
229
232
  putDouble("translationY", PixelUtil.toDIPFromPixel(handler.translationY).toDouble())
230
233
  putDouble("velocityX", PixelUtil.toDIPFromPixel(handler.velocityX).toDouble())
@@ -275,8 +278,8 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?)
275
278
  with(eventData) {
276
279
  putDouble("x", PixelUtil.toDIPFromPixel(handler.lastRelativePositionX).toDouble())
277
280
  putDouble("y", PixelUtil.toDIPFromPixel(handler.lastRelativePositionY).toDouble())
278
- putDouble("absoluteX", PixelUtil.toDIPFromPixel(handler.lastAbsolutePositionX).toDouble())
279
- putDouble("absoluteY", PixelUtil.toDIPFromPixel(handler.lastAbsolutePositionY).toDouble())
281
+ putDouble("absoluteX", PixelUtil.toDIPFromPixel(handler.lastPositionInWindowX).toDouble())
282
+ putDouble("absoluteY", PixelUtil.toDIPFromPixel(handler.lastPositionInWindowY).toDouble())
280
283
  }
281
284
  }
282
285
  }
@@ -359,10 +362,16 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?)
359
362
  }
360
363
 
361
364
  @ReactMethod
362
- fun attachGestureHandler(handlerTag: Int, viewTag: Int, useDeviceEvents: Boolean) {
363
- tryInitializeHandlerForReactRootView(viewTag)
365
+ fun attachGestureHandler(handlerTag: Int, viewTag: Int, actionType: Int) {
366
+ if (!BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
367
+ tryInitializeHandlerForReactRootView(viewTag)
368
+ }
364
369
 
365
- if (!registry.attachHandlerToView(handlerTag, viewTag, useDeviceEvents)) {
370
+ // We don't have to handle view flattening in any special way since handlers are stored as
371
+ // a map: viewTag -> [handler]. If the view with attached handlers was to be flattened
372
+ // then that viewTag simply wouldn't be visited when traversing the view hierarchy in the
373
+ // Orchestrator effectively ignoring all handlers attached to flattened views.
374
+ if (!registry.attachHandlerToView(handlerTag, viewTag, actionType)) {
366
375
  throw JSApplicationIllegalArgumentException("Handler with tag $handlerTag does not exists")
367
376
  }
368
377
  }
@@ -409,6 +418,21 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?)
409
418
  }
410
419
  }
411
420
 
421
+ @ReactMethod(isBlockingSynchronousMethod = true)
422
+ fun install(): Boolean {
423
+ return try {
424
+ SoLoader.loadLibrary("rngesturehandler_modules")
425
+ val jsContext = reactApplicationContext.javaScriptContextHolder
426
+ decorateRuntime(jsContext.get())
427
+ true
428
+ } catch (exception: Exception) {
429
+ Log.w("[RNGestureHandler]", "Could not install JSI bindings.")
430
+ false
431
+ }
432
+ }
433
+
434
+ private external fun decorateRuntime(jsiPtr: Long)
435
+
412
436
  override fun getConstants(): Map<String, Any> {
413
437
  return mapOf(
414
438
  "State" to mapOf(
@@ -501,6 +525,7 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?)
501
525
  }
502
526
 
503
527
  private fun findRootHelperForViewAncestor(viewTag: Int): RNGestureHandlerRootHelper? {
528
+ // TODO: remove resolveRootTagFromReactTag as it's deprecated and unavailable on FabricUIManager
504
529
  val uiManager = reactApplicationContext.UIManager
505
530
  val rootViewTag = uiManager.resolveRootTagFromReactTag(viewTag)
506
531
  if (rootViewTag < 1) {
@@ -518,6 +543,8 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?)
518
543
  handlerFactories.firstOrNull { it.type == handler.javaClass } as HandlerFactory<T>?
519
544
 
520
545
  private fun <T : GestureHandler<T>> onHandlerUpdate(handler: T, motionEvent: MotionEvent) {
546
+ // triggers onUpdate and onChange callbacks on the JS side
547
+
521
548
  if (handler.tag < 0) {
522
549
  // root containers use negative tags, we don't need to dispatch events for them to the JS
523
550
  return
@@ -525,76 +552,113 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?)
525
552
  if (handler.state == GestureHandler.STATE_ACTIVE) {
526
553
  val handlerFactory = findFactoryForHandler(handler)
527
554
 
528
- if (handler.usesDeviceEvents) {
555
+ if (handler.actionType == GestureHandler.ACTION_TYPE_REANIMATED_WORKLET) {
556
+ // Reanimated worklet
557
+ val event = RNGestureHandlerEvent.obtain(handler, handlerFactory)
558
+ sendEventForReanimated(event)
559
+ } else if (handler.actionType == GestureHandler.ACTION_TYPE_NATIVE_ANIMATED_EVENT) {
560
+ // Animated with useNativeDriver: true
561
+ val event = RNGestureHandlerEvent.obtain(handler, handlerFactory)
562
+ sendEventForNativeAnimatedEvent(event)
563
+ } else if (handler.actionType == GestureHandler.ACTION_TYPE_JS_FUNCTION_OLD_API) {
564
+ // JS function, Animated.event with useNativeDriver: false using old API
565
+ if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
566
+ val data = RNGestureHandlerEvent.createEventData(handler, handlerFactory)
567
+ sendEventForDeviceEvent(RNGestureHandlerEvent.EVENT_NAME, data)
568
+ } else {
569
+ val event = RNGestureHandlerEvent.obtain(handler, handlerFactory)
570
+ sendEventForDirectEvent(event)
571
+ }
572
+ } else if (handler.actionType == GestureHandler.ACTION_TYPE_JS_FUNCTION_NEW_API) {
573
+ // JS function, Animated.event with useNativeDriver: false using new API
529
574
  val data = RNGestureHandlerEvent.createEventData(handler, handlerFactory)
530
-
531
- reactApplicationContext
532
- .deviceEventEmitter
533
- .emit(RNGestureHandlerEvent.EVENT_NAME, data)
534
- } else {
535
- reactApplicationContext
536
- .UIManager
537
- .eventDispatcher.let {
538
- val event = RNGestureHandlerEvent.obtain(handler, handlerFactory)
539
- it.dispatchEvent(event)
540
- }
575
+ sendEventForDeviceEvent(RNGestureHandlerEvent.EVENT_NAME, data)
541
576
  }
542
577
  }
543
578
  }
544
579
 
545
580
  private fun <T : GestureHandler<T>> onStateChange(handler: T, newState: Int, oldState: Int) {
581
+ // triggers onBegin, onStart, onEnd, onFinalize callbacks on the JS side
582
+
546
583
  if (handler.tag < 0) {
547
584
  // root containers use negative tags, we don't need to dispatch events for them to the JS
548
585
  return
549
586
  }
550
587
  val handlerFactory = findFactoryForHandler(handler)
551
588
 
552
- if (handler.usesDeviceEvents) {
553
- val data = RNGestureHandlerStateChangeEvent.createEventData(
554
- handler,
555
- handlerFactory,
556
- newState,
557
- oldState,
558
- )
559
-
560
- reactApplicationContext
561
- .deviceEventEmitter
562
- .emit(RNGestureHandlerStateChangeEvent.EVENT_NAME, data)
563
- } else {
564
- reactApplicationContext
565
- .UIManager
566
- .eventDispatcher.let {
567
- val event =
568
- RNGestureHandlerStateChangeEvent.obtain(handler, newState, oldState, handlerFactory)
569
- it.dispatchEvent(event)
570
- }
589
+ if (handler.actionType == GestureHandler.ACTION_TYPE_REANIMATED_WORKLET) {
590
+ // Reanimated worklet
591
+ val event = RNGestureHandlerStateChangeEvent.obtain(handler, newState, oldState, handlerFactory)
592
+ sendEventForReanimated(event)
593
+ } else if (handler.actionType == GestureHandler.ACTION_TYPE_NATIVE_ANIMATED_EVENT
594
+ || handler.actionType == GestureHandler.ACTION_TYPE_JS_FUNCTION_OLD_API) {
595
+ // JS function or Animated.event with useNativeDriver: false with old API
596
+ if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
597
+ val data = RNGestureHandlerStateChangeEvent.createEventData(handler, handlerFactory, newState, oldState)
598
+ sendEventForDeviceEvent(RNGestureHandlerStateChangeEvent.EVENT_NAME, data)
599
+ } else {
600
+ val event = RNGestureHandlerStateChangeEvent.obtain(handler, newState, oldState, handlerFactory)
601
+ sendEventForDirectEvent(event)
602
+ }
603
+ } else if (handler.actionType == GestureHandler.ACTION_TYPE_JS_FUNCTION_NEW_API) {
604
+ // JS function or Animated.event with useNativeDriver: false with new API
605
+ val data = RNGestureHandlerStateChangeEvent.createEventData(handler, handlerFactory, newState, oldState)
606
+ sendEventForDeviceEvent(RNGestureHandlerStateChangeEvent.EVENT_NAME, data)
571
607
  }
572
608
  }
573
609
 
574
610
  private fun <T : GestureHandler<T>> onTouchEvent(handler: T) {
611
+ // triggers onTouchesDown, onTouchesMove, onTouchesUp, onTouchesCancelled callbacks on the JS side
612
+
575
613
  if (handler.tag < 0) {
576
614
  // root containers use negative tags, we don't need to dispatch events for them to the JS
577
615
  return
578
616
  }
579
617
  if (handler.state == GestureHandler.STATE_BEGAN || handler.state == GestureHandler.STATE_ACTIVE
580
- || handler.state == GestureHandler.STATE_UNDETERMINED || handler.view != null) {
581
- if (handler.usesDeviceEvents) {
618
+ || handler.state == GestureHandler.STATE_UNDETERMINED || handler.view != null) {
619
+ if (handler.actionType == GestureHandler.ACTION_TYPE_REANIMATED_WORKLET) {
620
+ // Reanimated worklet
621
+ val event = RNGestureHandlerTouchEvent.obtain(handler)
622
+ sendEventForReanimated(event)
623
+ } else if (handler.actionType == GestureHandler.ACTION_TYPE_JS_FUNCTION_NEW_API) {
624
+ // JS function, Animated.event with useNativeDriver: false with new API
582
625
  val data = RNGestureHandlerTouchEvent.createEventData(handler)
583
-
584
- reactApplicationContext
585
- .deviceEventEmitter
586
- .emit(RNGestureHandlerTouchEvent.EVENT_NAME, data)
587
- } else {
588
- reactApplicationContext
589
- .UIManager
590
- .eventDispatcher.let {
591
- val event = RNGestureHandlerTouchEvent.obtain(handler)
592
- it.dispatchEvent(event)
593
- }
626
+ sendEventForDeviceEvent(RNGestureHandlerEvent.EVENT_NAME, data)
594
627
  }
595
628
  }
596
629
  }
597
630
 
631
+ private fun <T : Event<T>>sendEventForReanimated(event: T) {
632
+ // Delivers the event to Reanimated.
633
+ if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
634
+ // TODO: send event directly to Reanimated
635
+ // This is already supported in Reanimated with Fabric but let's wait until the official release.
636
+ // val reanimatedModule = reactApplicationContext.getNativeModule(ReanimatedModule::class.java)
637
+ // reanimatedModule?.nodesManager?.onEventDispatch(event)
638
+ } else {
639
+ // In the old architecture, Reanimated subscribes for specific direct events.
640
+ sendEventForDirectEvent(event)
641
+ }
642
+ }
643
+
644
+ private fun sendEventForNativeAnimatedEvent(event: RNGestureHandlerEvent) {
645
+ // Delivers the event to NativeAnimatedModule.
646
+ // TODO: send event directly to NativeAnimated[Turbo]Module
647
+ // ReactContext.dispatchEvent is an extension function, depending on the architecture it will
648
+ // dispatch event using UIManagerModule or FabricUIManager.
649
+ reactApplicationContext.dispatchEvent(event)
650
+ }
651
+
652
+ private fun <T : Event<T>>sendEventForDirectEvent(event: T) {
653
+ // Delivers the event to JS as a direct event. This method is called only on Paper.
654
+ reactApplicationContext.dispatchEvent(event)
655
+ }
656
+
657
+ private fun sendEventForDeviceEvent(eventName: String, data: WritableMap) {
658
+ // Delivers the event to JS as a device event.
659
+ reactApplicationContext.deviceEventEmitter.emit(eventName, data)
660
+ }
661
+
598
662
  companion object {
599
663
  const val MODULE_NAME = "RNGestureHandlerModule"
600
664
  private const val KEY_SHOULD_CANCEL_WHEN_OUTSIDE = "shouldCancelWhenOutside"
@@ -23,11 +23,11 @@ class RNGestureHandlerRegistry : GestureHandlerRegistry {
23
23
  }
24
24
 
25
25
  @Synchronized
26
- fun attachHandlerToView(handlerTag: Int, viewTag: Int, useDeviceEvents: Boolean = false): Boolean {
26
+ fun attachHandlerToView(handlerTag: Int, viewTag: Int, actionType: Int): Boolean {
27
27
  val handler = handlers[handlerTag]
28
28
  return handler?.let {
29
29
  detachHandler(handler)
30
- handler.usesDeviceEvents = useDeviceEvents
30
+ handler.actionType = actionType
31
31
  registerHandlerForViewWithTag(viewTag, handler)
32
32
  true
33
33
  } ?: false
@@ -43,7 +43,9 @@ class RNGestureHandlerRegistry : GestureHandlerRegistry {
43
43
  listToAdd.add(handler)
44
44
  handlersForView.put(viewTag, listToAdd)
45
45
  } else {
46
- listToAdd.add(handler)
46
+ synchronized(listToAdd) {
47
+ listToAdd.add(handler)
48
+ }
47
49
  }
48
50
  }
49
51
 
@@ -54,7 +56,10 @@ class RNGestureHandlerRegistry : GestureHandlerRegistry {
54
56
  attachedTo.remove(handler.tag)
55
57
  val attachedHandlers = handlersForView[attachedToView]
56
58
  if (attachedHandlers != null) {
57
- attachedHandlers.remove(handler)
59
+ synchronized(attachedHandlers) {
60
+ attachedHandlers.remove(handler)
61
+ }
62
+
58
63
  if (attachedHandlers.size == 0) {
59
64
  handlersForView.remove(attachedToView)
60
65
  }
@@ -37,7 +37,7 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView:
37
37
  jsGestureHandler = RootViewGestureHandler().apply { tag = -wrappedViewTag }
38
38
  with(registry) {
39
39
  registerHandler(jsGestureHandler)
40
- attachHandlerToView(jsGestureHandler.tag, wrappedViewTag)
40
+ attachHandlerToView(jsGestureHandler.tag, wrappedViewTag, GestureHandler.ACTION_TYPE_JS_FUNCTION_OLD_API)
41
41
  }
42
42
  module.registerRootHelper(this)
43
43
  }
@@ -3,6 +3,9 @@ package com.swmansion.gesturehandler.react
3
3
  import com.facebook.react.module.annotations.ReactModule
4
4
  import com.facebook.react.uimanager.ThemedReactContext
5
5
  import com.facebook.react.uimanager.ViewGroupManager
6
+ import com.facebook.react.uimanager.ViewManagerDelegate
7
+ import com.facebook.react.viewmanagers.RNGestureHandlerRootViewManagerDelegate
8
+ import com.facebook.react.viewmanagers.RNGestureHandlerRootViewManagerInterface
6
9
 
7
10
  /**
8
11
  * React native's view manager used for creating instances of []RNGestureHandlerRootView}. It
@@ -10,8 +13,20 @@ import com.facebook.react.uimanager.ViewGroupManager
10
13
  * to be provided.
11
14
  */
12
15
  @ReactModule(name = RNGestureHandlerRootViewManager.REACT_CLASS)
13
- class RNGestureHandlerRootViewManager : ViewGroupManager<RNGestureHandlerRootView>() {
16
+ class RNGestureHandlerRootViewManager : ViewGroupManager<RNGestureHandlerRootView>(),
17
+ RNGestureHandlerRootViewManagerInterface<RNGestureHandlerRootView> {
18
+ private val mDelegate: ViewManagerDelegate<RNGestureHandlerRootView>
19
+
20
+ init {
21
+ mDelegate = RNGestureHandlerRootViewManagerDelegate<RNGestureHandlerRootView, RNGestureHandlerRootViewManager>(this)
22
+ }
23
+
24
+ override fun getDelegate(): ViewManagerDelegate<RNGestureHandlerRootView> {
25
+ return mDelegate
26
+ }
27
+
14
28
  override fun getName() = REACT_CLASS
29
+
15
30
  override fun createViewInstance(reactContext: ThemedReactContext) = RNGestureHandlerRootView(reactContext)
16
31
 
17
32
  override fun onDropViewInstance(view: RNGestureHandlerRootView) {
@@ -29,6 +44,6 @@ class RNGestureHandlerRootViewManager : ViewGroupManager<RNGestureHandlerRootVie
29
44
  mutableMapOf("registrationName" to RNGestureHandlerStateChangeEvent.EVENT_NAME))
30
45
 
31
46
  companion object {
32
- const val REACT_CLASS = "GestureHandlerRootView"
47
+ const val REACT_CLASS = "RNGestureHandlerRootView"
33
48
  }
34
49
  }
@@ -0,0 +1,53 @@
1
+ GESTURE_HANDLER_MAIN_THIS_DIR := $(call my-dir)
2
+
3
+ include $(REACT_ANDROID_DIR)/Android-prebuilt.mk
4
+
5
+ # libreact_render_uimanager
6
+ include $(CLEAR_VARS)
7
+ LOCAL_MODULE := libreact_render_uimanager
8
+ LOCAL_SRC_FILES := $(REACT_NDK_EXPORT_DIR)/$(TARGET_ARCH_ABI)/libreact_render_uimanager.so
9
+ LOCAL_EXPORT_C_INCLUDES := \
10
+ $(REACT_COMMON_DIR)/react/renderer/uimanager
11
+ include $(PREBUILT_SHARED_LIBRARY)
12
+ # end libreact_render_uimanager
13
+
14
+ include $(GESTURE_HANDLER_MAIN_THIS_DIR)/../../../build/generated/source/codegen/jni/Android.mk
15
+
16
+ include $(CLEAR_VARS)
17
+
18
+ LOCAL_PATH := $(GESTURE_HANDLER_MAIN_THIS_DIR)
19
+ LOCAL_MODULE := rngesturehandler_modules
20
+
21
+ LOCAL_C_INCLUDES := $(LOCAL_PATH) $(GENERATED_SRC_DIR)/codegen/jni
22
+ LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp)
23
+ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(GENERATED_SRC_DIR)/codegen/jni
24
+
25
+ # Please note as one of the library listed is libreact_codegen_samplelibrary
26
+ # This name will be generated as libreact_codegen_<library-name>
27
+ # where <library-name> is the one you specified in the Gradle configuration
28
+ LOCAL_SHARED_LIBRARIES := libjsi \
29
+ libfbjni \
30
+ libglog \
31
+ libfolly_json \
32
+ libyoga \
33
+ libreact_nativemodule_core \
34
+ libturbomodulejsijni \
35
+ librrc_view \
36
+ libreact_render_core \
37
+ libreact_render_graphics \
38
+ libfabricjni \
39
+ libfolly_futures \
40
+ libreact_debug \
41
+ libreact_render_componentregistry \
42
+ libreact_render_debug \
43
+ libruntimeexecutor \
44
+ libreact_render_mapbuffer \
45
+ libreact_render_uimanager \
46
+ libreact_codegen_rncore \
47
+ libreact_codegen_rngesturehandler
48
+
49
+ LOCAL_CFLAGS := \
50
+ -DLOG_TAG=\"ReactNative\"
51
+ LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall
52
+
53
+ include $(BUILD_SHARED_LIBRARY)
@@ -0,0 +1,9 @@
1
+ #include <fbjni/fbjni.h>
2
+
3
+ #include "RNGestureHandlerComponentsRegistry.h"
4
+
5
+ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
6
+ return facebook::jni::initialize(vm, [] {
7
+ facebook::react::RNGestureHandlerComponentsRegistry::registerNatives();
8
+ });
9
+ }
@@ -0,0 +1,71 @@
1
+ #include "RNGestureHandlerComponentsRegistry.h"
2
+
3
+ #include <CoreComponentsRegistry.h>
4
+ #include <fbjni/fbjni.h>
5
+ #include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
6
+ #include <react/renderer/components/rncore/ComponentDescriptors.h>
7
+ #include <react/renderer/components/rngesturehandler/ComponentDescriptors.h>
8
+
9
+ namespace facebook {
10
+ namespace react {
11
+
12
+ RNGestureHandlerComponentsRegistry::RNGestureHandlerComponentsRegistry(
13
+ ComponentFactory *delegate)
14
+ : delegate_(delegate) {}
15
+
16
+ std::shared_ptr<ComponentDescriptorProviderRegistry const>
17
+ RNGestureHandlerComponentsRegistry::sharedProviderRegistry() {
18
+ auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry();
19
+
20
+ // Gesture Handler
21
+ providerRegistry->add(concreteComponentDescriptorProvider<RNGestureHandlerRootViewComponentDescriptor>());
22
+ providerRegistry->add(concreteComponentDescriptorProvider<RNGestureHandlerButtonComponentDescriptor>());
23
+
24
+ return providerRegistry;
25
+ }
26
+
27
+ jni::local_ref<RNGestureHandlerComponentsRegistry::jhybriddata>
28
+ RNGestureHandlerComponentsRegistry::initHybrid(
29
+ jni::alias_ref<jclass>,
30
+ ComponentFactory *delegate) {
31
+ auto instance = makeCxxInstance(delegate);
32
+
33
+ auto buildRegistryFunction =
34
+ [](EventDispatcher::Weak const &eventDispatcher,
35
+ ContextContainer::Shared const &contextContainer)
36
+ -> ComponentDescriptorRegistry::Shared {
37
+ auto registry = RNGestureHandlerComponentsRegistry::sharedProviderRegistry()
38
+ ->createComponentDescriptorRegistry(
39
+ {eventDispatcher, contextContainer});
40
+
41
+ auto mutableRegistry =
42
+ std::const_pointer_cast<ComponentDescriptorRegistry>(registry);
43
+
44
+ mutableRegistry->setFallbackComponentDescriptor(
45
+ std::make_shared<UnimplementedNativeViewComponentDescriptor>(
46
+ ComponentDescriptorParameters{
47
+ eventDispatcher, contextContainer, nullptr}));
48
+
49
+ return registry;
50
+ };
51
+
52
+ delegate->buildRegistryFunction = buildRegistryFunction;
53
+ return instance;
54
+ }
55
+
56
+ void RNGestureHandlerComponentsRegistry::registerNatives() {
57
+ registerHybrid({
58
+ makeNativeMethod("initHybrid", RNGestureHandlerComponentsRegistry::initHybrid),
59
+ });
60
+
61
+ // This is a temporary solution that allows components exported by gesture-handler
62
+ // library to be added to the main component registry. This code is triggered
63
+ // when c++ gesture-handler library is initialized and is needed because RN's autolinking
64
+ // does not currently support Fabric components. As a consequence, users would need
65
+ // to manually put library initialization calls in their ReactNativeHost implementation
66
+ // which is undesirable.
67
+ sharedProviderRegistry();
68
+ }
69
+
70
+ } // namespace react
71
+ } // namespace facebook
@@ -0,0 +1,34 @@
1
+ #pragma once
2
+
3
+ #include <ComponentFactory.h>
4
+ #include <fbjni/fbjni.h>
5
+ #include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
6
+ #include <react/renderer/componentregistry/ComponentDescriptorRegistry.h>
7
+
8
+ namespace facebook {
9
+ namespace react {
10
+
11
+ class RNGestureHandlerComponentsRegistry
12
+ : public facebook::jni::HybridClass<RNGestureHandlerComponentsRegistry> {
13
+ public:
14
+ constexpr static auto kJavaDescriptor =
15
+ "Lcom/swmansion/gesturehandler/react/RNGestureHandlerComponentsRegistry;";
16
+
17
+ static void registerNatives();
18
+
19
+ RNGestureHandlerComponentsRegistry(ComponentFactory *delegate);
20
+
21
+ private:
22
+ friend HybridBase;
23
+
24
+ static std::shared_ptr<ComponentDescriptorProviderRegistry const> sharedProviderRegistry();
25
+
26
+ const ComponentFactory *delegate_;
27
+
28
+ static jni::local_ref<jhybriddata> initHybrid(
29
+ jni::alias_ref<jclass>,
30
+ ComponentFactory *delegate);
31
+ };
32
+
33
+ } // namespace react
34
+ } // namespace facebook