Skip to content

Commit ee3e71f

Browse files
fabOnReactfacebook-github-bot
authored andcommitted
onKeyPress event not fired with numeric keys (#29046)
Summary: This issue fixes #19507 fixes #30475 onKeyPress event not fired for numeric keyboard The TextInput onKeyPress event is not fired when pressing numeric keys on Android. The method sendKeyEvent will dispatchKeyEvent only for: - ENTER_KEY_VALUE - KEYCODE_DEL (delete key) The solution proposed is trigger dispatchKeyEvent for KeyEvents with event.getUnicodeChar() value included between 47 and 58 (numeric keys 0-9) ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [Fixed] - onKeyPress event not fired with numeric keys Pull Request resolved: #29046 Test Plan: **<details><summary>CLICK TO OPEN TESTS RESULTS</summary>** <p> | **BEFORE** | **AFTER** | |:-------------------------:|:-------------------------:| | <img src="https://user-images.githubusercontent.com/24992535/83673015-7ce2a000-a5d7-11ea-9c1d-32a5f5605687.gif" width="300" height="" /> | <img src="https://user-images.githubusercontent.com/24992535/83673017-7f44fa00-a5d7-11ea-8d93-edf1f61f7023.gif" width="300" height="" /> | </p> </details> Reviewed By: hramos, cortinico Differential Revision: D30427789 Pulled By: sshic fbshipit-source-id: b4e17ab94daa59fe28de5a5141b0fdd49bab72e3
1 parent 4841e1b commit ee3e71f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java

+3
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,13 @@ public boolean deleteSurroundingText(int beforeLength, int afterLength) {
131131
@Override
132132
public boolean sendKeyEvent(KeyEvent event) {
133133
if (event.getAction() == KeyEvent.ACTION_DOWN) {
134+
boolean isNumberKey = event.getUnicodeChar() < 58 && event.getUnicodeChar() > 47;
134135
if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
135136
dispatchKeyEvent(BACKSPACE_KEY_VALUE);
136137
} else if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
137138
dispatchKeyEvent(ENTER_KEY_VALUE);
139+
} else if (isNumberKey) {
140+
dispatchKeyEvent(String.valueOf(event.getNumber()));
138141
}
139142
}
140143
return super.sendKeyEvent(event);

0 commit comments

Comments
 (0)