Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enter key not triggered #52

Open
matthiasleitner opened this issue Sep 4, 2020 · 2 comments
Open

Enter key not triggered #52

matthiasleitner opened this issue Sep 4, 2020 · 2 comments

Comments

@matthiasleitner
Copy link

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
Copy link
Author

matthiasleitner commented Sep 7, 2020

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.

@anton-veretenenko
Copy link

anton-veretenenko commented Jan 8, 2023

@matthiasleitner thx, this needs to be in the docs
also a bit of update to catch only keyDown event from displatchKeyEvent

  @Override
  public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
      KeyEventModule.getInstance().onKeyDownEvent(event.getKeyCode(), event);
      return false;
    }
    return super.dispatchKeyEvent(event);
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants