Skip to content

Commit 7b46018

Browse files
authored
[Android] Dispatch cancel event only when root view is enabled (#4123)
## Description Currently, RootView on Android always dispatches `ACTION_CANCEL` before starting to process the new event stream. When multiple root views are rendered in the app, this will have a "waterfall" effect of each root view dispatching its own `ACTION_CANCEL` on top of passing the one received from the parent. This PR addresses that by requiring the root view to be enabled to dispatch the cancel event. ## Test plan Checked the `Nested touchables` example
1 parent 93e3a32 commit 7b46018

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class RNGestureHandlerRootView(context: Context?) : ReactViewGroup(context) {
4949
// When starting a new event stream, dispatch CANCEL event so the subtree
5050
// can clean up its internal state that may be stale due to Gesture Handler
5151
// starting to intercept events mid-stream.
52-
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
52+
if (rootViewEnabled && event.actionMasked == MotionEvent.ACTION_DOWN) {
5353
val cancelEvent = MotionEvent.obtain(event).apply { action = MotionEvent.ACTION_CANCEL }
5454
super.dispatchTouchEvent(cancelEvent)
5555
cancelEvent.recycle()

0 commit comments

Comments
 (0)