I use the following structure in my React Native project.
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Login" component={LoginScreen} />
<Stack.Screen
name="Home"
component={HomeScreen}
options={{
headerRight: () => <SettingsButton />,
presentation: 'modal',
}}
/>
<Stack.Screen
name="Settings"
component={SettingsScreen}
options={{
presentation: 'card',
}}
/>
</Stack.Navigator>
</NavigationContainer>
function SettingsButton() {
const navigation = useNavigation();
return (
<Button
title="Settings"
onPress={() => navigation.navigate('Settings')}
/>
);
}
Whenever SettingsButton is pressed, I want to open my Settings window on the home screen (foreground window) and not the login screen (background/root window). Unfortunately, React Navigation uses the root window to push the screen and this happens (notice how the back button appears on the background window):
How can I make it so that it uses the foreground window?