diff --git a/packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt b/packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt index 9ced951328..e021bdf90b 100644 --- a/packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +++ b/packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt @@ -366,9 +366,17 @@ class GestureHandlerOrchestrator( } /** - * Cancels all handlers created using API v1 and v2 + * Cancels the handlers that lose to a native view taking the touch lock: the ones created using + * API v1 and v2, and the [NativeViewGestureHandler] a button manages for itself. + * + * The button's handler is attached with [GestureHandler.ACTION_TYPE_NONE] - it dispatches its + * events natively rather than through an action - so an action type check alone leaves it + * running. It has to be cancelled here as well, or a touch that a native view claims still ends + * the button handler and fires a press. The root view's own handler shares that action type and + * must keep running, hence the type check rather than a plain [GestureHandler.ACTION_TYPE_NONE] + * one. */ - fun cancelAllLegacyHandlers() { + fun cancelHandlersLosingToNativeGesture() { val handlersToProcess = obtainHandlerList() handlersToProcess.addAll(gestureHandlers) @@ -377,7 +385,8 @@ class GestureHandlerOrchestrator( if (it.actionType == GestureHandler.ACTION_TYPE_JS_FUNCTION_OLD_API || it.actionType == GestureHandler.ACTION_TYPE_JS_FUNCTION_NEW_API || it.actionType == GestureHandler.ACTION_TYPE_REANIMATED_WORKLET || - it.actionType == GestureHandler.ACTION_TYPE_NATIVE_ANIMATED_EVENT + it.actionType == GestureHandler.ACTION_TYPE_NATIVE_ANIMATED_EVENT || + (it is NativeViewGestureHandler && it.actionType == GestureHandler.ACTION_TYPE_NONE) ) { it.cancel() } diff --git a/packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt b/packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt index 57979ea310..11d73416af 100644 --- a/packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt +++ b/packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt @@ -120,7 +120,7 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView: if (orchestrator != null && !passingTouch) { // if we are in the process of delivering touch events via GH orchestrator, we don't want to // treat it as a native gesture capturing the lock - orchestrator.cancelAllLegacyHandlers() + orchestrator.cancelHandlersLosingToNativeGesture() } }