react-native-gesture-handler 2.14.1 → 2.16.0-rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) hide show
  1. package/README.md +1 -0
  2. package/RNGestureHandler.podspec +3 -24
  3. package/android/build.gradle +1 -1
  4. package/android/paper/src/main/java/com/swmansion/gesturehandler/NativeRNGestureHandlerModuleSpec.java +55 -0
  5. package/android/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerPackage.kt +69 -4
  6. package/android/src/main/java/com/swmansion/gesturehandler/core/FlingGestureHandler.kt +4 -0
  7. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +69 -0
  8. package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +37 -21
  9. package/android/src/main/java/com/swmansion/gesturehandler/core/LongPressGestureHandler.kt +5 -1
  10. package/android/src/main/java/com/swmansion/gesturehandler/core/PanGestureHandler.kt +5 -1
  11. package/android/src/main/java/com/swmansion/gesturehandler/core/TapGestureHandler.kt +7 -3
  12. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +61 -24
  13. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt +3 -2
  14. package/android/src/main/java/com/swmansion/gesturehandler/react/eventbuilders/GestureHandlerEventDataBuilder.kt +3 -0
  15. package/android/src/main/jni/cpp-adapter.cpp +18 -22
  16. package/{ios → apple}/Handlers/RNFlingHandler.m +29 -8
  17. package/{ios → apple}/Handlers/RNForceTouchHandler.m +28 -8
  18. package/{ios → apple}/Handlers/RNHoverHandler.m +28 -2
  19. package/{ios → apple}/Handlers/RNLongPressHandler.m +27 -5
  20. package/{ios → apple}/Handlers/RNManualHandler.m +25 -4
  21. package/{ios → apple}/Handlers/RNNativeViewHandler.mm +51 -13
  22. package/{ios → apple}/Handlers/RNPanHandler.m +106 -16
  23. package/apple/Handlers/RNPinchHandler.m +175 -0
  24. package/apple/Handlers/RNRotationHandler.m +169 -0
  25. package/{ios → apple}/Handlers/RNTapHandler.m +98 -26
  26. package/apple/RNGHUIKit.h +27 -0
  27. package/{ios → apple}/RNGestureHandler.h +12 -3
  28. package/{ios → apple}/RNGestureHandler.m +68 -7
  29. package/{ios → apple}/RNGestureHandlerButton.h +4 -1
  30. package/{ios → apple}/RNGestureHandlerButton.m +12 -4
  31. package/{ios → apple}/RNGestureHandlerButtonManager.m +4 -2
  32. package/{ios → apple}/RNGestureHandlerEvents.h +19 -10
  33. package/{ios → apple}/RNGestureHandlerEvents.m +29 -11
  34. package/{ios → apple}/RNGestureHandlerManager.h +7 -2
  35. package/{ios → apple}/RNGestureHandlerManager.mm +78 -17
  36. package/apple/RNGestureHandlerModule.h +19 -0
  37. package/{ios → apple}/RNGestureHandlerModule.mm +69 -69
  38. package/{ios → apple}/RNGestureHandlerPointerTracker.h +5 -5
  39. package/{ios → apple}/RNGestureHandlerPointerTracker.m +19 -14
  40. package/apple/RNGestureHandlerPointerType.h +8 -0
  41. package/{ios → apple}/RNGestureHandlerRegistry.h +1 -1
  42. package/{ios → apple}/RNGestureHandlerRegistry.m +1 -1
  43. package/{ios → apple}/RNManualActivationRecognizer.h +8 -0
  44. package/{ios → apple}/RNManualActivationRecognizer.m +27 -7
  45. package/{ios → apple}/RNRootViewGestureRecognizer.m +72 -4
  46. package/lib/commonjs/PointerType.js +16 -0
  47. package/lib/commonjs/PointerType.js.map +1 -0
  48. package/lib/commonjs/RNGestureHandlerModule.js +5 -18
  49. package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
  50. package/lib/commonjs/RNGestureHandlerModule.windows.js +10 -102
  51. package/lib/commonjs/RNGestureHandlerModule.windows.js.map +1 -1
  52. package/lib/commonjs/components/DrawerLayout.js +2 -0
  53. package/lib/commonjs/components/DrawerLayout.js.map +1 -1
  54. package/lib/commonjs/components/GestureHandlerRootView.android.js +17 -2
  55. package/lib/commonjs/components/GestureHandlerRootView.android.js.map +1 -1
  56. package/lib/commonjs/components/GestureHandlerRootView.js +15 -2
  57. package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
  58. package/lib/commonjs/components/GestureHandlerRootView.web.js +15 -2
  59. package/lib/commonjs/components/GestureHandlerRootView.web.js.map +1 -1
  60. package/lib/commonjs/getShadowNodeFromRef.js +19 -2
  61. package/lib/commonjs/getShadowNodeFromRef.js.map +1 -1
  62. package/lib/commonjs/handlers/createHandler.js +5 -0
  63. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  64. package/lib/commonjs/handlers/gestureHandlerCommon.js +1 -1
  65. package/lib/commonjs/handlers/gestureHandlerCommon.js.map +1 -1
  66. package/lib/commonjs/handlers/gestures/GestureDetector.js +11 -1
  67. package/lib/commonjs/handlers/gestures/GestureDetector.js.map +1 -1
  68. package/lib/commonjs/handlers/gestures/gesture.js +5 -0
  69. package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
  70. package/lib/commonjs/index.js +16 -0
  71. package/lib/commonjs/index.js.map +1 -1
  72. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +13 -0
  73. package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -0
  74. package/lib/commonjs/web/handlers/FlingGestureHandler.js +4 -0
  75. package/lib/commonjs/web/handlers/FlingGestureHandler.js.map +1 -1
  76. package/lib/commonjs/web/handlers/GestureHandler.js +19 -4
  77. package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
  78. package/lib/commonjs/web/handlers/LongPressGestureHandler.js +8 -6
  79. package/lib/commonjs/web/handlers/LongPressGestureHandler.js.map +1 -1
  80. package/lib/commonjs/web/handlers/PanGestureHandler.js +4 -0
  81. package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
  82. package/lib/commonjs/web/handlers/TapGestureHandler.js +4 -0
  83. package/lib/commonjs/web/handlers/TapGestureHandler.js.map +1 -1
  84. package/lib/commonjs/web/interfaces.js +12 -24
  85. package/lib/commonjs/web/interfaces.js.map +1 -1
  86. package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js +3 -3
  87. package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js.map +1 -1
  88. package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js +35 -0
  89. package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js.map +1 -1
  90. package/lib/commonjs/web/tools/NodeManager.js +3 -2
  91. package/lib/commonjs/web/tools/NodeManager.js.map +1 -1
  92. package/lib/commonjs/web/tools/PointerEventManager.js +40 -10
  93. package/lib/commonjs/web/tools/PointerEventManager.js.map +1 -1
  94. package/lib/commonjs/web/tools/TouchEventManager.js +3 -2
  95. package/lib/commonjs/web/tools/TouchEventManager.js.map +1 -1
  96. package/lib/commonjs/web/utils.js +6 -0
  97. package/lib/commonjs/web/utils.js.map +1 -1
  98. package/lib/module/PointerType.js +9 -0
  99. package/lib/module/PointerType.js.map +1 -0
  100. package/lib/module/RNGestureHandlerModule.js +4 -18
  101. package/lib/module/RNGestureHandlerModule.js.map +1 -1
  102. package/lib/module/RNGestureHandlerModule.windows.js +10 -81
  103. package/lib/module/RNGestureHandlerModule.windows.js.map +1 -1
  104. package/lib/module/components/DrawerLayout.js +2 -0
  105. package/lib/module/components/DrawerLayout.js.map +1 -1
  106. package/lib/module/components/GestureHandlerRootView.android.js +15 -2
  107. package/lib/module/components/GestureHandlerRootView.android.js.map +1 -1
  108. package/lib/module/components/GestureHandlerRootView.js +15 -3
  109. package/lib/module/components/GestureHandlerRootView.js.map +1 -1
  110. package/lib/module/components/GestureHandlerRootView.web.js +15 -3
  111. package/lib/module/components/GestureHandlerRootView.web.js.map +1 -1
  112. package/lib/module/getShadowNodeFromRef.js +19 -2
  113. package/lib/module/getShadowNodeFromRef.js.map +1 -1
  114. package/lib/module/handlers/createHandler.js +6 -1
  115. package/lib/module/handlers/createHandler.js.map +1 -1
  116. package/lib/module/handlers/gestureHandlerCommon.js +1 -1
  117. package/lib/module/handlers/gestureHandlerCommon.js.map +1 -1
  118. package/lib/module/handlers/gestures/GestureDetector.js +11 -1
  119. package/lib/module/handlers/gestures/GestureDetector.js.map +1 -1
  120. package/lib/module/handlers/gestures/gesture.js +5 -0
  121. package/lib/module/handlers/gestures/gesture.js.map +1 -1
  122. package/lib/module/index.js +2 -0
  123. package/lib/module/index.js.map +1 -1
  124. package/lib/module/specs/NativeRNGestureHandlerModule.js +3 -0
  125. package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -0
  126. package/lib/module/web/handlers/FlingGestureHandler.js +4 -0
  127. package/lib/module/web/handlers/FlingGestureHandler.js.map +1 -1
  128. package/lib/module/web/handlers/GestureHandler.js +18 -4
  129. package/lib/module/web/handlers/GestureHandler.js.map +1 -1
  130. package/lib/module/web/handlers/LongPressGestureHandler.js +8 -5
  131. package/lib/module/web/handlers/LongPressGestureHandler.js.map +1 -1
  132. package/lib/module/web/handlers/PanGestureHandler.js +4 -0
  133. package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
  134. package/lib/module/web/handlers/TapGestureHandler.js +4 -0
  135. package/lib/module/web/handlers/TapGestureHandler.js.map +1 -1
  136. package/lib/module/web/interfaces.js +9 -20
  137. package/lib/module/web/interfaces.js.map +1 -1
  138. package/lib/module/web/tools/GestureHandlerOrchestrator.js +2 -2
  139. package/lib/module/web/tools/GestureHandlerOrchestrator.js.map +1 -1
  140. package/lib/module/web/tools/GestureHandlerWebDelegate.js +34 -0
  141. package/lib/module/web/tools/GestureHandlerWebDelegate.js.map +1 -1
  142. package/lib/module/web/tools/NodeManager.js +3 -2
  143. package/lib/module/web/tools/NodeManager.js.map +1 -1
  144. package/lib/module/web/tools/PointerEventManager.js +41 -12
  145. package/lib/module/web/tools/PointerEventManager.js.map +1 -1
  146. package/lib/module/web/tools/TouchEventManager.js +2 -2
  147. package/lib/module/web/tools/TouchEventManager.js.map +1 -1
  148. package/lib/module/web/utils.js +2 -0
  149. package/lib/module/web/utils.js.map +1 -1
  150. package/lib/typescript/PointerType.d.ts +6 -0
  151. package/lib/typescript/RNGestureHandlerModule.d.ts +2 -13
  152. package/lib/typescript/RNGestureHandlerModule.windows.d.ts +5 -21
  153. package/lib/typescript/components/DrawerLayout.d.ts +11 -0
  154. package/lib/typescript/components/GestureHandlerRootView.android.d.ts +1 -1
  155. package/lib/typescript/components/GestureHandlerRootView.d.ts +1 -1
  156. package/lib/typescript/components/GestureHandlerRootView.web.d.ts +1 -1
  157. package/lib/typescript/getShadowNodeFromRef.d.ts +1 -1
  158. package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +1 -1
  159. package/lib/typescript/handlers/PanGestureHandler.d.ts +1 -1
  160. package/lib/typescript/handlers/gestureHandlerCommon.d.ts +6 -1
  161. package/lib/typescript/handlers/gestures/GestureDetector.d.ts +2 -1
  162. package/lib/typescript/handlers/gestures/gesture.d.ts +2 -0
  163. package/lib/typescript/index.d.ts +2 -0
  164. package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +14 -0
  165. package/lib/typescript/web/handlers/GestureHandler.d.ts +4 -1
  166. package/lib/typescript/web/interfaces.d.ts +10 -14
  167. package/lib/typescript/web/tools/GestureHandlerDelegate.d.ts +2 -0
  168. package/lib/typescript/web/tools/GestureHandlerWebDelegate.d.ts +7 -0
  169. package/lib/typescript/web/tools/PointerEventManager.d.ts +2 -0
  170. package/lib/typescript/web/utils.d.ts +2 -0
  171. package/package.json +14 -11
  172. package/src/PointerType.ts +6 -0
  173. package/src/RNGestureHandlerModule.ts +4 -49
  174. package/src/RNGestureHandlerModule.windows.ts +18 -100
  175. package/src/components/DrawerLayout.tsx +15 -0
  176. package/src/components/GestureHandlerRootView.android.tsx +13 -5
  177. package/src/components/GestureHandlerRootView.tsx +10 -5
  178. package/src/components/GestureHandlerRootView.web.tsx +10 -5
  179. package/src/getShadowNodeFromRef.ts +28 -6
  180. package/src/handlers/createHandler.tsx +6 -0
  181. package/src/handlers/gestureHandlerCommon.ts +7 -0
  182. package/src/handlers/gestures/GestureDetector.tsx +16 -2
  183. package/src/handlers/gestures/gesture.ts +6 -0
  184. package/src/index.ts +2 -0
  185. package/src/specs/NativeRNGestureHandlerModule.ts +26 -0
  186. package/src/web/handlers/FlingGestureHandler.ts +4 -0
  187. package/src/web/handlers/GestureHandler.ts +20 -2
  188. package/src/web/handlers/LongPressGestureHandler.ts +8 -5
  189. package/src/web/handlers/PanGestureHandler.ts +4 -0
  190. package/src/web/handlers/TapGestureHandler.ts +4 -0
  191. package/src/web/interfaces.ts +12 -17
  192. package/src/web/tools/GestureHandlerDelegate.ts +3 -0
  193. package/src/web/tools/GestureHandlerOrchestrator.ts +2 -2
  194. package/src/web/tools/GestureHandlerWebDelegate.ts +39 -0
  195. package/src/web/tools/NodeManager.ts +5 -1
  196. package/src/web/tools/PointerEventManager.ts +46 -10
  197. package/src/web/tools/TouchEventManager.ts +2 -8
  198. package/src/web/utils.ts +9 -0
  199. package/ios/Handlers/RNPinchHandler.m +0 -95
  200. package/ios/Handlers/RNRotationHandler.m +0 -93
  201. package/ios/RNGestureHandlerModule.h +0 -7
  202. package/lib/commonjs/RNGestureHandlerModule.macos.js +0 -149
  203. package/lib/commonjs/RNGestureHandlerModule.macos.js.map +0 -1
  204. package/lib/module/RNGestureHandlerModule.macos.js +0 -110
  205. package/lib/module/RNGestureHandlerModule.macos.js.map +0 -1
  206. package/lib/typescript/RNGestureHandlerModule.macos.d.ts +0 -47
  207. package/src/RNGestureHandlerModule.macos.ts +0 -133
  208. /package/{ios → apple}/Handlers/RNFlingHandler.h +0 -0
  209. /package/{ios → apple}/Handlers/RNForceTouchHandler.h +0 -0
  210. /package/{ios → apple}/Handlers/RNHoverHandler.h +0 -0
  211. /package/{ios → apple}/Handlers/RNLongPressHandler.h +0 -0
  212. /package/{ios → apple}/Handlers/RNManualHandler.h +0 -0
  213. /package/{ios → apple}/Handlers/RNNativeViewHandler.h +0 -0
  214. /package/{ios → apple}/Handlers/RNPanHandler.h +0 -0
  215. /package/{ios → apple}/Handlers/RNPinchHandler.h +0 -0
  216. /package/{ios → apple}/Handlers/RNRotationHandler.h +0 -0
  217. /package/{ios → apple}/Handlers/RNTapHandler.h +0 -0
  218. /package/{ios → apple}/RNGHTouchEventType.h +0 -0
  219. /package/{ios → apple}/RNGestureHandler.xcodeproj/project.pbxproj +0 -0
  220. /package/{ios → apple}/RNGestureHandler.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -0
  221. /package/{ios → apple}/RNGestureHandlerActionType.h +0 -0
  222. /package/{ios → apple}/RNGestureHandlerButtonComponentView.h +0 -0
  223. /package/{ios → apple}/RNGestureHandlerButtonComponentView.mm +0 -0
  224. /package/{ios → apple}/RNGestureHandlerButtonManager.h +0 -0
  225. /package/{ios → apple}/RNGestureHandlerDirection.h +0 -0
  226. /package/{ios → apple}/RNGestureHandlerRootViewComponentView.mm +0 -0
  227. /package/{ios → apple}/RNGestureHandlerState.h +0 -0
  228. /package/{ios → apple}/RNGestureHandlerStateManager.h +0 -0
  229. /package/{ios → apple}/RNRootViewGestureRecognizer.h +0 -0
package/README.md CHANGED
@@ -39,6 +39,7 @@ You will need to have an Android or iOS device or emulator connected as well as
39
39
 
40
40
  | version | react-native version |
41
41
  | ------- | -------------------- |
42
+ | 2.14.0+ | 0.67.0+ |
42
43
  | 2.10.0+ | 0.64.0+ |
43
44
  | 2.0.0+ | 0.63.0+ |
44
45
  | 1.4.0+ | 0.60.0+ |
@@ -1,8 +1,5 @@
1
1
  require "json"
2
2
 
3
- new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
4
- apple_platform = new_arch_enabled ? '11.0' : '9.0'
5
-
6
3
  Pod::Spec.new do |s|
7
4
  # NPM package specification
8
5
  package = JSON.parse(File.read(File.join(File.dirname(__FILE__), "package.json")))
@@ -14,31 +11,13 @@ Pod::Spec.new do |s|
14
11
  s.license = "MIT"
15
12
  s.author = { package["author"]["name"] => package["author"]["email"] }
16
13
  s.source = { :git => "https://github.com/software-mansion/react-native-gesture-handler", :tag => "#{s.version}" }
17
- s.source_files = "ios/**/*.{h,m,mm}"
14
+ s.source_files = "apple/**/*.{h,m,mm}"
18
15
  s.requires_arc = true
19
- s.platforms = { ios: apple_platform, tvos: apple_platform }
16
+ s.platforms = { ios: '11.0', tvos: '11.0', osx: '10.15', visionos: '1.0' }
20
17
 
21
18
  if defined?(install_modules_dependencies()) != nil
22
19
  install_modules_dependencies(s);
23
20
  else
24
- if new_arch_enabled
25
- folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
26
-
27
- s.pod_target_xcconfig = {
28
- 'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/boost" "$(PODS_ROOT)/boost-for-react-native" "$(PODS_ROOT)/RCT-Folly"',
29
- 'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
30
- }
31
- s.compiler_flags = folly_compiler_flags + ' -DRCT_NEW_ARCH_ENABLED'
32
-
33
- s.dependency "React"
34
- s.dependency "React-RCTFabric" # This is for fabric component
35
- s.dependency "React-Codegen"
36
- s.dependency "RCT-Folly"
37
- s.dependency "RCTRequired"
38
- s.dependency "RCTTypeSafety"
39
- s.dependency "ReactCommon/turbomodule/core"
40
- else
41
- s.dependency "React-Core"
42
- end
21
+ s.dependency "React-Core"
43
22
  end
44
23
  end
@@ -136,7 +136,7 @@ android {
136
136
  var appProject = rootProject.allprojects.find {it.plugins.hasPlugin('com.android.application')}
137
137
  externalNativeBuild {
138
138
  cmake {
139
- cppFlags "-O2", "-frtti", "-fexceptions", "-Wall", "-Werror", "-std=c++17", "-DANDROID"
139
+ cppFlags "-O2", "-frtti", "-fexceptions", "-Wall", "-Werror", "-std=c++20", "-DANDROID"
140
140
  arguments "-DAPP_BUILD_DIR=${appProject.buildDir}",
141
141
  "-DREACT_NATIVE_DIR=${REACT_NATIVE_DIR}",
142
142
  "-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}",
@@ -0,0 +1,55 @@
1
+ package com.swmansion.gesturehandler;
2
+
3
+ import com.facebook.proguard.annotations.DoNotStrip;
4
+ import com.facebook.react.bridge.ReactApplicationContext;
5
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
6
+ import com.facebook.react.bridge.ReactMethod;
7
+ import com.facebook.react.bridge.ReadableMap;
8
+ import com.facebook.react.turbomodule.core.interfaces.TurboModule;
9
+ import javax.annotation.Nonnull;
10
+ import com.facebook.react.bridge.ReactMethod;
11
+
12
+ public abstract class NativeRNGestureHandlerModuleSpec extends ReactContextBaseJavaModule implements TurboModule {
13
+ public static final String NAME = "RNGestureHandlerModule";
14
+
15
+ public NativeRNGestureHandlerModuleSpec(ReactApplicationContext reactContext) {
16
+ super(reactContext);
17
+ }
18
+
19
+ @Override
20
+ public @Nonnull String getName() {
21
+ return NAME;
22
+ }
23
+
24
+ @DoNotStrip
25
+ @ReactMethod
26
+ public abstract void handleSetJSResponder(double tag, boolean blockNativeResponder);
27
+
28
+ @DoNotStrip
29
+ @ReactMethod
30
+ public abstract void handleClearJSResponder();
31
+
32
+ @DoNotStrip
33
+ @ReactMethod
34
+ public abstract void createGestureHandler(String handlerName, double handlerTag, ReadableMap config);
35
+
36
+ @DoNotStrip
37
+ @ReactMethod
38
+ public abstract void attachGestureHandler(double handlerTag, double newView, double actionType);
39
+
40
+ @DoNotStrip
41
+ @ReactMethod
42
+ public abstract void updateGestureHandler(double handlerTag, ReadableMap newConfig);
43
+
44
+ @DoNotStrip
45
+ @ReactMethod
46
+ public abstract void dropGestureHandler(double handlerTag);
47
+
48
+ @DoNotStrip
49
+ @ReactMethod
50
+ public abstract boolean install();
51
+
52
+ @DoNotStrip
53
+ @ReactMethod
54
+ public abstract void flushOperations();
55
+ }
@@ -1,16 +1,34 @@
1
1
  package com.swmansion.gesturehandler
2
2
 
3
- import com.facebook.react.ReactPackage
3
+ import com.facebook.react.TurboReactPackage
4
+ import com.facebook.react.ViewManagerOnDemandReactPackage
5
+ import com.facebook.react.bridge.ModuleSpec
4
6
  import com.facebook.react.bridge.NativeModule
5
7
  import com.facebook.react.bridge.ReactApplicationContext
8
+ import com.facebook.react.module.annotations.ReactModule
9
+ import com.facebook.react.module.annotations.ReactModuleList
10
+ import com.facebook.react.module.model.ReactModuleInfo
11
+ import com.facebook.react.module.model.ReactModuleInfoProvider
6
12
  import com.facebook.react.uimanager.ViewManager
7
13
  import com.swmansion.gesturehandler.react.RNGestureHandlerButtonViewManager
8
14
  import com.swmansion.gesturehandler.react.RNGestureHandlerModule
9
15
  import com.swmansion.gesturehandler.react.RNGestureHandlerRootViewManager
10
16
 
11
- class RNGestureHandlerPackage : ReactPackage {
12
- override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
13
- return listOf<NativeModule>(RNGestureHandlerModule(reactContext))
17
+ @ReactModuleList(
18
+ nativeModules = [
19
+ RNGestureHandlerModule::class
20
+ ]
21
+ )
22
+ class RNGestureHandlerPackage : TurboReactPackage(), ViewManagerOnDemandReactPackage {
23
+ private val viewManagers: Map<String, ModuleSpec> by lazy {
24
+ mapOf(
25
+ RNGestureHandlerRootViewManager.REACT_CLASS to ModuleSpec.viewManagerSpec {
26
+ RNGestureHandlerRootViewManager()
27
+ },
28
+ RNGestureHandlerButtonViewManager.REACT_CLASS to ModuleSpec.viewManagerSpec {
29
+ RNGestureHandlerButtonViewManager()
30
+ }
31
+ )
14
32
  }
15
33
 
16
34
  override fun createViewManagers(reactContext: ReactApplicationContext) =
@@ -18,4 +36,51 @@ class RNGestureHandlerPackage : ReactPackage {
18
36
  RNGestureHandlerRootViewManager(),
19
37
  RNGestureHandlerButtonViewManager()
20
38
  )
39
+
40
+ override fun getViewManagerNames(reactContext: ReactApplicationContext?) =
41
+ viewManagers.keys.toList()
42
+
43
+ override fun getViewManagers(reactContext: ReactApplicationContext?): MutableList<ModuleSpec> =
44
+ viewManagers.values.toMutableList()
45
+
46
+ override fun createViewManager(
47
+ reactContext: ReactApplicationContext?,
48
+ viewManagerName: String?
49
+ ) = viewManagers[viewManagerName]?.provider?.get() as? ViewManager<*, *>
50
+
51
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
52
+ return if (name == RNGestureHandlerModule.NAME) {
53
+ RNGestureHandlerModule(reactContext)
54
+ } else {
55
+ null
56
+ }
57
+ }
58
+
59
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
60
+ try {
61
+ val reactModuleInfoProviderClass =
62
+ Class.forName("com.swmansion.gesturehandler.RNGestureHandlerPackage$\$ReactModuleInfoProvider")
63
+ return reactModuleInfoProviderClass.newInstance() as ReactModuleInfoProvider
64
+ } catch (e: ClassNotFoundException) {
65
+ return ReactModuleInfoProvider {
66
+ val reactModule: ReactModule = RNGestureHandlerModule::class.java.getAnnotation(ReactModule::class.java)!!
67
+
68
+ mutableMapOf(
69
+ RNGestureHandlerModule.NAME to ReactModuleInfo(
70
+ reactModule.name,
71
+ RNGestureHandlerModule::class.java.name,
72
+ reactModule.canOverrideExistingModule,
73
+ reactModule.needsEagerInit,
74
+ reactModule.hasConstants,
75
+ reactModule.isCxxModule,
76
+ true
77
+ )
78
+ )
79
+ }
80
+ } catch (e: InstantiationException) {
81
+ throw RuntimeException("No ReactModuleInfoProvider for RNGestureHandlerPackage$\$ReactModuleInfoProvider", e)
82
+ } catch (e: IllegalAccessException) {
83
+ throw RuntimeException("No ReactModuleInfoProvider for RNGestureHandlerPackage$\$ReactModuleInfoProvider", e)
84
+ }
85
+ }
21
86
  }
@@ -67,6 +67,10 @@ class FlingGestureHandler : GestureHandler<FlingGestureHandler>() {
67
67
  }
68
68
 
69
69
  override fun onHandle(event: MotionEvent, sourceEvent: MotionEvent) {
70
+ if (!shouldActivateWithMouse(sourceEvent)) {
71
+ return
72
+ }
73
+
70
74
  val state = state
71
75
  if (state == STATE_UNDETERMINED) {
72
76
  startFling(sourceEvent)
@@ -5,6 +5,7 @@ import android.content.Context
5
5
  import android.content.ContextWrapper
6
6
  import android.graphics.PointF
7
7
  import android.graphics.Rect
8
+ import android.os.Build
8
9
  import android.view.MotionEvent
9
10
  import android.view.MotionEvent.PointerCoords
10
11
  import android.view.MotionEvent.PointerProperties
@@ -67,6 +68,10 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
67
68
  protected var orchestrator: GestureHandlerOrchestrator? = null
68
69
  private var onTouchEventListener: OnTouchEventListener? = null
69
70
  private var interactionController: GestureHandlerInteractionController? = null
71
+ var pointerType: Int = POINTER_TYPE_OTHER
72
+ private set
73
+
74
+ protected var mouseButton = 0
70
75
 
71
76
  @Suppress("UNCHECKED_CAST")
72
77
  protected fun self(): ConcreteGestureHandlerT = this as ConcreteGestureHandlerT
@@ -159,6 +164,10 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
159
164
  fun setInteractionController(controller: GestureHandlerInteractionController?): ConcreteGestureHandlerT =
160
165
  applySelf { interactionController = controller }
161
166
 
167
+ fun setMouseButton(mouseButton: Int) = apply {
168
+ this.mouseButton = mouseButton
169
+ }
170
+
162
171
  fun prepare(view: View?, orchestrator: GestureHandlerOrchestrator?) {
163
172
  check(!(this.view != null || this.orchestrator != null)) { "Already prepared or hasn't been reset" }
164
173
  Arrays.fill(trackedPointerIDs, -1)
@@ -371,6 +380,11 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
371
380
  lastAbsolutePositionY = GestureUtils.getLastPointerY(adaptedTransformedEvent, true)
372
381
  lastEventOffsetX = adaptedTransformedEvent.rawX - adaptedTransformedEvent.x
373
382
  lastEventOffsetY = adaptedTransformedEvent.rawY - adaptedTransformedEvent.y
383
+
384
+ if (sourceEvent.action == MotionEvent.ACTION_DOWN || sourceEvent.action == MotionEvent.ACTION_HOVER_ENTER || sourceEvent.action == MotionEvent.ACTION_HOVER_MOVE) {
385
+ setPointerType(sourceEvent)
386
+ }
387
+
374
388
  if (sourceEvent.action == MotionEvent.ACTION_HOVER_ENTER ||
375
389
  sourceEvent.action == MotionEvent.ACTION_HOVER_MOVE ||
376
390
  sourceEvent.action == MotionEvent.ACTION_HOVER_EXIT
@@ -688,6 +702,46 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
688
702
  protected open fun onReset() {}
689
703
  protected open fun onCancel() {}
690
704
 
705
+ private fun isButtonInConfig(clickedButton: Int): Boolean {
706
+ if (mouseButton == 0) {
707
+ return clickedButton == MotionEvent.BUTTON_PRIMARY
708
+ }
709
+
710
+ return clickedButton and mouseButton != 0
711
+ }
712
+
713
+ protected fun shouldActivateWithMouse(sourceEvent: MotionEvent): Boolean {
714
+ // While using mouse, we get both sets of events, for example ACTION_DOWN and ACTION_BUTTON_PRESS. That's why we want to take actions to only one of them.
715
+ // On API >= 23, we will use events with infix BUTTON, otherwise we use standard action events (like ACTION_DOWN).
716
+
717
+ with(sourceEvent) {
718
+ // To use actionButton, we need API >= 23.
719
+ if (getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
720
+ // While using mouse, we want to ignore default events for touch.
721
+ if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP || action == MotionEvent.ACTION_POINTER_DOWN) {
722
+ return@shouldActivateWithMouse false
723
+ }
724
+
725
+ // We don't want to do anything if wrong button was clicked. If we received event for BUTTON, we have to use actionButton to get which one was clicked.
726
+ if (action != MotionEvent.ACTION_MOVE && !isButtonInConfig(actionButton)) {
727
+ return@shouldActivateWithMouse false
728
+ }
729
+
730
+ // When we receive ACTION_MOVE, we have to check buttonState field.
731
+ if (action == MotionEvent.ACTION_MOVE && !isButtonInConfig(buttonState)) {
732
+ return@shouldActivateWithMouse false
733
+ }
734
+ } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
735
+ // We do not fully support mouse below API 23, so we will ignore BUTTON events.
736
+ if (action == MotionEvent.ACTION_BUTTON_PRESS || action == MotionEvent.ACTION_BUTTON_RELEASE) {
737
+ return@shouldActivateWithMouse false
738
+ }
739
+ }
740
+ }
741
+
742
+ return true
743
+ }
744
+
691
745
  /**
692
746
  * Transforms a point in the coordinate space of the wrapperView (GestureHandlerRootView) to
693
747
  * coordinate space of the view the gesture is attached to.
@@ -721,6 +775,17 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
721
775
  isWithinBounds = false
722
776
  }
723
777
 
778
+ private fun setPointerType(event: MotionEvent) {
779
+ val pointerIndex = event.actionIndex
780
+
781
+ pointerType = when (event.getToolType(pointerIndex)) {
782
+ MotionEvent.TOOL_TYPE_FINGER -> POINTER_TYPE_TOUCH
783
+ MotionEvent.TOOL_TYPE_STYLUS -> POINTER_TYPE_STYLUS
784
+ MotionEvent.TOOL_TYPE_MOUSE -> POINTER_TYPE_MOUSE
785
+ else -> POINTER_TYPE_OTHER
786
+ }
787
+ }
788
+
724
789
  fun setOnTouchEventListener(listener: OnTouchEventListener?): GestureHandler<*> {
725
790
  onTouchEventListener = listener
726
791
  return this
@@ -763,6 +828,10 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
763
828
  const val ACTION_TYPE_NATIVE_ANIMATED_EVENT = 2
764
829
  const val ACTION_TYPE_JS_FUNCTION_OLD_API = 3
765
830
  const val ACTION_TYPE_JS_FUNCTION_NEW_API = 4
831
+ const val POINTER_TYPE_TOUCH = 0
832
+ const val POINTER_TYPE_STYLUS = 1
833
+ const val POINTER_TYPE_MOUSE = 2
834
+ const val POINTER_TYPE_OTHER = 3
766
835
  private const val MAX_POINTERS_COUNT = 12
767
836
  private lateinit var pointerProps: Array<PointerProperties?>
768
837
  private lateinit var pointerCoords: Array<PointerCoords?>
@@ -101,27 +101,33 @@ class GestureHandlerOrchestrator(
101
101
  fun onHandlerStateChange(handler: GestureHandler<*>, newState: Int, prevState: Int) {
102
102
  handlingChangeSemaphore += 1
103
103
  if (isFinished(newState)) {
104
+ // We have to loop through copy in order to avoid modifying collection
105
+ // while iterating over its elements
106
+ val currentlyAwaitingHandlers = awaitingHandlers.toList()
107
+
104
108
  // if there were handlers awaiting completion of this handler, we can trigger active state
105
- for (otherHandler in awaitingHandlers) {
106
- if (shouldHandlerWaitForOther(otherHandler, handler)) {
107
- if (newState == GestureHandler.STATE_END) {
108
- // gesture has ended, we need to kill the awaiting handler
109
- otherHandler.cancel()
110
- if (otherHandler.state == GestureHandler.STATE_END) {
111
- // Handle edge case, where discrete gestures end immediately after activation thus
112
- // their state is set to END and when the gesture they are waiting for activates they
113
- // should be cancelled, however `cancel` was never sent as gestures were already in the END state.
114
- // Send synthetic BEGAN -> CANCELLED to properly handle JS logic
115
- otherHandler.dispatchStateChange(
116
- GestureHandler.STATE_CANCELLED,
117
- GestureHandler.STATE_BEGAN
118
- )
119
- }
120
- otherHandler.isAwaiting = false
121
- } else {
122
- // gesture has failed recognition, we may try activating
123
- tryActivate(otherHandler)
109
+ for (otherHandler in currentlyAwaitingHandlers) {
110
+ if (!shouldHandlerWaitForOther(otherHandler, handler)) {
111
+ continue
112
+ }
113
+
114
+ if (newState == GestureHandler.STATE_END) {
115
+ // gesture has ended, we need to kill the awaiting handler
116
+ otherHandler.cancel()
117
+ if (otherHandler.state == GestureHandler.STATE_END) {
118
+ // Handle edge case, where discrete gestures end immediately after activation thus
119
+ // their state is set to END and when the gesture they are waiting for activates they
120
+ // should be cancelled, however `cancel` was never sent as gestures were already in the END state.
121
+ // Send synthetic BEGAN -> CANCELLED to properly handle JS logic
122
+ otherHandler.dispatchStateChange(
123
+ GestureHandler.STATE_CANCELLED,
124
+ GestureHandler.STATE_BEGAN
125
+ )
124
126
  }
127
+ otherHandler.isAwaiting = false
128
+ } else {
129
+ // gesture has failed recognition, we may try activating
130
+ tryActivate(otherHandler)
125
131
  }
126
132
  }
127
133
  cleanupAwaitingHandlers()
@@ -174,9 +180,19 @@ class GestureHandlerOrchestrator(
174
180
  }
175
181
  cleanupAwaitingHandlers()
176
182
 
177
- // Dispatch state change event if handler is no longer in the active state we should also
178
- // trigger END state change and UNDETERMINED state change if necessary
183
+ // At this point the waiting handler is allowed to activate, so we need to send BEGAN -> ACTIVE event
184
+ // as it wasn't sent before. If handler has finished recognizing the gesture before it was allowed to
185
+ // activate, we also need to send ACTIVE -> END and END -> UNDETERMINED events, as it was blocked from
186
+ // sending events while waiting.
187
+ // There is one catch though - if the handler failed or was cancelled while waiting, relevant event has
188
+ // already been sent. The following chain would result in artificially activating that handler after the
189
+ // failure logic was ran and we don't want to do that.
190
+ if (currentState == GestureHandler.STATE_FAILED || currentState == GestureHandler.STATE_CANCELLED) {
191
+ return
192
+ }
193
+
179
194
  handler.dispatchStateChange(GestureHandler.STATE_ACTIVE, GestureHandler.STATE_BEGAN)
195
+
180
196
  if (currentState != GestureHandler.STATE_ACTIVE) {
181
197
  handler.dispatchStateChange(GestureHandler.STATE_END, GestureHandler.STATE_ACTIVE)
182
198
  if (currentState != GestureHandler.STATE_END) {
@@ -38,6 +38,10 @@ class LongPressGestureHandler(context: Context) : GestureHandler<LongPressGestur
38
38
  }
39
39
 
40
40
  override fun onHandle(event: MotionEvent, sourceEvent: MotionEvent) {
41
+ if (!shouldActivateWithMouse(sourceEvent)) {
42
+ return
43
+ }
44
+
41
45
  if (state == STATE_UNDETERMINED) {
42
46
  previousTime = SystemClock.uptimeMillis()
43
47
  startTime = previousTime
@@ -51,7 +55,7 @@ class LongPressGestureHandler(context: Context) : GestureHandler<LongPressGestur
51
55
  activate()
52
56
  }
53
57
  }
54
- if (sourceEvent.actionMasked == MotionEvent.ACTION_UP) {
58
+ if (sourceEvent.actionMasked == MotionEvent.ACTION_UP || sourceEvent.actionMasked == MotionEvent.ACTION_BUTTON_RELEASE) {
55
59
  handler?.let {
56
60
  it.removeCallbacksAndMessages(null)
57
61
  handler = null
@@ -208,6 +208,10 @@ class PanGestureHandler(context: Context?) : GestureHandler<PanGestureHandler>()
208
208
  }
209
209
 
210
210
  override fun onHandle(event: MotionEvent, sourceEvent: MotionEvent) {
211
+ if (!shouldActivateWithMouse(sourceEvent)) {
212
+ return
213
+ }
214
+
211
215
  val state = state
212
216
  val action = sourceEvent.actionMasked
213
217
  if (action == MotionEvent.ACTION_POINTER_UP || action == MotionEvent.ACTION_POINTER_DOWN) {
@@ -246,7 +250,7 @@ class PanGestureHandler(context: Context?) : GestureHandler<PanGestureHandler>()
246
250
  velocityX = velocityTracker!!.xVelocity
247
251
  velocityY = velocityTracker!!.yVelocity
248
252
  }
249
- if (action == MotionEvent.ACTION_UP) {
253
+ if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_BUTTON_RELEASE) {
250
254
  if (state == STATE_ACTIVE) {
251
255
  end()
252
256
  } else {
@@ -105,6 +105,10 @@ class TapGestureHandler : GestureHandler<TapGestureHandler>() {
105
105
  }
106
106
 
107
107
  override fun onHandle(event: MotionEvent, sourceEvent: MotionEvent) {
108
+ if (!shouldActivateWithMouse(sourceEvent)) {
109
+ return
110
+ }
111
+
108
112
  val state = state
109
113
  val action = sourceEvent.actionMasked
110
114
  if (state == STATE_UNDETERMINED) {
@@ -130,14 +134,14 @@ class TapGestureHandler : GestureHandler<TapGestureHandler>() {
130
134
  if (shouldFail()) {
131
135
  fail()
132
136
  } else if (state == STATE_UNDETERMINED) {
133
- if (action == MotionEvent.ACTION_DOWN) {
137
+ if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_BUTTON_PRESS) {
134
138
  begin()
135
139
  }
136
140
  startTap()
137
141
  } else if (state == STATE_BEGAN) {
138
- if (action == MotionEvent.ACTION_UP) {
142
+ if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_BUTTON_RELEASE) {
139
143
  endTap()
140
- } else if (action == MotionEvent.ACTION_DOWN) {
144
+ } else if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_BUTTON_PRESS) {
141
145
  startTap()
142
146
  }
143
147
  }
@@ -6,7 +6,6 @@ import android.view.MotionEvent
6
6
  import com.facebook.react.ReactRootView
7
7
  import com.facebook.react.bridge.JSApplicationIllegalArgumentException
8
8
  import com.facebook.react.bridge.ReactApplicationContext
9
- import com.facebook.react.bridge.ReactContextBaseJavaModule
10
9
  import com.facebook.react.bridge.ReactMethod
11
10
  import com.facebook.react.bridge.ReadableMap
12
11
  import com.facebook.react.bridge.ReadableType
@@ -17,6 +16,7 @@ import com.facebook.react.uimanager.events.Event
17
16
  import com.facebook.soloader.SoLoader
18
17
  import com.swmansion.common.GestureHandlerStateManager
19
18
  import com.swmansion.gesturehandler.BuildConfig
19
+ import com.swmansion.gesturehandler.NativeRNGestureHandlerModuleSpec
20
20
  import com.swmansion.gesturehandler.ReanimatedEventDispatcher
21
21
  import com.swmansion.gesturehandler.core.FlingGestureHandler
22
22
  import com.swmansion.gesturehandler.core.GestureHandler
@@ -47,9 +47,9 @@ import com.swmansion.gesturehandler.react.eventbuilders.TapGestureHandlerEventDa
47
47
  // UIManagerModule.resolveRootTagFromReactTag() was deprecated and will be removed in the next RN release
48
48
  // ref: https://github.com/facebook/react-native/commit/acbf9e18ea666b07c1224a324602a41d0a66985e
49
49
  @Suppress("DEPRECATION")
50
- @ReactModule(name = RNGestureHandlerModule.MODULE_NAME)
50
+ @ReactModule(name = RNGestureHandlerModule.NAME)
51
51
  class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
52
- ReactContextBaseJavaModule(reactContext), GestureHandlerStateManager {
52
+ NativeRNGestureHandlerModuleSpec(reactContext), GestureHandlerStateManager {
53
53
  private abstract class HandlerFactory<T : GestureHandler<T>> {
54
54
  abstract val type: Class<T>
55
55
  abstract val name: String
@@ -71,6 +71,9 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
71
71
  if (config.hasKey(KEY_MANUAL_ACTIVATION)) {
72
72
  handler.setManualActivation(config.getBoolean(KEY_MANUAL_ACTIVATION))
73
73
  }
74
+ if (config.hasKey("mouseButton")) {
75
+ handler.setMouseButton(config.getInt("mouseButton"))
76
+ }
74
77
  }
75
78
 
76
79
  abstract fun createEventBuilder(handler: T): GestureHandlerEventDataBuilder<T>
@@ -331,15 +334,21 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
331
334
  private val interactionManager = RNGestureHandlerInteractionManager()
332
335
  private val roots: MutableList<RNGestureHandlerRootHelper> = ArrayList()
333
336
  private val reanimatedEventDispatcher = ReanimatedEventDispatcher()
334
- override fun getName() = MODULE_NAME
337
+ override fun getName() = NAME
335
338
 
336
- @ReactMethod
337
339
  @Suppress("UNCHECKED_CAST")
338
- fun <T : GestureHandler<T>> createGestureHandler(
340
+ private fun <T : GestureHandler<T>> createGestureHandlerHelper(
339
341
  handlerName: String,
340
342
  handlerTag: Int,
341
343
  config: ReadableMap,
342
344
  ) {
345
+
346
+ if (registry.getHandler(handlerTag) !== null) {
347
+ throw IllegalStateException(
348
+ "Handler with tag $handlerTag already exists. Please ensure that no Gesture instance is used across multiple GestureDetectors."
349
+ )
350
+ }
351
+
343
352
  for (handlerFactory in handlerFactories as Array<HandlerFactory<T>>) {
344
353
  if (handlerFactory.name == handlerName) {
345
354
  val handler = handlerFactory.create(reactApplicationContext).apply {
@@ -356,7 +365,21 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
356
365
  }
357
366
 
358
367
  @ReactMethod
359
- fun attachGestureHandler(handlerTag: Int, viewTag: Int, actionType: Int) {
368
+ override fun createGestureHandler(
369
+ handlerName: String,
370
+ handlerTagDouble: Double,
371
+ config: ReadableMap,
372
+ ) {
373
+ val handlerTag = handlerTagDouble.toInt()
374
+
375
+ createGestureHandlerHelper(handlerName, handlerTag, config)
376
+ }
377
+
378
+ @ReactMethod
379
+ override fun attachGestureHandler(handlerTagDouble: Double, viewTagDouble: Double, actionTypeDouble: Double) {
380
+ val handlerTag = handlerTagDouble.toInt()
381
+ val viewTag = viewTagDouble.toInt()
382
+ val actionType = actionTypeDouble.toInt()
360
383
  // We don't have to handle view flattening in any special way since handlers are stored as
361
384
  // a map: viewTag -> [handler]. If the view with attached handlers was to be flattened
362
385
  // then that viewTag simply wouldn't be visited when traversing the view hierarchy in the
@@ -366,9 +389,8 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
366
389
  }
367
390
  }
368
391
 
369
- @ReactMethod
370
392
  @Suppress("UNCHECKED_CAST")
371
- fun <T : GestureHandler<T>> updateGestureHandler(handlerTag: Int, config: ReadableMap) {
393
+ private fun <T : GestureHandler<T>> updateGestureHandlerHelper(handlerTag: Int, config: ReadableMap) {
372
394
  val handler = registry.getHandler(handlerTag) as T?
373
395
  if (handler != null) {
374
396
  val factory = findFactoryForHandler(handler)
@@ -381,19 +403,32 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
381
403
  }
382
404
 
383
405
  @ReactMethod
384
- fun dropGestureHandler(handlerTag: Int) {
406
+ override fun updateGestureHandler(handlerTagDouble: Double, config: ReadableMap) {
407
+ val handlerTag = handlerTagDouble.toInt()
408
+
409
+ updateGestureHandlerHelper(handlerTag, config)
410
+ }
411
+
412
+ @ReactMethod
413
+ override fun dropGestureHandler(handlerTagDouble: Double) {
414
+ val handlerTag = handlerTagDouble.toInt()
385
415
  interactionManager.dropRelationsForHandlerWithTag(handlerTag)
386
416
  registry.dropHandler(handlerTag)
387
417
  }
388
418
 
389
419
  @ReactMethod
390
- fun handleSetJSResponder(viewTag: Int, blockNativeResponder: Boolean) {
420
+ override fun handleSetJSResponder(viewTagDouble: Double, blockNativeResponder: Boolean) {
421
+ val viewTag = viewTagDouble.toInt()
391
422
  val rootView = findRootHelperForViewAncestor(viewTag)
392
423
  rootView?.handleSetJSResponder(viewTag, blockNativeResponder)
393
424
  }
394
425
 
395
426
  @ReactMethod
396
- fun handleClearJSResponder() {
427
+ override fun handleClearJSResponder() {
428
+ }
429
+
430
+ @ReactMethod
431
+ override fun flushOperations() {
397
432
  }
398
433
 
399
434
  override fun setGestureHandlerState(handlerTag: Int, newState: Int) {
@@ -409,16 +444,18 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
409
444
  }
410
445
 
411
446
  @ReactMethod(isBlockingSynchronousMethod = true)
412
- fun install(): Boolean {
413
- return try {
414
- SoLoader.loadLibrary("gesturehandler")
415
- val jsContext = reactApplicationContext.javaScriptContextHolder!!
416
- decorateRuntime(jsContext.get())
417
- true
418
- } catch (exception: Exception) {
419
- Log.w("[RNGestureHandler]", "Could not install JSI bindings.")
420
- false
447
+ override fun install(): Boolean {
448
+ reactApplicationContext.runOnJSQueueThread {
449
+ try {
450
+ SoLoader.loadLibrary("gesturehandler")
451
+ val jsContext = reactApplicationContext.javaScriptContextHolder!!
452
+ decorateRuntime(jsContext.get())
453
+ } catch (exception: Exception) {
454
+ Log.w("[RNGestureHandler]", "Could not install JSI bindings.")
455
+ }
421
456
  }
457
+
458
+ return true
422
459
  }
423
460
 
424
461
  private external fun decorateRuntime(jsiPtr: Long)
@@ -442,7 +479,7 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
442
479
  )
443
480
  }
444
481
 
445
- override fun onCatalystInstanceDestroy() {
482
+ override fun invalidate() {
446
483
  registry.dropAllHandlers()
447
484
  interactionManager.reset()
448
485
  synchronized(roots) {
@@ -455,7 +492,7 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
455
492
  }
456
493
  }
457
494
  }
458
- super.onCatalystInstanceDestroy()
495
+ super.invalidate()
459
496
  }
460
497
 
461
498
  fun registerRootHelper(root: RNGestureHandlerRootHelper) {
@@ -611,7 +648,7 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
611
648
  }
612
649
 
613
650
  companion object {
614
- const val MODULE_NAME = "RNGestureHandlerModule"
651
+ const val NAME = "RNGestureHandlerModule"
615
652
  private const val KEY_SHOULD_CANCEL_WHEN_OUTSIDE = "shouldCancelWhenOutside"
616
653
  private const val KEY_ENABLED = "enabled"
617
654
  private const val KEY_NEEDS_POINTER_DATA = "needsPointerData"