Skip to content

Commit 5741a1b

Browse files
committed
fixed native gesture
1 parent d0bf8a4 commit 5741a1b

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class RNGestureHandlerDetectorView(context: Context) : ReactViewGroup(context) {
1313
private val reactContext: ThemedReactContext
1414
get() = context as ThemedReactContext
1515
private var handlersToAttach: List<Int>? = null
16-
private var nativeHandlersToAttach: MutableSet<Int> = mutableSetOf()
16+
private var nativeHandlers: MutableSet<Int> = mutableSetOf()
1717
private var attachedHandlers: MutableSet<Int> = mutableSetOf()
1818
private var moduleId: Int = -1
1919

@@ -40,7 +40,6 @@ class RNGestureHandlerDetectorView(context: Context) : ReactViewGroup(context) {
4040
private fun shouldAttachGestureToChildView(tag: Int): Boolean {
4141
val registry = RNGestureHandlerModule.registries[moduleId]
4242
?: throw Exception("Tried to access a non-existent registry")
43-
4443
return registry.getHandler(tag)?.wantsToAttachDirectlyToView() ?: false
4544
}
4645

@@ -77,14 +76,15 @@ class RNGestureHandlerDetectorView(context: Context) : ReactViewGroup(context) {
7776
// It might happen that `attachHandlers` will be called before children are added into view hierarchy. In that case we cannot
7877
// attach `NativeViewGestureHandlers` here and we have to do it in `addView` method.
7978
if (shouldAttachGestureToChildView(tag)) {
80-
nativeHandlersToAttach.add(tag)
79+
nativeHandlers.add(tag)
8180
} else {
8281
registry.attachHandlerToView(tag, this.id, GestureHandler.ACTION_TYPE_NATIVE_DETECTOR)
8382

8483
attachedHandlers.add(tag)
8584
}
8685
} else if (entry.value == GestureHandlerMutation.Detach) {
8786
registry.detachHandler(tag)
87+
nativeHandlers.remove(tag)
8888
attachedHandlers.remove(tag)
8989
}
9090
}
@@ -101,24 +101,20 @@ class RNGestureHandlerDetectorView(context: Context) : ReactViewGroup(context) {
101101
val registry = RNGestureHandlerModule.registries[moduleId]
102102
?: throw Exception("Tried to access a non-existent registry")
103103

104-
for (tag in nativeHandlersToAttach) {
104+
for (tag in nativeHandlers) {
105105
registry.attachHandlerToView(tag, childId, GestureHandler.ACTION_TYPE_NATIVE_DETECTOR)
106106

107107
attachedHandlers.add(tag)
108108
}
109-
110-
nativeHandlersToAttach.clear()
111109
}
112110

113111
private fun detachNativeGestureHandlers() {
114112
val registry = RNGestureHandlerModule.registries[moduleId]
115113
?: throw Exception("Tried to access a non-existent registry")
116114

117-
for (tag in attachedHandlers) {
118-
if (shouldAttachGestureToChildView(tag)) {
119-
registry.detachHandler(tag)
120-
attachedHandlers.remove(tag)
121-
}
115+
for (tag in nativeHandlers) {
116+
registry.detachHandler(tag)
117+
attachedHandlers.remove(tag)
122118
}
123119
}
124120

0 commit comments

Comments
 (0)