[Android] Fix text getting selected during gestures#4273
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses Android text selection/long-press side effects that can occur when RNGH begins intercepting mid-gesture by proactively sending a synthetic ACTION_CANCEL to the native view(s) that originally received the touch down sequence (unless that view is explicitly opted into RNGH via an active/non-conflicting NativeViewGestureHandler).
Changes:
- Trigger native-view cancellation when
RNGestureHandlerRootHelpertransitions into interception (shouldInterceptflips totrue). - Track per-pointer
DOWNcoordinates in the orchestrator and use them to find the touched view path (leaf-to-root) at the initial touch location. - Dispatch a synthetic
ACTION_CANCELto collected views, exempting views still driven by an active/non-conflictingNativeViewGestureHandler.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt | Calls into orchestrator to cancel native touches exactly when interception starts. |
| packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt | Tracks pointer down points, collects touched view paths, and dispatches synthetic cancel events with NVGH exemptions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
m-bert
approved these changes
Jun 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #3866
When a gesture activates, the root helper's
shouldInterceptflips totrue, causing it to stop delivering events to the OS touch handling path. If a native view tries to detect a long press, it's possible that the event stream will stop on aMOVEevent, triggering the long press action.This PR adds a native view cancellation step - when
shouldInterceptflips, all views on the path from the root to the leaf that received the touch receive a syntheticCANCELevent, preventing that from happening.Views with an active
NativeViewGestureHandlerattached to them are exempt from that mechanism, since the cancel event would cause them to stop recognizing the event mid-stream and they've been explicitly opted in to the RNGH touch system.Note: the logic to find views to cancel relies on the
DOWNcoordinates for each pointer instead of the current ones - the goal is to cancel views that have possibly handled theDOWNevent and started their own logic.Test plan
Tested on the issue reproducer