Commit 9195e52
fix: show the soft keyboard when a long-press starts text selection in TextInput on Android (#57471)
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
Pull Request resolved: #57471
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_method` → `mInputShown=false`
**After (this change)** — same gestures:
- Unfocused field, long-press a word → selection + toolbar + **keyboard appears**:
`ImeTracker: onRequestShow at ORIGIN_CLIENT reason SHOW_SOFT_INPUT` → `onShown`; `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.
Reviewed By: javache
Differential Revision: D110990211
Pulled By: Abbondanzo
fbshipit-source-id: fcb8f362d9fcdb0688bd6c92eda25687b3e42ec41 parent d13d2b0 commit 9195e52
1 file changed
Lines changed: 23 additions & 0 deletions
File tree
- packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput
Lines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
261 | 268 | | |
262 | 269 | | |
263 | 270 | | |
| |||
499 | 506 | | |
500 | 507 | | |
501 | 508 | | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
502 | 517 | | |
503 | 518 | | |
504 | 519 | | |
| |||
909 | 924 | | |
910 | 925 | | |
911 | 926 | | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
912 | 935 | | |
913 | 936 | | |
914 | 937 | | |
| |||
0 commit comments