react-native-keyevent icon indicating copy to clipboard operation
react-native-keyevent copied to clipboard

Enter key not triggered

Open matthiasleitner opened this issue 5 years ago • 2 comments

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?

matthiasleitner avatar Sep 04 '20 12:09 matthiasleitner

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.

matthiasleitner avatar Sep 07 '20 06:09 matthiasleitner