Repository navigation
Report hardware keyboard keys in Android TextInput onKeyPress - #59120
YevheniiKotyrlo wants to merge 3 commits into
Conversation
|
Warning JavaScript API change detected This PR commits an update to
This change was flagged as: |
8276603 to
0725a33
Compare
|
@Abbondanzo with a hardware keyboard on Android, |
0725a33 to
4380cb6
Compare
We shouldn't be reporting modifier-only key presses, that's not something that web does |
4380cb6 to
dfa20e1
Compare
|
Modifier keys pressed alone are no longer reported: Shift, Control, Alt, Meta, Fn, Sym and the lock keys reach |
|
@Abbondanzo has imported this pull request. If you are a Meta employee, you can view this in D135204282. |
javache
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
|
@YevheniiKotyrlo could you regenerate |
|
Added in ed74448:
The missing task is #60446. |
|
@YevheniiKotyrlo can you rebase to fix merge conflicts? |
ed74448 to
369364f
Compare
ReactEditText.onKeyDown reports every key event the view receives, from a hardware keyboard or forwarded by an input method through InputConnection.sendKeyEvent, by its KeyboardEvent.key value, with altKey, ctrlKey, metaKey and shiftKey. A Ctrl or Meta shortcut is named by its key, and so is an Alt shortcut where Alt types nothing on the layout. A key that types a character after a dead key is reported as the composed character, and system keys such as Back and volume are not reported. ReactEditTextInputConnectionWrapper reports only the text an input method types, so no key is reported twice. The key table follows the UI Events key values as Firefox for Android pairs them with key codes, so View onKeyDown also names Home, End, the function keys and Ctrl shortcuts instead of reporting them as Unidentified. Signed-off-by: YevheniiKotyrlo <44449990+YevheniiKotyrlo@users.noreply.github.com>
…ress A modifier key pressed alone - Shift, Control, Alt, Meta, Fn, Sym, Num and the lock keys - types nothing, so onKeyPress does not report it, whether the keyboard sends it to the view or the input method forwards it. It reaches onKeyPress as the altKey, ctrlKey, metaKey and shiftKey of the key it is held with. View onKeyDown keeps reporting it. Signed-off-by: YevheniiKotyrlo <44449990+YevheniiKotyrlo@users.noreply.github.com>
Signed-off-by: YevheniiKotyrlo <44449990+YevheniiKotyrlo@users.noreply.github.com>
369364f to
384dfaf
Compare
|
Rebased onto |
Summary:
With a keyboard attached to an Android phone or tablet,
TextInput'sonKeyPressmisses keys, and which ones depends on the keyboard app. With Samsung Keyboard, the default on Samsung devices, nothing typed on the keyboard is reported: not letters, not Enter, not Backspace. With Gboard, letters and Backspace are reported, but arrows, Home, End and every other key are not. A code field that steps back on Backspace, or a suggestion list moved with the arrow keys, works on the web and not on Android. The docs record the limitation ("on Android only the inputs from soft keyboard are handled"), and #19507 met the same gap on the soft numeric keypad, which #29046 closed for digits only.onKeyPressonly reported what an input method types through theInputConnection. A hardware key reachesReactEditTextas a key event instead: directly with Samsung Keyboard, and throughInputConnection.sendKeyEventwith Gboard. This reports every key event fromReactEditText.onKeyDown, where both arrive, by itsKeyboardEvent.keyvalue, withaltKey,ctrlKey,metaKeyandshiftKey. A modifier key pressed alone (Shift, Control, Alt, Meta, Fn, Sym and the lock keys) is not reported, and neither are system keys (Back, volume, media); a character typed after a dead key is reported composed, as on the web. The input connection wrapper keeps reporting typed text, without itssendKeyEventspecial cases.The names come from the table the View
onKeyDownevent (#54308) already used, completed with the UI Events key values as Firefox for Android pairs them with key codes, soonKeyDownalso names Home, End, the function keys and Ctrl shortcuts that it reported asUnidentified.onKeyDownalone does not cover this: it is behindenableKeyEvents, and it never sees a key that Gboard types as text.Changelog:
[ANDROID] [ADDED] -
TextInputonKeyPressreports hardware keyboard keys by theirKeyboardEvent.keyvalue, withaltKey,ctrlKey,metaKeyandshiftKeyTest Plan:
ReactEditTextKeyPressTestfocuses the view in a window and sends keys the two ways a device does: to the window, as a hardware keyboard does, and through the view's input connection, which the framework delivers back to the view. Onmain10 of its 16 cases fail; with the change all pass.KeyDownEventTestfails onmainwithUnidentifiedfor Home, PageDown, Delete and F1. The ReactAndroid unit suite passes with-PenableWarningsAsErrors=true, as do Flow, both TypeScript checks, ESLint, Prettier and ktfmt, andReactNativeApi.d.tsis regenerated.RNTester release builds with the Playground below, typing a, Shift+B, Ctrl+C, ←, →, Home, End, F1, Alt+E, E, volume up, volume down, ←, Backspace and z on a USB keyboard (registered through
uinput), report:main[]a,shift+B,ctrl+c,ArrowLeft,ArrowRight,Home,End,F1,alt+e,e,ArrowLeft,Backspace,za,B,e,Backspace,za,B,ctrl+c,ArrowLeft,ArrowRight,Home,End,F1,alt+e,e,ArrowLeft,Backspace,zGboard types letters as text and forwards the other keys, so
Barrives withoutshiftKey. Shift, Control, Alt and the volume keys are not reported on either device. An accent key (Alt+E in Android's virtual key map, sent withadb shell input keycombination) reportsalt+Deadand thenéon the S23. The soft keyboard (q, Backspace, Backspace,w) and the soft numeric keypad (1,2, Backspace,3) report the same keys on both builds and both devices.packages/rn-tester/js/examples/Playground/RNTesterPlayground.js