react-native-gesture-handler 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/RNGestureHandler.podspec +2 -1
- package/android/build.gradle +10 -2
- package/android/lib/src/main/java/com/swmansion/gesturehandler/GestureHandler.kt +14 -2
- package/android/noreanimated/src/main/java/com/swmansion/gesturehandler/ReanimatedEventDispatcher.kt +10 -0
- package/android/reanimated/src/main/java/com/swmansion/gesturehandler/ReanimatedEventDispatcher.kt +17 -0
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +11 -3
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEnabledRootView.kt +3 -41
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEvent.kt +6 -0
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +10 -54
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootView.kt +2 -0
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerStateChangeEvent.kt +6 -0
- package/ios/RNGHTouchEventType.h +9 -0
- package/ios/RNGestureHandler.h +2 -2
- package/ios/RNGestureHandler.m +21 -8
- package/ios/RNGestureHandler.xcodeproj/project.xcworkspace/xcuserdata/jakubpiasecki.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/RNGestureHandler.xcodeproj/xcuserdata/jakubpiasecki.xcuserdatad/xcschemes/xcschememanagement.plist +19 -0
- package/ios/RNGestureHandlerButton.h +1 -0
- package/ios/RNGestureHandlerButton.m +9 -1
- package/ios/RNGestureHandlerButtonComponentView.mm +14 -1
- package/ios/RNGestureHandlerButtonManager.m +4 -1
- package/ios/RNGestureHandlerEvents.h +2 -2
- package/ios/RNGestureHandlerEvents.m +2 -2
- package/ios/RNGestureHandlerManager.h +2 -0
- package/ios/RNGestureHandlerManager.mm +30 -20
- package/ios/RNGestureHandlerModule.mm +18 -0
- package/ios/RNGestureHandlerPointerTracker.h +2 -2
- package/ios/RNGestureHandlerPointerTracker.m +9 -6
- package/ios/RNGestureHandlerRegistry.h +1 -0
- package/ios/RNGestureHandlerRegistry.m +10 -0
- package/jest-utils/package.json +6 -0
- package/lib/commonjs/GestureHandlerRootView.android.js +7 -1
- package/lib/commonjs/GestureHandlerRootView.android.js.map +1 -1
- package/lib/commonjs/GestureHandlerRootView.js +6 -0
- package/lib/commonjs/GestureHandlerRootView.js.map +1 -1
- package/lib/commonjs/GestureHandlerRootView.web.js +19 -0
- package/lib/commonjs/GestureHandlerRootView.web.js.map +1 -0
- package/lib/commonjs/RNGestureHandlerModule.js +5 -0
- package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/RNGestureHandlerModule.web.js +4 -1
- package/lib/commonjs/RNGestureHandlerModule.web.js.map +1 -1
- package/lib/commonjs/{EventType.js → TouchEventType.js} +4 -4
- package/lib/commonjs/TouchEventType.js.map +1 -0
- package/lib/commonjs/components/GestureButtons.js.map +1 -1
- package/lib/commonjs/components/GestureHandlerButton.js +1 -1
- package/lib/commonjs/components/GestureHandlerButton.js.map +1 -1
- package/lib/commonjs/components/touchables/GenericTouchable.js +2 -0
- package/lib/commonjs/components/touchables/GenericTouchable.js.map +1 -1
- package/lib/commonjs/components/touchables/TouchableOpacity.js +3 -1
- package/lib/commonjs/components/touchables/TouchableOpacity.js.map +1 -1
- package/lib/commonjs/fabric/RNGestureHandlerButtonNativeComponent.js +4 -6
- package/lib/commonjs/fabric/RNGestureHandlerButtonNativeComponent.js.map +1 -1
- package/lib/commonjs/fabric/RNGestureHandlerRootViewNativeComponent.js +4 -6
- package/lib/commonjs/fabric/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
- package/lib/commonjs/getShadowNodeFromRef.js +12 -9
- package/lib/commonjs/getShadowNodeFromRef.js.map +1 -1
- package/lib/commonjs/handlers/createHandler.js +10 -14
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/handlers/gestureHandlerCommon.js +18 -1
- package/lib/commonjs/handlers/gestureHandlerCommon.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector.js +41 -21
- package/lib/commonjs/handlers/gestures/GestureDetector.js.map +1 -1
- package/lib/commonjs/handlers/gestures/eventReceiver.js +6 -5
- package/lib/commonjs/handlers/gestures/eventReceiver.js.map +1 -1
- package/lib/commonjs/handlers/gestures/gesture.js +11 -2
- package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
- package/lib/commonjs/index.js +0 -14
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/init.js +10 -1
- package/lib/commonjs/init.js.map +1 -1
- package/lib/commonjs/jestUtils/index.js +20 -0
- package/lib/commonjs/jestUtils/index.js.map +1 -0
- package/lib/commonjs/{jestUtils.js → jestUtils/jestUtils.js} +12 -12
- package/lib/commonjs/jestUtils/jestUtils.js.map +1 -0
- package/lib/commonjs/utils.js +23 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/GestureHandler.js +4 -1
- package/lib/commonjs/web/GestureHandler.js.map +1 -1
- package/lib/module/GestureHandlerRootView.android.js +7 -2
- package/lib/module/GestureHandlerRootView.android.js.map +1 -1
- package/lib/module/GestureHandlerRootView.js +5 -0
- package/lib/module/GestureHandlerRootView.js.map +1 -1
- package/lib/module/GestureHandlerRootView.web.js +6 -0
- package/lib/module/GestureHandlerRootView.web.js.map +1 -0
- package/lib/module/RNGestureHandlerModule.js +5 -0
- package/lib/module/RNGestureHandlerModule.js.map +1 -1
- package/lib/module/RNGestureHandlerModule.web.js +4 -1
- package/lib/module/RNGestureHandlerModule.web.js.map +1 -1
- package/lib/module/{EventType.js → TouchEventType.js} +2 -2
- package/lib/module/TouchEventType.js.map +1 -0
- package/lib/module/components/GestureButtons.js.map +1 -1
- package/lib/module/components/GestureHandlerButton.js +2 -2
- package/lib/module/components/GestureHandlerButton.js.map +1 -1
- package/lib/module/components/touchables/GenericTouchable.js +2 -0
- package/lib/module/components/touchables/GenericTouchable.js.map +1 -1
- package/lib/module/components/touchables/TouchableOpacity.js +4 -2
- package/lib/module/components/touchables/TouchableOpacity.js.map +1 -1
- package/lib/module/fabric/RNGestureHandlerButtonNativeComponent.js +5 -7
- package/lib/module/fabric/RNGestureHandlerButtonNativeComponent.js.map +1 -1
- package/lib/module/fabric/RNGestureHandlerRootViewNativeComponent.js +5 -8
- package/lib/module/fabric/RNGestureHandlerRootViewNativeComponent.js.map +1 -1
- package/lib/module/getShadowNodeFromRef.js +11 -8
- package/lib/module/getShadowNodeFromRef.js.map +1 -1
- package/lib/module/handlers/createHandler.js +10 -17
- package/lib/module/handlers/createHandler.js.map +1 -1
- package/lib/module/handlers/gestureHandlerCommon.js +11 -1
- package/lib/module/handlers/gestureHandlerCommon.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector.js +41 -22
- package/lib/module/handlers/gestures/GestureDetector.js.map +1 -1
- package/lib/module/handlers/gestures/eventReceiver.js +6 -7
- package/lib/module/handlers/gestures/eventReceiver.js.map +1 -1
- package/lib/module/handlers/gestures/gesture.js +10 -2
- package/lib/module/handlers/gestures/gesture.js.map +1 -1
- package/lib/module/index.js +0 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/init.js +6 -1
- package/lib/module/init.js.map +1 -1
- package/lib/module/jestUtils/index.js +2 -0
- package/lib/module/jestUtils/index.js.map +1 -0
- package/lib/module/{jestUtils.js → jestUtils/jestUtils.js} +12 -12
- package/lib/module/jestUtils/jestUtils.js.map +1 -0
- package/lib/module/utils.js +17 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/GestureHandler.js +4 -1
- package/lib/module/web/GestureHandler.js.map +1 -1
- package/lib/typescript/GestureHandlerRootView.web.d.ts +5 -0
- package/lib/typescript/RNGestureHandlerModule.d.ts +1 -0
- package/lib/typescript/RNGestureHandlerModule.web.d.ts +1 -0
- package/lib/typescript/{EventType.d.ts → TouchEventType.d.ts} +2 -2
- package/lib/typescript/components/GestureButtons.d.ts +18 -6
- package/lib/typescript/components/touchables/TouchableOpacity.d.ts +5 -1
- package/lib/typescript/fabric/RNGestureHandlerButtonNativeComponent.d.ts +13 -0
- package/lib/typescript/fabric/RNGestureHandlerRootViewNativeComponent.d.ts +5 -0
- package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +1 -1
- package/lib/typescript/handlers/gestureHandlerCommon.d.ts +5 -3
- package/lib/typescript/handlers/gestures/GestureDetector.d.ts +0 -3
- package/lib/typescript/handlers/gestures/eventReceiver.d.ts +2 -0
- package/lib/typescript/handlers/gestures/gesture.d.ts +2 -0
- package/lib/typescript/index.d.ts +0 -1
- package/lib/typescript/init.d.ts +1 -0
- package/lib/typescript/jestUtils/index.d.ts +1 -0
- package/lib/typescript/{jestUtils.d.ts → jestUtils/jestUtils.d.ts} +18 -18
- package/lib/typescript/utils.d.ts +2 -0
- package/lib/typescript/web/GestureHandler.d.ts +1 -1
- package/package.json +5 -2
- package/src/GestureHandlerRootView.android.tsx +8 -2
- package/src/GestureHandlerRootView.tsx +6 -0
- package/src/GestureHandlerRootView.web.tsx +12 -0
- package/src/RNGestureHandlerModule.ts +7 -0
- package/src/RNGestureHandlerModule.web.ts +2 -0
- package/src/{EventType.ts → TouchEventType.ts} +2 -2
- package/src/components/GestureButtons.tsx +21 -7
- package/src/components/GestureHandlerButton.tsx +2 -2
- package/src/components/touchables/GenericTouchable.tsx +2 -0
- package/src/components/touchables/TouchableOpacity.tsx +6 -2
- package/src/fabric/RNGestureHandlerButtonNativeComponent.ts +27 -0
- package/src/fabric/RNGestureHandlerRootViewNativeComponent.ts +12 -0
- package/src/getShadowNodeFromRef.ts +12 -9
- package/src/handlers/createHandler.ts +7 -17
- package/src/handlers/gestureHandlerCommon.ts +19 -2
- package/src/handlers/gestures/GestureDetector.tsx +64 -31
- package/src/handlers/gestures/eventReceiver.ts +6 -6
- package/src/handlers/gestures/gesture.ts +13 -2
- package/src/index.ts +0 -1
- package/src/init.ts +8 -1
- package/src/jestUtils/index.ts +1 -0
- package/src/{jestUtils.ts → jestUtils/jestUtils.ts} +21 -21
- package/src/utils.ts +20 -0
- package/src/web/GestureHandler.ts +7 -1
- package/ios/RNTouchEventType.h +0 -9
- package/lib/commonjs/EventType.js.map +0 -1
- package/lib/commonjs/jestUtils.js.map +0 -1
- package/lib/module/EventType.js.map +0 -1
- package/lib/module/jestUtils.js.map +0 -1
- package/src/fabric/RNGestureHandlerButtonNativeComponent.js +0 -27
- package/src/fabric/RNGestureHandlerRootViewNativeComponent.js +0 -19
package/RNGestureHandler.podspec
CHANGED
@@ -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'
|
package/android/build.gradle
CHANGED
@@ -38,7 +38,7 @@ def shouldUseCommonInterfaceFromReanimated() {
|
|
38
38
|
def json = new JsonSlurper().parseText(inputFile.text)
|
39
39
|
def reanimatedVersion = json.version as String
|
40
40
|
def (major, minor, patch) = reanimatedVersion.tokenize('.')
|
41
|
-
return Integer.parseInt(major) == 2 && Integer.parseInt(minor) >= 3
|
41
|
+
return (Integer.parseInt(major) == 2 && Integer.parseInt(minor) >= 3) || Integer.parseInt(major) == 3
|
42
42
|
} else {
|
43
43
|
return false
|
44
44
|
}
|
@@ -76,6 +76,11 @@ android {
|
|
76
76
|
}
|
77
77
|
}
|
78
78
|
|
79
|
+
compileOptions {
|
80
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
81
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
82
|
+
}
|
83
|
+
|
79
84
|
if (isNewArchitectureEnabled()) {
|
80
85
|
externalNativeBuild {
|
81
86
|
ndkBuild {
|
@@ -101,8 +106,11 @@ android {
|
|
101
106
|
|
102
107
|
// Include "common/" only when it's not provided by Reanimated to mitigate
|
103
108
|
// multiple definitions of the same class preventing build
|
104
|
-
if (
|
109
|
+
if (shouldUseCommonInterfaceFromReanimated()) {
|
110
|
+
srcDirs += 'reanimated/src/main/java'
|
111
|
+
} else {
|
105
112
|
srcDirs += 'common/src/main/java'
|
113
|
+
srcDirs += 'noreanimated/src/main/java'
|
106
114
|
}
|
107
115
|
|
108
116
|
if (isNewArchitectureEnabled()) {
|
@@ -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.
|
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
|
-
|
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
|
package/android/noreanimated/src/main/java/com/swmansion/gesturehandler/ReanimatedEventDispatcher.kt
ADDED
@@ -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
|
+
}
|
package/android/reanimated/src/main/java/com/swmansion/gesturehandler/ReanimatedEventDispatcher.kt
ADDED
@@ -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
|
+
}
|
@@ -134,10 +134,18 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>(), R
|
|
134
134
|
|
135
135
|
private fun applyRippleEffectWhenNeeded(selectable: Drawable): Drawable {
|
136
136
|
val rippleColor = rippleColor
|
137
|
-
if (
|
137
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && selectable is RippleDrawable) {
|
138
138
|
val states = arrayOf(intArrayOf(android.R.attr.state_enabled))
|
139
|
-
val
|
140
|
-
|
139
|
+
val colorStateList = if (rippleColor != null) {
|
140
|
+
val colors = intArrayOf(rippleColor)
|
141
|
+
ColorStateList(states, colors)
|
142
|
+
} else {
|
143
|
+
// if rippleColor is null, reapply the default color
|
144
|
+
context.theme.resolveAttribute(android.R.attr.colorControlHighlight, resolveOutValue, true)
|
145
|
+
val colors = intArrayOf(resolveOutValue.data)
|
146
|
+
ColorStateList(states, colors)
|
147
|
+
}
|
148
|
+
|
141
149
|
selectable.setColor(colorStateList)
|
142
150
|
}
|
143
151
|
|
package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEnabledRootView.kt
CHANGED
@@ -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
|
-
|
19
|
-
|
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
|
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
|
-
|
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
|
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
|
-
//
|
635
|
-
|
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)
|
package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootView.kt
CHANGED
@@ -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
|
}
|
package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerStateChangeEvent.kt
CHANGED
@@ -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
|
package/ios/RNGestureHandler.h
CHANGED
@@ -26,7 +26,7 @@ if (value != nil) { recognizer.prop = [RCTConvert type:value]; }\
|
|
26
26
|
|
27
27
|
@protocol RNGestureHandlerEventEmitter
|
28
28
|
|
29
|
-
- (void)
|
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)
|
77
|
+
- (void)sendEvent:(nonnull RNGestureHandlerStateChange *)event;
|
78
78
|
- (void)sendTouchEventInState:(RNGestureHandlerState)state
|
79
79
|
forViewWithTag:(nonnull NSNumber *)reactTag;
|
80
80
|
|
package/ios/RNGestureHandler.m
CHANGED
@@ -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
|
-
|
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
|
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
|
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
|
246
|
+
[self sendEvent:touchEvent];
|
234
247
|
}
|
235
248
|
}
|
236
249
|
|
237
|
-
- (void)
|
250
|
+
- (void)sendEvent:(RNGestureHandlerStateChange *)event
|
238
251
|
{
|
239
|
-
[self.emitter
|
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
|
264
|
+
[self.emitter sendEvent:event withActionType:self.actionType];
|
252
265
|
}
|
253
266
|
|
254
267
|
- (RNGestureHandlerState)recognizerState
|
Binary file
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
+
<plist version="1.0">
|
4
|
+
<dict>
|
5
|
+
<key>SchemeUserState</key>
|
6
|
+
<dict>
|
7
|
+
<key>RNGestureHandler-tvOS.xcscheme_^#shared#^_</key>
|
8
|
+
<dict>
|
9
|
+
<key>orderHint</key>
|
10
|
+
<integer>1</integer>
|
11
|
+
</dict>
|
12
|
+
<key>RNGestureHandler.xcscheme_^#shared#^_</key>
|
13
|
+
<dict>
|
14
|
+
<key>orderHint</key>
|
15
|
+
<integer>0</integer>
|
16
|
+
</dict>
|
17
|
+
</dict>
|
18
|
+
</dict>
|
19
|
+
</plist>
|
@@ -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])
|
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 =
|
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
|
-
|
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 "
|
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:(
|
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:(
|
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 =
|
114
|
+
eventType = RNGHTouchEventTypeUndetermined;
|
115
115
|
}
|
116
116
|
|
117
117
|
return [[RNGestureHandlerEventExtraData alloc]
|