Skip to content

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

@silencer07

Description

@silencer07

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions