I have the following structure in my React Native project, suggested by this answer:
export const Root = () => {
const RootStack = useMemo(() => createStackNavigator(), []);
const HomeStack = useMemo(() => createStackNavigator(), []);
function renderHomeStack() {
return (
<HomeStack.Navigator>
<HomeStack.Screen name="Home" component={HomeScreen} />
<HomeStack.Screen name="Settings" component={SettingsScreen} />
</HomeStack.Navigator>
);
}
function renderRootStack() {
return (
<RootStack.Navigator>
<RootStack.Screen name="Login" component={LoginScreen} />
<RootStack.Screen
name="HomeStack"
options={{
presentation: 'modal',
}}
component={renderHomeStack}
/>
</RootStack.Navigator>
);
}
return renderRootStack();
};
Currently, I want to go back from the Settings screen to the Login screen.
I tried the solutions under this question, but they didn't work.
I also tried using
DeviceEventEmitter
to send an event to the login screen to call navigation.popToTop() or navigation.goBack() - that didn't work either.