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

Additional code needed to make the android remote KEYCODE_DPAD_CENTER work #4

Open
silencer07 opened this issue Jan 23, 2024 · 0 comments

Comments

@silencer07
Copy link

Context:

kevinejohn/react-native-keyevent#80

Solution:

add the following code to make DPAD_CENTER work. this ensure that short presses work instead of user needing to long press

const withAndroidMainActivityBody = (config) => {
    // @ts-ignore
    const newConfig = (0, config_plugins_1.withMainActivity)(config, (config) => {
        const newSrc = [
            // ... code omitted, the below lines is what I added
            '@Override',
            'public boolean dispatchKeyEvent(KeyEvent event) {',
            '    if ((event.keyCode == KeyEvent.KEYCODE_ENTER || event.keyCode == KeyEvent.KEYCODE_DPAD_CENTER) && event.getAction() == KeyEvent.ACTION_DOWN) {',
            '        KeyEventModule.getInstance().onKeyDownEvent(event.getKeyCode(), event);',
            '        return false;',
            '    }',
            '    return super.dispatchKeyEvent(event);',
            '}',
        ];
// .... rest of code

Thanks!

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

1 participant