I have a scene with a list of tasks, some of which have subtasks.
Pressing on an icon to show subtasks opens the same scene, but with different data.
When in subtask list, pressing hardware back button should take me to parent task list (which is the previous scene in the stack).
This is how it worked in rnrf v3.
The app closes, because of
return _navigationStore2.default.currentScene!==_navigationStore2.default.prevScene;
in onBackPress callback. Even though prevScene === currentScene, their keys are different and they have different props.
const sceneRoot = ({ level }) => (
<View>
<Text>Scene {level}</Text>
<Button title="Deeper" onPress={() => {
Actions.root({
level: level + 1,
});
}} />
</View>
);
export default class RouterComponent extends React.Component {
render() {
return (
<Router>
<Scene>
<Scene key="root" component={sceneRoot} />
</Scene>
</Router>
);
}
}
Try pressing "Deeper" button, and then pressing hardware back button. It closes the app.
Pressing "Deeper" and then pressing back in navbar works.
I'm not sure if this helps but if you call type={ActionConst.RESET} to the Scene, It will prevent the default behavior of the hardware back button.
<Router>
<Scene>
<Scene key="root" component={sceneRoot} type={ActionConst.RESET} />
</Scene>
</Router>
Try this and let me know
I just tried this, it doesn't help. Although, I think this should be the expected behavior in that case as RESET resets the stack, which I don't want to do, I want to go back.
Thanks anyway.
+1
I fixed it by doing this:
BackHandler.addEventListener('hardwareBackPress', this.handleHardwareBack);
...
handleHardwareBack = () => {
Actions.pop();
return true;
}
I can't reproduce it with the latest version of RNRF, If you still see the issue, feel free to reopen and fork and modify Example project to demonstrate.
Most helpful comment
I fixed it by doing this: