React-native-navigation: How to disable "hardware back" button on Android, so that I can stop user dismiss my modal?

Created on 26 Apr 2017  路  6Comments  路  Source: wix/react-native-navigation

I just want to do:

In my "app.android.js" file (it is the App entry file), I do a check, when a user has not logined before, I will show the "loginScreen" as the home screen, otherwise show the "homeScreen".

However, I got a confusing issue: when user do login in "loginScreen", I push the "HomeScreen" to "this.props.navigator". Things seems OK, but once user touch the "hardware back" button, the "loginScreen" shows again~~~

Am i misusing it?

Most helpful comment

You can set overrideBackPress to true in your model config. You can then catch the event using setOnNavigatorEvent

All 6 comments

You can set overrideBackPress to true in your model config. You can then catch the event using setOnNavigatorEvent

@Ehesp thanks for your reply.
Actually, I misused it before, "this.props.navigator.resetTo" did a good job for me.

@Ehesp That solution does not work for me with the latset releases of RNN(tried 1.1.113 -> master-branch). If I set _overrideBackPress = true_, the click-event is overridden but it does not generate an event for the _setOnNavigatorEvent_. Am I missing something crucial in order to use this right? I'm in dire need for this to work properly

@em222iv You're not getting backPress event in your modal?

@guyca I'm not getting the event at all.

this.props.navigator.setOnNavigatorEvent((event) => {
event <= when clicking the "back button" in android i do not receive the "backPress" event when overrideBackPress = true
})

I've tried combining multiple versions of RNN with different versions of react-native (0.43 -> 0.46)

@em222iv This has nothing to do with react-native versions since RNN uses it's own navigation stack.

I've added the following to Modal.js in the example app and the event seems to work as expected

  constructor(props) {
    super(props);
    this.props.navigator.setOnNavigatorEvent((event) => {
      console.log(event);
    })
  }
Was this page helpful?
0 / 5 - 0 ratings