Repository navigation
Android: a TextInput with its context menu hidden takes no long press - #59130
YevheniiKotyrlo wants to merge 1 commit into
Conversation
Device evidence — before / afterUNFIXED — Held on a word, the press selects it and focuses the field, and the keyboard stays down after the release. FIXED — Nothing happens while the press is held; lifting it on the field places the caret and opens the keyboard.
RedMagic NX809J, Android 16 (API 36): RNTester debug builds of |
02736ea to
ff5f305
Compare
A long press on an Android TextInput selects the word under the finger and focuses the field so the text action menu can act on the selection. With contextMenuHidden set the menu never opens, so the long press only selected a word nothing could act on and focused the field with the keyboard down. ReactEditText is not long-clickable while contextMenuHidden is set: View never starts the long press, accessibility no longer offers one, and a press held on the field ends as a click when it lifts on it. TextView turns long-clicking back on when setInputType sets a key listener and when onAttachedToWindow makes the text selectable, so the gate sits in setLongClickable.
ff5f305 to
bfa64fa
Compare
Visual regressionNo visual differences at ios: no capture |
|
@Abbondanzo this and #59136 are the Android |


Summary:
On Android, a
TextInputwithcontextMenuHiddenstill runs the long press that exists to open that menu. Holding a word selects it and focuses the field without opening the keyboard, and the menu never appears. Holding and sliding off the field before lifting leaves it focused too. The flag refused the long press until #45014, which replaced the long-click listener that consumed it with the action mode callback, and that callback runs only afterEditorhas selected the word.ReactEditTextis no longer long-clickable whilecontextMenuHiddenis set, soViewnever starts the long press and accessibility stops offering one. A held press then ends like a tap: lifted on the field, it places the caret and opens the keyboard; lifted elsewhere, it does nothing.TextViewturns long-clicking back on when it sets a key listener, which every keyboard type change does, and whenonAttachedToWindowmakes the text selectable, so the gate is insetLongClickable.Related: #59136, which keeps a mouse right-click from opening the menu under the same flag.
Changelog:
[ANDROID] [FIXED] - A
TextInputwithcontextMenuHiddenno longer selects a word and takes focus on a long pressTest Plan:
New
ReactTextInputPropertyTest.testContextMenuHidden: the field is long-clickable by default; withcontextMenuHiddenit is not, and stays that way after setting the flag again, a keyboard type change, andsetTextIsSelectable(true)(whatonAttachedToWindowcalls); clearing the flag makes it long-clickable again. Onmainit fails at the second assertion.RNTester's Playground (
RNTesterPlayground.js) with this component:Playground
Press and hold the word "hold" for a second, then lift. On
mainthe word is selected and the field focused while it is held, and the keyboard stays down after the release: on Android 14 and 16 the caret moves to the end of the word, and on Android 10 the word stays selected. With this change nothing happens while it is held, and the release places the caret where the finger lifts and opens the keyboard. Press and hold, then slide off the field and lift: onmainthe field ends up focused, and with this change it stays unfocused. I checked it on RNTester debug builds ofmainand this branch on Android 10, 14 and 16 phones, with the same result on every round; the captures and readings are in this comment.ReactTextInputPropertyTest,ReactEditTextKeyEventTestandReactEditTextOutlineTestpass under./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest -PenableWarningsAsErrors=true(41 tests), and ktfmt, asnode ./scripts/format-kotlin.js --checkruns it, leaves both changed Kotlin files unchanged.