Skip to content

Commit 7e73369

Browse files
committed
Simplify android detector attach logic
1 parent 8ee5c0e commit 7e73369

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ import com.swmansion.gesturehandler.core.GestureHandler
1111
class RNGestureHandlerDetectorView(context: Context) : ReactViewGroup(context) {
1212
private val reactContext: ThemedReactContext
1313
get() = context as ThemedReactContext
14+
private var handlersToAttach: List<Int>? = null
1415
private var attachedHandlers = listOf<Int>()
1516
private var moduleId: Int = -1
1617
private var animatedEvents: Boolean = false
1718

1819
fun setHandlerTags(handlerTags: ReadableArray?) {
1920
val newHandlers = handlerTags?.toArrayList()?.map { (it as Double).toInt() } ?: emptyList()
2021
if (moduleId == -1) {
21-
attachedHandlers = newHandlers
22+
// It's possible that handlerTags will be set before module id. In that case, store
23+
// the handler ids and attach them after setting module id.
24+
handlersToAttach = newHandlers
2225
return
2326
}
2427

@@ -28,9 +31,8 @@ class RNGestureHandlerDetectorView(context: Context) : ReactViewGroup(context) {
2831
fun setModuleId(id: Int) {
2932
if (this.moduleId == -1) {
3033
this.moduleId = id
31-
val handlersToAttach = this.attachedHandlers
32-
this.attachedHandlers = emptyList()
33-
this.attachHandlers(handlersToAttach)
34+
this.attachHandlers(handlersToAttach ?: return)
35+
handlersToAttach = null
3436
} else {
3537
throw Exception("Tried to change moduleId of a native detector")
3638
}

0 commit comments

Comments
 (0)