mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
onKeyPress event not fired with numeric keys (#29046)
Summary: This issue fixes https://github.com/facebook/react-native/issues/19507 fixes https://github.com/facebook/react-native/issues/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: https://github.com/facebook/react-native/pull/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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
4841e1bae0
commit
ee3e71f536
+3
@@ -131,10 +131,13 @@ class ReactEditTextInputConnectionWrapper extends InputConnectionWrapper {
|
||||
@Override
|
||||
public boolean sendKeyEvent(KeyEvent event) {
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
boolean isNumberKey = event.getUnicodeChar() < 58 && event.getUnicodeChar() > 47;
|
||||
if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
|
||||
dispatchKeyEvent(BACKSPACE_KEY_VALUE);
|
||||
} else if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
|
||||
dispatchKeyEvent(ENTER_KEY_VALUE);
|
||||
} else if (isNumberKey) {
|
||||
dispatchKeyEvent(String.valueOf(event.getNumber()));
|
||||
}
|
||||
}
|
||||
return super.sendKeyEvent(event);
|
||||
|
||||
Reference in New Issue
Block a user