react-native-gesture-handler 2.3.2 → 2.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. package/RNGestureHandler.podspec +2 -1
  2. package/android/build.gradle +38 -6
  3. package/android/lib/src/main/java/com/swmansion/gesturehandler/GestureHandler.kt +14 -2
  4. package/android/noreanimated/src/main/java/com/swmansion/gesturehandler/ReanimatedEventDispatcher.kt +10 -0
  5. package/android/reanimated/src/main/java/com/swmansion/gesturehandler/ReanimatedEventDispatcher.kt +17 -0
  6. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEnabledRootView.kt +3 -41
  7. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEvent.kt +6 -0
  8. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +10 -54
  9. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootView.kt +2 -0
  10. package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerStateChangeEvent.kt +6 -0
  11. package/ios/RNGHTouchEventType.h +9 -0
  12. package/ios/RNGestureHandler.h +2 -2
  13. package/ios/RNGestureHandler.m +21 -8
  14. package/ios/RNGestureHandlerButton.h +1 -0
  15. package/ios/RNGestureHandlerButton.m +9 -1
  16. package/ios/RNGestureHandlerButtonComponentView.mm +14 -1
  17. package/ios/RNGestureHandlerButtonManager.m +4 -1
  18. package/ios/RNGestureHandlerEvents.h +2 -2
  19. package/ios/RNGestureHandlerEvents.m +2 -2
  20. package/ios/RNGestureHandlerManager.h +2 -0
  21. package/ios/RNGestureHandlerManager.mm +30 -20
  22. package/ios/RNGestureHandlerModule.mm +18 -0
  23. package/ios/RNGestureHandlerPointerTracker.h +2 -2
  24. package/ios/RNGestureHandlerPointerTracker.m +9 -6
  25. package/ios/RNGestureHandlerRegistry.h +1 -0
  26. package/ios/RNGestureHandlerRegistry.m +10 -0
  27. package/lib/commonjs/GestureHandlerRootView.android.js +7 -1
  28. package/lib/commonjs/GestureHandlerRootView.android.js.map +1 -1
  29. package/lib/commonjs/GestureHandlerRootView.js +6 -0
  30. package/lib/commonjs/GestureHandlerRootView.js.map +1 -1
  31. package/lib/commonjs/GestureHandlerRootView.web.js +19 -0
  32. package/lib/commonjs/GestureHandlerRootView.web.js.map +1 -0
  33. package/lib/commonjs/RNGestureHandlerModule.js +5 -0
  34. package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
  35. package/lib/commonjs/RNGestureHandlerModule.web.js +4 -1
  36. package/lib/commonjs/RNGestureHandlerModule.web.js.map +1 -1
  37. package/lib/commonjs/{EventType.js → TouchEventType.js} +4 -4
  38. package/lib/commonjs/TouchEventType.js.map +1 -0
  39. package/lib/commonjs/components/DrawerLayout.js +38 -11
  40. package/lib/commonjs/components/DrawerLayout.js.map +1 -1
  41. package/lib/commonjs/components/GestureButtons.js.map +1 -1
  42. package/lib/commonjs/components/GestureHandlerButton.js +1 -1
  43. package/lib/commonjs/components/GestureHandlerButton.js.map +1 -1
  44. package/lib/commonjs/components/touchables/GenericTouchable.js +2 -0
  45. package/lib/commonjs/components/touchables/GenericTouchable.js.map +1 -1
  46. package/lib/commonjs/fabric/RNGestureHandlerButtonNativeComponent.js +4 -6
  47. package/lib/commonjs/fabric/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  48. package/lib/commonjs/fabric/RNGestureHandlerRootViewNativeComponent.js +4 -6
  49. package/lib/commonjs/fabric/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
  50. package/lib/commonjs/getShadowNodeFromRef.js +12 -9
  51. package/lib/commonjs/getShadowNodeFromRef.js.map +1 -1
  52. package/lib/commonjs/handlers/ForceTouchGestureHandler.js +2 -1
  53. package/lib/commonjs/handlers/ForceTouchGestureHandler.js.map +1 -1
  54. package/lib/commonjs/handlers/createHandler.js +25 -20
  55. package/lib/commonjs/handlers/createHandler.js.map +1 -1
  56. package/lib/commonjs/handlers/gestureHandlerCommon.js +18 -1
  57. package/lib/commonjs/handlers/gestureHandlerCommon.js.map +1 -1
  58. package/lib/commonjs/handlers/gestures/GestureDetector.js +120 -80
  59. package/lib/commonjs/handlers/gestures/GestureDetector.js.map +1 -1
  60. package/lib/commonjs/handlers/gestures/eventReceiver.js +6 -5
  61. package/lib/commonjs/handlers/gestures/eventReceiver.js.map +1 -1
  62. package/lib/commonjs/handlers/gestures/gesture.js +24 -4
  63. package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
  64. package/lib/commonjs/init.js +10 -1
  65. package/lib/commonjs/init.js.map +1 -1
  66. package/lib/commonjs/mocks.js +2 -0
  67. package/lib/commonjs/mocks.js.map +1 -1
  68. package/lib/commonjs/utils.js +23 -1
  69. package/lib/commonjs/utils.js.map +1 -1
  70. package/lib/commonjs/web/GestureHandler.js +4 -1
  71. package/lib/commonjs/web/GestureHandler.js.map +1 -1
  72. package/lib/commonjs/web/utils.js.map +1 -1
  73. package/lib/module/GestureHandlerRootView.android.js +7 -2
  74. package/lib/module/GestureHandlerRootView.android.js.map +1 -1
  75. package/lib/module/GestureHandlerRootView.js +5 -0
  76. package/lib/module/GestureHandlerRootView.js.map +1 -1
  77. package/lib/module/GestureHandlerRootView.web.js +6 -0
  78. package/lib/module/GestureHandlerRootView.web.js.map +1 -0
  79. package/lib/module/RNGestureHandlerModule.js +5 -0
  80. package/lib/module/RNGestureHandlerModule.js.map +1 -1
  81. package/lib/module/RNGestureHandlerModule.web.js +4 -1
  82. package/lib/module/RNGestureHandlerModule.web.js.map +1 -1
  83. package/lib/module/{EventType.js → TouchEventType.js} +2 -2
  84. package/lib/module/TouchEventType.js.map +1 -0
  85. package/lib/module/components/DrawerLayout.js +38 -11
  86. package/lib/module/components/DrawerLayout.js.map +1 -1
  87. package/lib/module/components/GestureButtons.js.map +1 -1
  88. package/lib/module/components/GestureHandlerButton.js +2 -2
  89. package/lib/module/components/GestureHandlerButton.js.map +1 -1
  90. package/lib/module/components/touchables/GenericTouchable.js +2 -0
  91. package/lib/module/components/touchables/GenericTouchable.js.map +1 -1
  92. package/lib/module/fabric/RNGestureHandlerButtonNativeComponent.js +5 -7
  93. package/lib/module/fabric/RNGestureHandlerButtonNativeComponent.js.map +1 -1
  94. package/lib/module/fabric/RNGestureHandlerRootViewNativeComponent.js +5 -8
  95. package/lib/module/fabric/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
  96. package/lib/module/getShadowNodeFromRef.js +11 -8
  97. package/lib/module/getShadowNodeFromRef.js.map +1 -1
  98. package/lib/module/handlers/ForceTouchGestureHandler.js +1 -1
  99. package/lib/module/handlers/ForceTouchGestureHandler.js.map +1 -1
  100. package/lib/module/handlers/createHandler.js +25 -22
  101. package/lib/module/handlers/createHandler.js.map +1 -1
  102. package/lib/module/handlers/gestureHandlerCommon.js +11 -1
  103. package/lib/module/handlers/gestureHandlerCommon.js.map +1 -1
  104. package/lib/module/handlers/gestures/GestureDetector.js +120 -81
  105. package/lib/module/handlers/gestures/GestureDetector.js.map +1 -1
  106. package/lib/module/handlers/gestures/eventReceiver.js +6 -7
  107. package/lib/module/handlers/gestures/eventReceiver.js.map +1 -1
  108. package/lib/module/handlers/gestures/gesture.js +23 -4
  109. package/lib/module/handlers/gestures/gesture.js.map +1 -1
  110. package/lib/module/init.js +6 -1
  111. package/lib/module/init.js.map +1 -1
  112. package/lib/module/mocks.js +2 -0
  113. package/lib/module/mocks.js.map +1 -1
  114. package/lib/module/utils.js +17 -1
  115. package/lib/module/utils.js.map +1 -1
  116. package/lib/module/web/GestureHandler.js +4 -1
  117. package/lib/module/web/GestureHandler.js.map +1 -1
  118. package/lib/module/web/utils.js.map +1 -1
  119. package/lib/typescript/GestureHandlerRootView.web.d.ts +5 -0
  120. package/lib/typescript/RNGestureHandlerModule.d.ts +1 -0
  121. package/lib/typescript/RNGestureHandlerModule.web.d.ts +1 -0
  122. package/lib/typescript/{EventType.d.ts → TouchEventType.d.ts} +2 -2
  123. package/lib/typescript/components/DrawerLayout.d.ts +3 -0
  124. package/lib/typescript/components/GestureButtons.d.ts +18 -6
  125. package/lib/typescript/fabric/RNGestureHandlerButtonNativeComponent.d.ts +13 -0
  126. package/lib/typescript/fabric/RNGestureHandlerRootViewNativeComponent.d.ts +5 -0
  127. package/lib/typescript/handlers/ForceTouchGestureHandler.d.ts +2 -2
  128. package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +1 -1
  129. package/lib/typescript/handlers/gestureHandlerCommon.d.ts +6 -3
  130. package/lib/typescript/handlers/gestures/GestureDetector.d.ts +2 -4
  131. package/lib/typescript/handlers/gestures/eventReceiver.d.ts +2 -0
  132. package/lib/typescript/handlers/gestures/gesture.d.ts +5 -0
  133. package/lib/typescript/init.d.ts +1 -0
  134. package/lib/typescript/mocks.d.ts +1 -0
  135. package/lib/typescript/utils.d.ts +2 -0
  136. package/lib/typescript/web/GestureHandler.d.ts +1 -1
  137. package/package.json +4 -2
  138. package/src/GestureHandlerRootView.android.tsx +8 -2
  139. package/src/GestureHandlerRootView.tsx +6 -0
  140. package/src/GestureHandlerRootView.web.tsx +12 -0
  141. package/src/RNGestureHandlerModule.ts +7 -0
  142. package/src/RNGestureHandlerModule.web.ts +2 -0
  143. package/src/{EventType.ts → TouchEventType.ts} +2 -2
  144. package/src/components/DrawerLayout.tsx +34 -10
  145. package/src/components/GestureButtons.tsx +21 -7
  146. package/src/components/GestureHandlerButton.tsx +2 -2
  147. package/src/components/touchables/GenericTouchable.tsx +2 -0
  148. package/src/fabric/RNGestureHandlerButtonNativeComponent.ts +27 -0
  149. package/src/fabric/RNGestureHandlerRootViewNativeComponent.ts +12 -0
  150. package/src/getShadowNodeFromRef.ts +12 -9
  151. package/src/handlers/ForceTouchGestureHandler.ts +3 -2
  152. package/src/handlers/createHandler.ts +30 -26
  153. package/src/handlers/gestureHandlerCommon.ts +21 -2
  154. package/src/handlers/gestures/GestureDetector.tsx +164 -105
  155. package/src/handlers/gestures/eventReceiver.ts +6 -6
  156. package/src/handlers/gestures/gesture.ts +29 -2
  157. package/src/init.ts +8 -1
  158. package/src/mocks.ts +2 -0
  159. package/src/utils.ts +20 -0
  160. package/src/web/GestureHandler.ts +7 -1
  161. package/src/web/utils.ts +1 -1
  162. package/ios/RNTouchEventType.h +0 -9
  163. package/lib/commonjs/EventType.js.map +0 -1
  164. package/lib/module/EventType.js.map +0 -1
  165. package/src/fabric/RNGestureHandlerButtonNativeComponent.js +0 -27
  166. package/src/fabric/RNGestureHandlerRootViewNativeComponent.js +0 -19
@@ -23,7 +23,8 @@ Pod::Spec.new do |s|
23
23
  folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
24
24
 
25
25
  s.pod_target_xcconfig = {
26
- 'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/boost" "$(PODS_ROOT)/boost-for-react-native" "$(PODS_ROOT)/RCT-Folly"'
26
+ 'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/boost" "$(PODS_ROOT)/boost-for-react-native" "$(PODS_ROOT)/RCT-Folly"',
27
+ 'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
27
28
  }
28
29
  s.platforms = { ios: '11.0', tvos: '11.0' }
29
30
  s.compiler_flags = folly_compiler_flags + ' -DRN_FABRIC_ENABLED'
@@ -1,4 +1,5 @@
1
1
  import groovy.json.JsonSlurper
2
+ import java.nio.file.Paths
2
3
 
3
4
  buildscript {
4
5
  def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['RNGH_kotlinVersion']
@@ -20,6 +21,20 @@ def isNewArchitectureEnabled() {
20
21
  return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
21
22
  }
22
23
 
24
+ def findNodeModulePath(baseDir, packageName) {
25
+ def basePath = baseDir.toPath().normalize()
26
+ // Node's module resolution algorithm searches up to the root directory,
27
+ // after which the base path will be null
28
+ while (basePath) {
29
+ def candidatePath = Paths.get(basePath.toString(), "node_modules", packageName)
30
+ if (candidatePath.toFile().exists()) {
31
+ return candidatePath.toString()
32
+ }
33
+ basePath = basePath.getParent()
34
+ }
35
+ return null
36
+ }
37
+
23
38
  if (isNewArchitectureEnabled()) {
24
39
  apply plugin: 'com.facebook.react'
25
40
  }
@@ -38,7 +53,7 @@ def shouldUseCommonInterfaceFromReanimated() {
38
53
  def json = new JsonSlurper().parseText(inputFile.text)
39
54
  def reanimatedVersion = json.version as String
40
55
  def (major, minor, patch) = reanimatedVersion.tokenize('.')
41
- return Integer.parseInt(major) == 2 && Integer.parseInt(minor) >= 3
56
+ return (Integer.parseInt(major) == 2 && Integer.parseInt(minor) >= 3) || Integer.parseInt(major) == 3
42
57
  } else {
43
58
  return false
44
59
  }
@@ -51,6 +66,15 @@ repositories {
51
66
  android {
52
67
  compileSdkVersion safeExtGet("compileSdkVersion", 28)
53
68
 
69
+ // Used to override the NDK path/version on internal CI or by allowing
70
+ // users to customize the NDK path/version from their root project (e.g. for M1 support)
71
+ if (rootProject.hasProperty("ndkPath")) {
72
+ ndkPath rootProject.ext.ndkPath
73
+ }
74
+ if (rootProject.hasProperty("ndkVersion")) {
75
+ ndkVersion rootProject.ext.ndkVersion
76
+ }
77
+
54
78
  defaultConfig {
55
79
  minSdkVersion safeExtGet('minSdkVersion', 16)
56
80
  targetSdkVersion safeExtGet('targetSdkVersion', 28)
@@ -66,8 +90,8 @@ android {
66
90
  "NDK_TOOLCHAIN_VERSION=clang",
67
91
  "GENERATED_SRC_DIR=${appProject.buildDir}/generated/source",
68
92
  "PROJECT_BUILD_DIR=${appProject.buildDir}",
69
- "REACT_ANDROID_DIR=${appProject.rootDir}/../node_modules/react-native/ReactAndroid",
70
- "REACT_ANDROID_BUILD_DIR=${appProject.rootDir}/../node_modules/react-native/ReactAndroid/build"
93
+ "REACT_ANDROID_DIR=${findNodeModulePath(appProject.rootDir, "react-native") ?: "../node_modules/react-native/"}/ReactAndroid",
94
+ "REACT_ANDROID_BUILD_DIR=${findNodeModulePath(appProject.rootDir, "react-native") ?: "../node_modules/react-native/"}/ReactAndroid/build"
71
95
  cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
72
96
  cppFlags "-std=c++17"
73
97
  targets "rngesturehandler_modules"
@@ -76,6 +100,11 @@ android {
76
100
  }
77
101
  }
78
102
 
103
+ compileOptions {
104
+ sourceCompatibility JavaVersion.VERSION_1_8
105
+ targetCompatibility JavaVersion.VERSION_1_8
106
+ }
107
+
79
108
  if (isNewArchitectureEnabled()) {
80
109
  externalNativeBuild {
81
110
  ndkBuild {
@@ -101,8 +130,11 @@ android {
101
130
 
102
131
  // Include "common/" only when it's not provided by Reanimated to mitigate
103
132
  // multiple definitions of the same class preventing build
104
- if (!shouldUseCommonInterfaceFromReanimated()) {
133
+ if (shouldUseCommonInterfaceFromReanimated()) {
134
+ srcDirs += 'reanimated/src/main/java'
135
+ } else {
105
136
  srcDirs += 'common/src/main/java'
137
+ srcDirs += 'noreanimated/src/main/java'
106
138
  }
107
139
 
108
140
  if (isNewArchitectureEnabled()) {
@@ -140,9 +172,9 @@ dependencies {
140
172
 
141
173
  if (isNewArchitectureEnabled()) {
142
174
  react {
143
- reactRoot = rootProject.file("../node_modules/react-native/")
175
+ reactNativeDir = rootProject.file(findNodeModulePath(rootProject.rootDir, "react-native") ?: "../node_modules/react-native/")
144
176
  jsRootDir = file("../src/fabric/")
145
- codegenDir = rootProject.file("../node_modules/react-native-codegen/")
177
+ codegenDir = rootProject.file(findNodeModulePath(rootProject.rootDir, "react-native-codegen") ?: "../node_modules/react-native-codegen/")
146
178
  libraryName = "rngesturehandler"
147
179
  codegenJavaPackageName = "com.swmansion.gesturehandler"
148
180
  }
@@ -316,7 +316,7 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
316
316
  isEnabled: ${handler.isEnabled}
317
317
  isActive: ${handler.isActive}
318
318
  isAwaiting: ${handler.isAwaiting}
319
- trackedPointersCount: ${handler.trackedPointersCount}
319
+ trackedPointersCount: ${handler.trackedPointersIDsCount}
320
320
  trackedPointers: ${handler.trackedPointerIDs.joinToString(separator = ", ")}
321
321
  while handling event: $event
322
322
  """.trimIndent(), e) {}
@@ -329,7 +329,19 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
329
329
  || trackedPointersIDsCount < 1) {
330
330
  return
331
331
  }
332
- val event = adaptEvent(origEvent)
332
+
333
+ // a workaround for https://github.com/software-mansion/react-native-gesture-handler/issues/1188
334
+ val event = if (BuildConfig.DEBUG) {
335
+ adaptEvent(origEvent)
336
+ } else {
337
+ try {
338
+ adaptEvent(origEvent)
339
+ } catch (e: AdaptEventException) {
340
+ fail()
341
+ return
342
+ }
343
+ }
344
+
333
345
  x = event.x
334
346
  y = event.y
335
347
  numberOfPointers = event.pointerCount
@@ -0,0 +1,10 @@
1
+ package com.swmansion.gesturehandler
2
+
3
+ import com.facebook.react.bridge.ReactContext
4
+ import com.facebook.react.uimanager.events.Event
5
+
6
+ object ReanimatedEventDispatcher {
7
+ fun <T : Event<T>>sendEvent(event: T, reactApplicationContext: ReactContext) {
8
+ // no-op
9
+ }
10
+ }
@@ -0,0 +1,17 @@
1
+ package com.swmansion.gesturehandler
2
+
3
+ import com.facebook.react.bridge.ReactContext
4
+ import com.facebook.react.uimanager.events.Event
5
+ import com.swmansion.reanimated.ReanimatedModule
6
+
7
+ object ReanimatedEventDispatcher {
8
+ private var reanimatedModule: ReanimatedModule? = null
9
+
10
+ fun <T : Event<T>>sendEvent(event: T, reactApplicationContext: ReactContext) {
11
+ if (reanimatedModule == null) {
12
+ reanimatedModule = reactApplicationContext.getNativeModule(ReanimatedModule::class.java)
13
+ }
14
+
15
+ reanimatedModule?.nodesManager?.onEventDispatch(event)
16
+ }
17
+ }
@@ -6,52 +6,14 @@ import android.util.AttributeSet
6
6
  import android.view.MotionEvent
7
7
  import com.facebook.react.ReactInstanceManager
8
8
  import com.facebook.react.ReactRootView
9
+ import java.lang.Exception
9
10
 
10
11
  @Deprecated(message = "Use <GestureHandlerRootView /> component instead. Check gesture handler installation instructions in documentation for more information.")
11
12
  class RNGestureHandlerEnabledRootView : ReactRootView {
12
- private lateinit var _reactInstanceManager: ReactInstanceManager
13
- private var gestureRootHelper: RNGestureHandlerRootHelper? = null
14
-
15
13
  constructor(context: Context?) : super(context) {}
16
14
  constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {}
17
15
 
18
- override fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {
19
- gestureRootHelper?.requestDisallowInterceptTouchEvent(disallowIntercept)
20
- super.requestDisallowInterceptTouchEvent(disallowIntercept)
21
- }
22
-
23
- override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
24
- return if (gestureRootHelper?.dispatchTouchEvent(ev) == true) {
25
- true
26
- } else super.dispatchTouchEvent(ev)
27
- }
28
-
29
- /**
30
- * This method is used to enable root view to start processing touch events through the gesture
31
- * handler library logic. Unless this method is called (which happens as a result of instantiating
32
- * new gesture handler from JS) the root view component will just proxy all touch related methods
33
- * to its superclass. Thus in the "disabled" state all touch related events will fallback to
34
- * default RN behavior.
35
- */
36
- fun initialize() {
37
- check(gestureRootHelper == null) { "GestureHandler already initialized for root view $this" }
38
- gestureRootHelper = RNGestureHandlerRootHelper(
39
- _reactInstanceManager.currentReactContext!!, this)
40
- }
41
-
42
- fun tearDown() {
43
- gestureRootHelper?.let {
44
- it.tearDown()
45
- gestureRootHelper = null
46
- }
47
- }
48
-
49
- override fun startReactApplication(
50
- reactInstanceManager: ReactInstanceManager,
51
- moduleName: String,
52
- initialProperties: Bundle?,
53
- ) {
54
- super.startReactApplication(reactInstanceManager, moduleName, initialProperties)
55
- _reactInstanceManager = reactInstanceManager
16
+ init {
17
+ throw UnsupportedOperationException("Your application is configured to use RNGestureHandlerEnabledRootView which is no longer supported. You can see how to migrate to <GestureHandlerRootView /> here: https://docs.swmansion.com/react-native-gesture-handler/docs/guides/migrating-off-rnghenabledroot")
56
18
  }
57
19
  }
@@ -1,3 +1,9 @@
1
+ // 1. RCTEventEmitter was deprecated in favor of RCTModernEventEmitter interface
2
+ // 2. Event#init() with only viewTag was deprecated in favor of two arg c-tor
3
+ // 3. Event#receiveEvent() with 3 args was deprecated in favor of 4 args version
4
+ // ref: https://github.com/facebook/react-native/commit/2fbbdbb2ce897e8da3f471b08b93f167d566db1d
5
+ @file:Suppress("DEPRECATION")
6
+
1
7
  package com.swmansion.gesturehandler.react
2
8
 
3
9
  import androidx.core.util.Pools
@@ -14,7 +14,12 @@ import com.facebook.soloader.SoLoader
14
14
  import com.swmansion.common.GestureHandlerStateManager
15
15
  import com.swmansion.gesturehandler.*
16
16
  import java.util.*
17
+ // NativeModule.onCatalystInstanceDestroy() was deprecated in favor of NativeModule.invalidate()
18
+ // ref: https://github.com/facebook/react-native/commit/18c8417290823e67e211bde241ae9dde27b72f17
17
19
 
20
+ // UIManagerModule.resolveRootTagFromReactTag() was deprecated and will be removed in the next RN release
21
+ // ref: https://github.com/facebook/react-native/commit/acbf9e18ea666b07c1224a324602a41d0a66985e
22
+ @Suppress("DEPRECATION")
18
23
  @ReactModule(name = RNGestureHandlerModule.MODULE_NAME)
19
24
  class RNGestureHandlerModule(reactContext: ReactApplicationContext?)
20
25
  : ReactContextBaseJavaModule(reactContext), GestureHandlerStateManager {
@@ -314,7 +319,7 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?)
314
319
 
315
320
  private val eventListener = object : OnTouchEventListener {
316
321
  override fun <T : GestureHandler<T>> onHandlerUpdate(handler: T, event: MotionEvent) {
317
- this@RNGestureHandlerModule.onHandlerUpdate(handler, event)
322
+ this@RNGestureHandlerModule.onHandlerUpdate(handler)
318
323
  }
319
324
 
320
325
  override fun <T : GestureHandler<T>> onStateChange(handler: T, newState: Int, oldState: Int) {
@@ -363,10 +368,6 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?)
363
368
 
364
369
  @ReactMethod
365
370
  fun attachGestureHandler(handlerTag: Int, viewTag: Int, actionType: Int) {
366
- if (!BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
367
- tryInitializeHandlerForReactRootView(viewTag)
368
- }
369
-
370
371
  // We don't have to handle view flattening in any special way since handlers are stored as
371
372
  // a map: viewTag -> [handler]. If the view with attached handlers was to be flattened
372
373
  // then that viewTag simply wouldn't be visited when traversing the view hierarchy in the
@@ -459,12 +460,7 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?)
459
460
  while (roots.isNotEmpty()) {
460
461
  val sizeBefore: Int = roots.size
461
462
  val root: RNGestureHandlerRootHelper = roots[0]
462
- val reactRootView: ViewGroup = root.rootView
463
- if (reactRootView is RNGestureHandlerEnabledRootView) {
464
- reactRootView.tearDown()
465
- } else {
466
- root.tearDown()
467
- }
463
+ root.tearDown()
468
464
  if (roots.size >= sizeBefore) {
469
465
  throw IllegalStateException("Expected root helper to get unregistered while tearing down")
470
466
  }
@@ -473,44 +469,6 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?)
473
469
  super.onCatalystInstanceDestroy()
474
470
  }
475
471
 
476
- private fun tryInitializeHandlerForReactRootView(ancestorViewTag: Int) {
477
- val uiManager = reactApplicationContext.UIManager
478
- val rootViewTag = uiManager.resolveRootTagFromReactTag(ancestorViewTag)
479
- if (rootViewTag < 1) {
480
- throw JSApplicationIllegalArgumentException("Could find root view for a given ancestor with tag $ancestorViewTag")
481
- }
482
- synchronized(roots) {
483
- for (root in roots) {
484
- val rootView: ViewGroup = root.rootView
485
- if (rootView is ReactRootView && rootView.rootViewTag == rootViewTag) {
486
- // we have found root helper registered for a given react root, we don't need to
487
- // initialize a new one then
488
- return
489
- }
490
- }
491
- }
492
- synchronized(enqueuedRootViewInit) {
493
- if (rootViewTag in enqueuedRootViewInit) {
494
- // root view initialization already enqueued -> we skip
495
- return
496
- }
497
- enqueuedRootViewInit.add(rootViewTag)
498
- }
499
- // root helper for a given root tag has not been found, we may wat to check if the root view is
500
- // an instance of RNGestureHandlerEnabledRootView and then initialize gesture handler with it
501
- uiManager.addUIBlock(UIBlock { nativeViewHierarchyManager ->
502
- val view = nativeViewHierarchyManager.resolveView(rootViewTag)
503
- if (view is RNGestureHandlerEnabledRootView) {
504
- view.initialize()
505
- } else {
506
- // Seems like the root view is something else than RNGestureHandlerEnabledRootView, this
507
- // is fine though as long as gestureHandlerRootHOC is used in JS
508
- // FIXME: check and warn about gestureHandlerRootHOC
509
- }
510
- synchronized(enqueuedRootViewInit) { enqueuedRootViewInit.remove(rootViewTag) }
511
- })
512
- }
513
-
514
472
  fun registerRootHelper(root: RNGestureHandlerRootHelper) {
515
473
  synchronized(roots) {
516
474
  if (root in roots) {
@@ -542,7 +500,7 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?)
542
500
  private fun <T : GestureHandler<T>> findFactoryForHandler(handler: GestureHandler<T>): HandlerFactory<T>? =
543
501
  handlerFactories.firstOrNull { it.type == handler.javaClass } as HandlerFactory<T>?
544
502
 
545
- private fun <T : GestureHandler<T>> onHandlerUpdate(handler: T, motionEvent: MotionEvent) {
503
+ private fun <T : GestureHandler<T>> onHandlerUpdate(handler: T) {
546
504
  // triggers onUpdate and onChange callbacks on the JS side
547
505
 
548
506
  if (handler.tag < 0) {
@@ -631,10 +589,8 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?)
631
589
  private fun <T : Event<T>>sendEventForReanimated(event: T) {
632
590
  // Delivers the event to Reanimated.
633
591
  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)
592
+ // Send event directly to Reanimated
593
+ ReanimatedEventDispatcher.sendEvent(event, reactApplicationContext)
638
594
  } else {
639
595
  // In the old architecture, Reanimated subscribes for specific direct events.
640
596
  sendEventForDirectEvent(event)
@@ -51,6 +51,8 @@ class RNGestureHandlerRootView(context: Context?) : ReactViewGroup(context) {
51
51
 
52
52
  var parent = viewGroup.parent
53
53
  while (parent != null) {
54
+ // our own deprecated root view
55
+ @Suppress("DEPRECATION")
54
56
  if (parent is RNGestureHandlerEnabledRootView || parent is RNGestureHandlerRootView) {
55
57
  return true
56
58
  }
@@ -1,3 +1,9 @@
1
+ // 1. RCTEventEmitter was deprecated in favor of RCTModernEventEmitter interface
2
+ // 2. Event#init() with only viewTag was deprecated in favor of two arg c-tor
3
+ // 3. Event#receiveEvent() with 3 args was deprecated in favor of 4 args version
4
+ // ref: https://github.com/facebook/react-native/commit/2fbbdbb2ce897e8da3f471b08b93f167d566db1d
5
+ @file:Suppress("DEPRECATION")
6
+
1
7
  package com.swmansion.gesturehandler.react
2
8
 
3
9
  import androidx.core.util.Pools
@@ -0,0 +1,9 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ typedef NS_ENUM(NSInteger, RNGHTouchEventType) {
4
+ RNGHTouchEventTypeUndetermined = 0,
5
+ RNGHTouchEventTypePointerDown,
6
+ RNGHTouchEventTypePointerMove,
7
+ RNGHTouchEventTypePointerUp,
8
+ RNGHTouchEventTypeCancelled,
9
+ };
@@ -26,7 +26,7 @@ if (value != nil) { recognizer.prop = [RCTConvert type:value]; }\
26
26
 
27
27
  @protocol RNGestureHandlerEventEmitter
28
28
 
29
- - (void)sendStateChangeEvent:(nonnull RNGestureHandlerStateChange *)event withActionType:(RNGestureHandlerActionType)actionType;
29
+ - (void)sendEvent:(nonnull RNGestureHandlerStateChange *)event withActionType:(RNGestureHandlerActionType)actionType;
30
30
 
31
31
  @end
32
32
 
@@ -74,7 +74,7 @@ if (value != nil) { recognizer.prop = [RCTConvert type:value]; }\
74
74
  - (void)sendEventsInState:(RNGestureHandlerState)state
75
75
  forViewWithTag:(nonnull NSNumber *)reactTag
76
76
  withExtraData:(nonnull RNGestureHandlerEventExtraData *)extraData;
77
- - (void)sendStateChangeEvent:(nonnull RNGestureHandlerStateChange *)event;
77
+ - (void)sendEvent:(nonnull RNGestureHandlerStateChange *)event;
78
78
  - (void)sendTouchEventInState:(RNGestureHandlerState)state
79
79
  forViewWithTag:(nonnull NSNumber *)reactTag;
80
80
 
@@ -94,13 +94,14 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
94
94
  - (void)resetConfig
95
95
  {
96
96
  self.enabled = YES;
97
+ self.manualActivation = NO;
97
98
  _shouldCancelWhenOutside = NO;
98
99
  _handlersToWaitFor = nil;
99
100
  _simultaneousHandlers = nil;
100
101
  _hitSlop = RNGHHitSlopEmpty;
101
102
  _needsPointerData = NO;
102
-
103
- self.manualActivation = NO;
103
+
104
+ _recognizer.cancelsTouchesInView = YES;
104
105
  }
105
106
 
106
107
  - (void)configure:(NSDictionary *)config
@@ -119,6 +120,11 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
119
120
  _shouldCancelWhenOutside = [RCTConvert BOOL:prop];
120
121
  }
121
122
 
123
+ prop = config[@"cancelsTouchesInView"];
124
+ if (prop != nil) {
125
+ _recognizer.cancelsTouchesInView = [RCTConvert BOOL:prop];
126
+ }
127
+
122
128
  prop = config[@"needsPointerData"];
123
129
  if (prop != nil) {
124
130
  _needsPointerData = [RCTConvert BOOL:prop];
@@ -189,6 +195,13 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
189
195
 
190
196
  - (void)handleGesture:(UIGestureRecognizer *)recognizer
191
197
  {
198
+ // it may happen that the gesture recognizer is reset after it's been unbound from the view,
199
+ // it that recognizer tried to send event, the app would crash because the target of the event
200
+ // would be nil.
201
+ if (recognizer.view.reactTag == nil) {
202
+ return;
203
+ }
204
+
192
205
  _state = [self recognizerState];
193
206
  RNGestureHandlerEventExtraData *eventData = [self eventExtraData:recognizer];
194
207
  [self sendEventsInState:self.state forViewWithTag:recognizer.view.reactTag withExtraData:eventData];
@@ -212,7 +225,7 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
212
225
  state:RNGestureHandlerStateActive
213
226
  prevState:_lastState
214
227
  extraData:extraData];
215
- [self sendStateChangeEvent:event];
228
+ [self sendEvent:event];
216
229
  _lastState = RNGestureHandlerStateActive;
217
230
  }
218
231
  id stateEvent = [[RNGestureHandlerStateChange alloc] initWithReactTag:reactTag
@@ -220,7 +233,7 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
220
233
  state:state
221
234
  prevState:_lastState
222
235
  extraData:extraData];
223
- [self sendStateChangeEvent:stateEvent];
236
+ [self sendEvent:stateEvent];
224
237
  _lastState = state;
225
238
  }
226
239
 
@@ -230,13 +243,13 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
230
243
  state:state
231
244
  extraData:extraData
232
245
  coalescingKey:self->_eventCoalescingKey];
233
- [self sendStateChangeEvent:touchEvent];
246
+ [self sendEvent:touchEvent];
234
247
  }
235
248
  }
236
249
 
237
- - (void)sendStateChangeEvent:(RNGestureHandlerStateChange *)event
250
+ - (void)sendEvent:(RNGestureHandlerStateChange *)event
238
251
  {
239
- [self.emitter sendStateChangeEvent:event withActionType:self.actionType];
252
+ [self.emitter sendEvent:event withActionType:self.actionType];
240
253
  }
241
254
 
242
255
  - (void)sendTouchEventInState:(RNGestureHandlerState)state
@@ -248,7 +261,7 @@ static NSHashTable<RNGestureHandler *> *allGestureHandlers;
248
261
  withNumberOfTouches:_pointerTracker.trackedPointersCount];
249
262
  id event = [[RNGestureHandlerEvent alloc] initWithReactTag:reactTag handlerTag:_tag state:state extraData:extraData coalescingKey:[_tag intValue]];
250
263
 
251
- [self.emitter sendStateChangeEvent:event withActionType:self.actionType];
264
+ [self.emitter sendEvent:event withActionType:self.actionType];
252
265
  }
253
266
 
254
267
  - (RNGestureHandlerState)recognizerState
@@ -14,5 +14,6 @@
14
14
  * Insets used when hit testing inside this view.
15
15
  */
16
16
  @property (nonatomic, assign) UIEdgeInsets hitTestEdgeInsets;
17
+ @property (nonatomic) BOOL userEnabled;
17
18
 
18
19
  @end
@@ -38,6 +38,7 @@
38
38
  self = [super init];
39
39
  if (self) {
40
40
  _hitTestEdgeInsets = UIEdgeInsetsZero;
41
+ _userEnabled = YES;
41
42
  #if !TARGET_OS_TV
42
43
  [self setExclusiveTouch:YES];
43
44
  #endif
@@ -47,6 +48,11 @@
47
48
 
48
49
  - (BOOL)shouldHandleTouch:(UIView *)view
49
50
  {
51
+ if ([view isKindOfClass:[RNGestureHandlerButton class]]) {
52
+ RNGestureHandlerButton *button = (RNGestureHandlerButton *)view;
53
+ return button.userEnabled;
54
+ }
55
+
50
56
  return [view isKindOfClass:[UIControl class]] || [view.gestureRecognizers count] > 0;
51
57
  }
52
58
 
@@ -62,7 +68,9 @@
62
68
  - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
63
69
  {
64
70
  UIView *inner = [super hitTest:point withEvent:event];
65
- while (inner && ![self shouldHandleTouch:inner]) inner = inner.superview;
71
+ while (inner && ![self shouldHandleTouch:inner]) {
72
+ inner = inner.superview;
73
+ }
66
74
  return inner;
67
75
  }
68
76
 
@@ -18,14 +18,18 @@ using namespace facebook::react;
18
18
  @end
19
19
 
20
20
  @implementation RNGestureHandlerButtonComponentView
21
+ {
22
+ RNGestureHandlerButton *_buttonView;
23
+ }
21
24
 
22
25
  - (instancetype)initWithFrame:(CGRect)frame
23
26
  {
24
27
  if (self = [super initWithFrame:frame]) {
25
28
  static const auto defaultProps = std::make_shared<const RNGestureHandlerButtonProps>();
26
29
  _props = defaultProps;
30
+ _buttonView = [[RNGestureHandlerButton alloc] initWithFrame:self.bounds];
27
31
 
28
- self.contentView = [[RNGestureHandlerButton alloc] initWithFrame:self.bounds];
32
+ self.contentView = _buttonView;
29
33
  }
30
34
 
31
35
  return self;
@@ -38,6 +42,15 @@ using namespace facebook::react;
38
42
  return concreteComponentDescriptorProvider<RNGestureHandlerButtonComponentDescriptor>();
39
43
  }
40
44
 
45
+ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps
46
+ {
47
+ const auto &newProps = *std::static_pointer_cast<const RNGestureHandlerButtonProps>(props);
48
+
49
+ _buttonView.userEnabled = newProps.enabled;
50
+ _buttonView.exclusiveTouch = newProps.exclusive;
51
+
52
+ [super updateProps:props oldProps:oldProps];
53
+ }
41
54
  @end
42
55
 
43
56
  Class<RCTComponentViewProtocol> RNGestureHandlerButtonCls(void)
@@ -5,7 +5,10 @@
5
5
 
6
6
  RCT_EXPORT_MODULE(RNGestureHandlerButton)
7
7
 
8
- RCT_EXPORT_VIEW_PROPERTY(enabled, BOOL)
8
+ RCT_CUSTOM_VIEW_PROPERTY(enabled, BOOL, RNGestureHandlerButton)
9
+ {
10
+ view.userEnabled = json == nil ? YES : [RCTConvert BOOL: json];
11
+ }
9
12
  #if !TARGET_OS_TV
10
13
  RCT_CUSTOM_VIEW_PROPERTY(exclusive, BOOL, RNGestureHandlerButton)
11
14
  {
@@ -4,7 +4,7 @@
4
4
  #import <UIKit/UIKit.h>
5
5
 
6
6
  #import "RNGestureHandlerState.h"
7
- #import "RNTouchEventType.h"
7
+ #import "RNGHTouchEventType.h"
8
8
 
9
9
  @interface RNGestureHandlerEventExtraData : NSObject
10
10
 
@@ -36,7 +36,7 @@
36
36
  withAnchorPoint:(CGPoint)anchorPoint
37
37
  withVelocity:(CGFloat)velocity
38
38
  withNumberOfTouches:(NSUInteger)numberOfTouches;
39
- + (RNGestureHandlerEventExtraData *)forEventType:(RNTouchEventType)eventType
39
+ + (RNGestureHandlerEventExtraData *)forEventType:(RNGHTouchEventType)eventType
40
40
  withChangedPointers:(NSArray<NSDictionary *> *)changedPointers
41
41
  withAllPointers:(NSArray<NSDictionary *> *)allPointers
42
42
  withNumberOfTouches:(NSUInteger)numberOfTouches;
@@ -103,7 +103,7 @@
103
103
  @"numberOfPointers": @(numberOfTouches)}];
104
104
  }
105
105
 
106
- + (RNGestureHandlerEventExtraData *)forEventType:(RNTouchEventType)eventType
106
+ + (RNGestureHandlerEventExtraData *)forEventType:(RNGHTouchEventType)eventType
107
107
  withChangedPointers:(NSArray<NSDictionary *> *)changedPointers
108
108
  withAllPointers:(NSArray<NSDictionary *> *)allPointers
109
109
  withNumberOfTouches:(NSUInteger)numberOfTouches
@@ -111,7 +111,7 @@
111
111
  if (changedPointers == nil || allPointers == nil) {
112
112
  changedPointers = @[];
113
113
  allPointers = @[];
114
- eventType = RNTouchEventTypeUndetermined;
114
+ eventType = RNGHTouchEventTypeUndetermined;
115
115
  }
116
116
 
117
117
  return [[RNGestureHandlerEventExtraData alloc]
@@ -24,6 +24,8 @@
24
24
 
25
25
  - (void)dropGestureHandler:(nonnull NSNumber *)handlerTag;
26
26
 
27
+ - (void)dropAllGestureHandlers;
28
+
27
29
  - (void)handleSetJSResponder:(nonnull NSNumber *)viewTag
28
30
  blockNativeResponder:(nonnull NSNumber *)blockNativeResponder;
29
31