Skip to content

Commit a9569cf

Browse files
committed
Update root helper
1 parent 348df89 commit a9569cf

2 files changed

Lines changed: 12 additions & 15 deletions

File tree

packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
2020
NativeRNGestureHandlerModuleSpec(reactContext),
2121
GestureHandlerStateManager {
2222

23-
private val eventDispatcher = RNGestureHandlerEventDispatcher(reactApplicationContext)
2423
val registry: RNGestureHandlerRegistry = RNGestureHandlerRegistry()
24+
private val eventDispatcher = RNGestureHandlerEventDispatcher(reactApplicationContext)
2525
private val interactionManager = RNGestureHandlerInteractionManager()
2626
private val roots: MutableList<RNGestureHandlerRootHelper> = ArrayList()
27+
2728
override fun getName() = NAME
2829

2930
@Suppress("UNCHECKED_CAST")

packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView:
2424
init {
2525
UiThreadUtil.assertOnUiThread()
2626
val wrappedViewTag = wrappedView.id
27-
check(wrappedViewTag >= 1) { "Expect view tag to be set for $wrappedView" }
28-
val module = (context as ThemedReactContext).reactApplicationContext.getNativeModule(
29-
RNGestureHandlerModule::class.java,
30-
)!!
27+
assert(wrappedViewTag >= 1) { "Expect view tag to be set for $wrappedView" }
28+
val module = context.getNativeModule(RNGestureHandlerModule::class.java)!!
3129
val registry = module.registry
3230
rootView = findRootViewTag(wrappedView)
3331
Log.i(
@@ -41,15 +39,9 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView:
4139
).apply {
4240
minimumAlphaForTraversal = MIN_ALPHA_FOR_TOUCH
4341
}
44-
jsGestureHandler = RootViewGestureHandler().apply { tag = -wrappedViewTag }
45-
with(registry) {
46-
registerHandler(jsGestureHandler)
47-
attachHandlerToView(
48-
jsGestureHandler.tag,
49-
wrappedViewTag,
50-
GestureHandler.ACTION_TYPE_JS_FUNCTION_OLD_API,
51-
)
52-
}
42+
jsGestureHandler = RootViewGestureHandler(handlerTag = -wrappedViewTag)
43+
registry.registerHandler(jsGestureHandler)
44+
registry.attachHandlerToView(jsGestureHandler.tag, wrappedViewTag, GestureHandler.ACTION_TYPE_JS_FUNCTION_OLD_API)
5345
module.registerRootHelper(this)
5446
}
5547

@@ -67,7 +59,11 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView:
6759
}
6860
}
6961

70-
internal inner class RootViewGestureHandler : GestureHandler<RootViewGestureHandler>() {
62+
internal inner class RootViewGestureHandler(handlerTag: Int) : GestureHandler<RootViewGestureHandler>() {
63+
init {
64+
this.tag = handlerTag
65+
}
66+
7167
private fun handleEvent(event: MotionEvent) {
7268
val currentState = state
7369

0 commit comments

Comments
 (0)