Skip to content

Treat a vertical drag that scrolls a TextInput as a native gesture on Android - #60528

Open
leeseonghyun21 wants to merge 1 commit into
react:mainfrom
leeseonghyun21:fix/android-textinput-drag-native-gesture
Open

leeseonghyun21 wants to merge 1 commit into
react:mainfrom
leeseonghyun21:fix/android-textinput-drag-native-gesture

Conversation

@leeseonghyun21

Copy link
Copy Markdown

Summary:

On Android, a short vertical drag on the text of an unfocused multiline TextInput that has more text than fits scrolls the text, and then, on release:

  • the input gets focus and the keyboard opens, and
  • the input scrolls back to the caret, undoing the drag.

The drag is never handed to native the way a ScrollView drag is. The JS touch stays active, so Pressability treats a short drag inside the input as a press, and TextInput's onPress focuses it on release. Focusing an EditText brings the caret into view, which scrolls the text back.

A drag that cannot scroll the text further (for example, at the end of the text) has a second path to the same result: TextView.onTouchEvent focuses the input itself on ACTION_UP when the touch did not scroll it.

This is separate from #58678, which lets a parent ScrollView take a gesture the input cannot scroll. Here the input does scroll, and the problem is what happens on release.

Changes in ReactEditText.onTouchEvent:

  • Once a vertical drag past the touch slop has scrolled the text, or the text cannot scroll in the drag direction, call NativeGestureUtil.notifyNativeGestureStarted, as ReactScrollView does when it starts dragging. This cancels the JS touch. Waiting for the text to scroll first matters: cancelling earlier also stopped the scroll that was about to start (checked on an emulator).
  • On ACTION_UP / ACTION_CANCEL of that gesture, call notifyNativeGestureEnded.
  • If the input is not focused, pass ACTION_UP of that gesture to TextView as ACTION_CANCEL (a copy, since ancestors keep reading the original event), so TextView does not focus it either.

A tap and a long press behave as before.

Changelog:

[ANDROID] [FIXED] - Dragging the text of an unfocused multiline TextInput no longer focuses it and scrolls it back on release

Test Plan:

RNTester Playground with this reproducer (Pixel 9 Pro Fold emulator, API 36):

<TextInput
  multiline
  defaultValue={/* 30 lines of text */}
  style={{height: 160, borderWidth: 1, fontSize: 16, padding: 8}}
  onFocus={() => console.log('focus')}
/>

The text starts scrolled to the end. Without tapping first, drag down by about 50 px (the text scrolls up) and release; then, from a fresh mount, drag up (the text is already at the end and cannot scroll further) and release. Drags were sent with adb shell input touchscreen swipe (finger, 300 ms).

main this PR
short drag that scrolls, release onFocus, keyboard opens, scroll offset jumps back to the caret (412 → 426) no focus, no keyboard, stays where the drag left it
drag at the end (cannot scroll), release onFocus, keyboard opens no focus, no keyboard
tap focus + keyboard focus + keyboard
long press word selected + keyboard word selected + keyboard

A longer drag (past the press area) did not focus the input on main either; that is the case Pressability already cancels.

ktfmt with the yarn format-check-kotlin settings passes on the changed file.

🤖 Generated with Claude Code

… Android

Signed-off-by: leeseonghyun21 <33210765+leeseonghyun21@users.noreply.github.com>
@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Dec 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant