Skip to content

[Android] Fix text getting selected during gestures#4273

Merged
j-piasecki merged 2 commits into
mainfrom
@jpiasecki/fix-text-getting-selected
Jun 19, 2026
Merged

[Android] Fix text getting selected during gestures#4273
j-piasecki merged 2 commits into
mainfrom
@jpiasecki/fix-text-getting-selected

Conversation

@j-piasecki

Copy link
Copy Markdown
Member

Description

Fixes #3866

When a gesture activates, the root helper's shouldIntercept flips to true, 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 a MOVE event, triggering the long press action.

This PR adds a native view cancellation step - when shouldIntercept flips, all views on the path from the root to the leaf that received the touch receive a synthetic CANCEL event, preventing that from happening.

Views with an active NativeViewGestureHandler attached 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 DOWN coordinates for each pointer instead of the current ones - the goal is to cancel views that have possibly handled the DOWN event and started their own logic.

Test plan

Tested on the issue reproducer

Copilot AI review requested due to automatic review settings June 18, 2026 08:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 RNGestureHandlerRootHelper transitions into interception (shouldIntercept flips to true).
  • Track per-pointer DOWN coordinates in the orchestrator and use them to find the touched view path (leaf-to-root) at the initial touch location.
  • Dispatch a synthetic ACTION_CANCEL to collected views, exempting views still driven by an active/non-conflicting NativeViewGestureHandler.

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.

@j-piasecki j-piasecki requested a review from m-bert June 18, 2026 08:57
@j-piasecki j-piasecki merged commit 3b11fdd into main Jun 19, 2026
3 checks passed
@j-piasecki j-piasecki deleted the @jpiasecki/fix-text-getting-selected branch June 19, 2026 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Text] selectable text gets highlighted while panning inside a ScrollView on Android

3 participants