2

running into an interesting one with ReactNative.

On the Android side, anywhere in my app, when a modal is open, if the user does a Long Press on the Home Button, then the app crashes.

It's fine for a single tap, and it doesn't have issues when the screen is not a Modal. iOS does not have any issues.

On a semi-related note, if we use the touchid, and a fingerprint is registered, the app does not crash, and the user is signed in. This tells me there should be an event I can catch to deal with this... but I don't know what that event may be.

The modal is very basic (I have removed styles for clarity, however they are all added like this <View style = {styles.modalStyle}>

Modal:

<Modal
    onRequestClose={()=> {
        props.waitingForResponse(false);
    }}
    visible={props.visible}>
    <View>
        <View>
            <View>
                <Image source={modalImageSrc} />
                <Text>
                    {props.showErrorMesage ? "Error" : props.title}
                </Text>
                <Text>{props.showErrorMesage ? "Item disabled" : props.text}</Text>
            </View>
            <View>
                <Button
                    onPress={()=> {
                        props.waitingForResponse(false);
                    }}
                    title="Cancel"
                />
            </View>
        </View>
    </View>
</Modal>

All Modals are created in a similar fashion.

As of this point, I thought I could add something directly to the Modal itself - an onError or onPause (nope, those events don't exist for Modals?!?)... I can't seem to "catch" the long hold home press in this environment So now, I am trying to override some functions on the Java side - in MainActivity.java, I tried an Override of the onKeyUp, onKeyDown, onKeyLongPress - but none of these are currently triggered on the long-press of KeyEvent.KEYCODE_HOME. (See below)

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if( keyCode == KeyEvent.KEYCODE_HOME){
        Toast.makeText(MainActivity.this, "onKeyDown KeyEvent.KEYCODE_HOME", Toast.LENGTH_LONG).show();
        event.startTracking();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if( keyCode == KeyEvent.KEYCODE_HOME){
        Toast.makeText(MainActivity.this, "onKeyUp KeyEvent.KEYCODE_HOME", Toast.LENGTH_LONG).show();
        return true;
    }
    return super.onKeyUp(keyCode, event);
}
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    if( keyCode == KeyEvent.KEYCODE_HOME){
        Toast.makeText(MainActivity.this, "onKeyLongPress KeyEvent.KEYCODE_HOME", Toast.LENGTH_LONG).show();
        return true;
    }
    return super.onKeyLongPress(keyCode, event);
}

But I don't seem to be finding any joy.

Has anyone come across this? Any recommendations on where else I could look? Switching to a 3rd party isn't an option at this point, but may be in the future if we can't get this resolved.

Thanks!!

Tracey
  • 96
  • 4
  • If someone knows the name of an event that I could override on the java side to catch a home-button long press, that would be fantastic also! – Tracey Aug 10 '17 at 17:03

0 Answers0