Tell us which versions you are using:
Hardware back press should close app only when there is no scene to go back to.
App closes on any of the child scene
This is my Router definition
<Router
createReducer={reducerCreate}
getSceneStyle={getSceneStyle}
navBarStyle={styles.navigationBarStyle}
backAndroidHandler={backAndroidHandler}>...</Router>
I am passing backAndroidHandler as empty
const backAndroidHandler = () => {
console.log('Back Handler');
};
Even though I am not handling back press, the app still closes.
Please help.
Fixed the issue by using following:
const reducerCreate = params => {
const defaultReducer = new Reducer(params);
return (state, action) => {
console.log('ACTION:', action, Actions.currentScene);
if (action.type === 'Navigation/BACK') {
console.log(TAG, 'Back Pressed');
if (Actions.currentScene === 'home') {
BackHandler.exitApp();
}
}
if (action.type === 'Navigation/INIT') {
Actions.auth();
}
return defaultReducer(state, action);
};
};
@tusharv-bidchat
const onBackAndroid = () => {
return false; // Return true to stay, or return false to exit the app.
};
<Router backAndroidHandler={onBackAndroid}>
</Router>
refer https://github.com/aksonov/react-native-router-flux/blob/master/src/Router.js#L23
@tanthanh289 @tusharv-bidchat do we need to write on every scene about the hardware back procedure? because on my case, pressing hardware back on reset scene won't do nothing, while pressing hardware back on normal scene will exit the app
Is there any better solution? or a stable release per se?
@sitompul I did this
const onBackAndroid = () => {
Actions.pop()
return true; // Return true to stay, or return false to exit the app.
};
<Router backAndroidHandler={onBackAndroid}>
</Router>
@albinhubsch Thanks i already implemented that. It's working fine now
If you want to have the expected behavior use the following
<Router backAndroidHandler={() => { return Actions.pop(); }}>
</Router>
This will make the back button pops the scenes of the stack without exiting until there are no scenes to pop then the app will exit.
Should work well with latest RNRF Example project.
Most helpful comment
@tusharv-bidchat
refer https://github.com/aksonov/react-native-router-flux/blob/master/src/Router.js#L23