diff --git a/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt b/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt index 2c6c277787..d44513339d 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +++ b/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt @@ -325,6 +325,8 @@ class GestureHandlerOrchestrator( return parent === wrapperView } + fun isAnyHandlerActive() = gestureHandlers.any { it?.state == GestureHandler.STATE_ACTIVE } + /** * Transforms an event in the coordinates of wrapperView into the coordinate space of the received view. * diff --git a/android/src/main/java/com/swmansion/gesturehandler/core/NativeViewGestureHandler.kt b/android/src/main/java/com/swmansion/gesturehandler/core/NativeViewGestureHandler.kt index 3fd219d041..64f230a2c8 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/core/NativeViewGestureHandler.kt +++ b/android/src/main/java/com/swmansion/gesturehandler/core/NativeViewGestureHandler.kt @@ -6,6 +6,7 @@ import android.view.View import android.view.ViewConfiguration import android.view.ViewGroup import android.widget.ScrollView +import com.facebook.react.views.scroll.ReactScrollView import com.facebook.react.views.swiperefresh.ReactSwipeRefreshLayout import com.facebook.react.views.textinput.ReactEditText @@ -75,6 +76,7 @@ class NativeViewGestureHandler : GestureHandler() { is NativeViewGestureHandlerHook -> this.hook = view is ReactEditText -> this.hook = EditTextHook(this, view) is ReactSwipeRefreshLayout -> this.hook = SwipeRefreshLayoutHook(this, view) + is ReactScrollView -> this.hook = ScrollViewHook() } } @@ -248,4 +250,8 @@ class NativeViewGestureHandler : GestureHandler() { // oh well ¯\_(ツ)_/¯ } } + + private class ScrollViewHook : NativeViewGestureHandlerHook { + override fun shouldCancelRootViewGestureHandlerIfNecessary() = true + } } diff --git a/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt b/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt index b20ba42229..f6ea6a107f 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt +++ b/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt @@ -59,7 +59,9 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView: private inner class RootViewGestureHandler : GestureHandler() { override fun onHandle(event: MotionEvent, sourceEvent: MotionEvent) { val currentState = state - if (currentState == STATE_UNDETERMINED) { + // we shouldn't stop intercepting events when there is an active handler already, which could happen when + // adding a new pointer to the screen after a handler activates + if (currentState == STATE_UNDETERMINED && (!shouldIntercept || orchestrator?.isAnyHandlerActive() != true)) { begin() shouldIntercept = false }