Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 29449

Return true from onKeyDown stops the event propagation to React native

$
0
0

I am trying to detect the LongPress event of any keys. Here is the MainActivity.java

@Override
    public boolean onKeyDown( int keyCode, KeyEvent event ) {
        if(Seek.LONG_SEEK_BUTTONS.contains(keyCode)) {
            event.startTracking();
            Log.e(LOG_TAG,"onKeyDown"+event.toString());
            Log.e(LOG_TAG,"keyevent "+event.isLongPress());
            return true;
        }
        return super.onKeyDown( keyCode, event );
    }

    @Override
    public boolean onKeyLongPress( int keyCode, KeyEvent event ) {
        if(Seek.LONG_SEEK_BUTTONS.contains(keyCode) ) {
            seekManager.OnLongKeyPress(keyCode, event);
            Log.e(LOG_TAG,"onKeyLongPress"+event.toString());
            Log.e(LOG_TAG,"keyevent "+event.isLongPress());
            return true;
        }
        return super.onKeyLongPress( keyCode, event );
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if(mReactInstanceManager != null) {
            seek.OnKeyUp(keyCode, event);

        }

        return super.onKeyUp(keyCode, event);
    }

This is working and i am receiving calls in onKeyLongPress. But this creates another problem in React native layer. Now i am not able to use d-pad left, right top , bottom to select any element. As per my understanding it s happening because because i send true in key down event which stops the event propagation further and RN layer never receive any command to move the cursor.

To fix this error, if i simply return super.onKeyDown( keyCode, event ); from onKeyDown then RN layer controls works as per the expectation but i am no longer able to receive any call in onKeyLongPress event handler.

How can i fix the the control selection error in RN layer and at the same time I should be able to receive long press detection events.

Thanks in advance


Viewing all articles
Browse latest Browse all 29449

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>