react-native-keyevent
react-native-keyevent copied to clipboard
Enter key not triggered
Hi,
I am seeing the following issue: react-native-keyevent has been working flawlessly with react-native 0.59 and an early version of react-navigation. I have now upraded to 0.63 and react-navigation 4.4.0. No react-native-key-event stops sending newline characters as soon as the screen is touched.
Any ideas why this would happen?
I found a work around to fix this. Generally it seems to be related to a change in react-native itself that causes other components to capture the 'enter' keyevent.
In MainActivity.java use dispatchKeyEvent to capture the enter key before it can be intercepted from any other listener:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
KeyEventModule.getInstance().onKeyDownEvent(event.getKeyCode(), event);
return false;
}
return super.dispatchKeyEvent(event);
If someone needs full control over key events dispatchKeyEvent would be generally the method to use.