Skip to content

fix: show the soft keyboard when a long-press starts text selection in TextInput on Android#57471

Open
idoyana wants to merge 1 commit into
react:mainfrom
idoyana:fix/android-long-press-selection-keyboard
Open

fix: show the soft keyboard when a long-press starts text selection in TextInput on Android#57471
idoyana wants to merge 1 commit into
react:mainfrom
idoyana:fix/android-long-press-selection-keyboard

Conversation

@idoyana

@idoyana idoyana commented Jul 7, 2026

Copy link
Copy Markdown

Summary

On Android, long-pressing text in a TextInput while the soft keyboard is hidden starts text selection (highlight + Cut/Copy toolbar) and focuses the field — but the soft keyboard never appears, leaving the user unable to type over the selection. This happens both when the input was unfocused and when it was focused with the keyboard dismissed.

Root cause: ReactEditText.onAttachedToWindow() calls super.setTextIsSelectable(true) (a removeClippedSubviews workaround, #6805). That makes isTextSelectable() return true, so the platform Editor#startActionModeInternal() skips its own "Show the IME to be able to replace text" branch — it is gated on !isTextSelectable() and deliberately skips read-only selectable text, which every RN TextInput now masquerades as. RN's own keyboard paths cover only clicks and programmatic focus (see the comment on requestFocusProgrammatically()); focus gained through long-press selection is a third path neither covers.

Fix: compensate in ReactEditText, mirroring the platform branch it opted out of —

  • request the keyboard when a selection/insertion action mode is created (onCreateActionMode), and
  • when focus is gained with a non-collapsed selection (onFocusChanged) — the action mode can be created before the view becomes the IME-served view, so this re-requests once focus has landed.

Both sites go through a shared guard (isEnabled — the editable prop maps to it, isInTouchMode, showSoftInputOnFocus) that mirrors requestFocusProgrammatically(), so read-only inputs and showSoftInputOnFocus={false} are unaffected. showSoftInput is idempotent, so an already-visible keyboard is a no-op.

Fixes #57470 (reproduced there with a bare TextInput in a plain View, no third-party components).

Changelog:

[ANDROID] [FIXED] - Show the soft keyboard when a long-press starts text selection in TextInput

Test Plan:

RNTester TextInput example on a Pixel 10 Pro (Android 16, Gboard), -PreactNativeArchitectures=arm64-v8a:

Before (main, 0015d1e4f9) — long-press a word in the prefilled "Default color text" field with the keyboard hidden:

  • word selected + Cut/Copy toolbar, no keyboard
  • logcat: zero ImeTracker events; dumpsys input_methodmInputShown=false

After (this change) — same gestures:

  • Unfocused field, long-press a word → selection + toolbar + keyboard appears:
    ImeTracker: onRequestShow at ORIGIN_CLIENT reason SHOW_SOFT_INPUTonShown; mInputShown=true
  • Focused field, dismiss keyboard (back), long-press → keyboard appears (same trace)
  • Plain tap → unchanged (framework fromUser=true request + RN's existing click path, same as before the change)
  • Selection is preserved and the selection toolbar stays up while the keyboard shows — matching stock EditText behavior

./gradlew :packages:react-native:ReactAndroid:ktfmtCheck passes.

…Input on Android

ReactEditText marks itself textIsSelectable in onAttachedToWindow (a
removeClippedSubviews workaround, react#6805), which makes the platform
Editor treat every RN TextInput as read-only selectable text and skip
its "Show the IME to be able to replace text" branch when a selection
action mode starts (Editor#startActionModeInternal gates that branch on
!isTextSelectable()). RN's own keyboard paths only cover clicks and
programmatic focus, so long-pressing to select text in an unfocused
input — or in a focused input after the keyboard was dismissed — left
the user with a selection toolbar and no keyboard.

Compensate in ReactEditText: request the keyboard when a selection or
insertion action mode is created, and when focus is gained with a
non-collapsed selection (the action mode can precede focus). Guarded by
isEnabled (the editable prop), isInTouchMode, and showSoftInputOnFocus,
mirroring both requestFocusProgrammatically() and the platform branch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@meta-cla

meta-cla Bot commented Jul 7, 2026

Copy link
Copy Markdown

Hi @idoyana!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Jul 7, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 7, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jul 7, 2026
@meta-codesync

meta-codesync Bot commented Jul 8, 2026

Copy link
Copy Markdown

@Abbondanzo has imported this pull request. If you are a Meta employee, you can view this in D110990211.

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] Long-pressing a TextInput that is unfocused (or focused with the keyboard dismissed) starts text selection but never shows the soft keyboard

1 participant