So I've created a navigation using React Navigation (v6) as follows:
- Home
- Work - Work.js
- Work Details - WorkDetails.js
Upon selecting a specific work item from the Work overview screen (Work.js
), you're taken to directed to the Word Details screen to see more details. This works as intended, however after doing so, pressing/clicking on "Work" to get back to the overview screen no longer works. Nothing happens from the Work Details page, and if you click home and come back, you simply come back to the details specific page you just left.
In order to navigate to the Work Details screen without having it listed in the primary navigation, I'm using a combination of Drawer and Stack navigators as follows:
App.js
function DrawerMenu() {
return (
<Drawer.Navigator
useLegacyImplementation
screenOptions={{
headerShown: true,
drawerPosition: 'right',
overlayColor: 'rgba(0,0,0,.5)',
drawerActiveTintColor: text,
drawerInactiveTintColor: text,
drawerStyle: { backgroundColor: bg, },
}}
drawerContent={(props) => <CustomDrawerContent {...props} />} >
<Drawer.Screen name="Home" component={HomeDrawer} options={customDrawOptions} />
<Drawer.Screen name="Work" component={WorkMenu} options={customDrawOptions} />
<Drawer.Screen name="Posts" component={PostsDrawer} options={customDrawOptions} />
</Drawer.Navigator>
);
}
function WorkMenu(){
return (
<Stack.Navigator initialRouteName="WorkOverview"
useLegacyImplementation
screenOptions={{
headerShown: true,
drawerPosition: 'right',
overlayColor: 'rgba(0,0,0,.5)',
drawerActiveTintColor: text,
drawerInactiveTintColor: text,
drawerStyle: { backgroundColor: bg, },
}} >
<Stack.Screen name="WorkOverview" component={WorkDrawer} options={{ headerShown: false }} />
<Stack.Screen name="WorkDetail" component={WorkDetailDrawer} options={{ headerShown: false }} />
</Stack.Navigator>
);
}
export default function App() {
return (
<NativeBaseProvider theme={theme}>
<NavigationContainer>
<DrawerMenu />
</NavigationContainer>
</NativeBaseProvider>
);
}
And then from the work overview page:
Work.js
import { useNavigation } from '@react-navigation/native';
function WorkTile({data}) {
const navigation = useNavigation();
return (
<Pressable mt={5} shadow="2" rounded="lg" w={{ base: 96, md: 72, lg: 48 }}
_light={{ bg: "coolGray.50" }}
_dark={{ bg: "gray.800" }}
overflow={"hidden"}
onPress={() =>
navigation.navigate("WorkDetail",
{
initial: false,
workDetail: data
}
)
}
>
...
</Pressable>
);
}
export default WorkTile;
Which just sends the relevant workDetail: data
object to WorkDetails.js which then just gets peppered throughout various JSX elements.
The desired behavior is similar to how it would react on the web:
Home -> Work -> Work Details(1) -> Work -> Work Details(2) -> etc.
However it ends up behaving as:
Home <-> Work Details(1)
I've tried adding initial: false
when navigating to the WorkDetails.js screen, per the React Navigation docs as well as implementing a reset once on the WorkDetails.js screen, and also updating the config for nested navigation. Most of the similar questions on StackOverflow seem to be a variation of one of those three solutions or seem to be leveraging custom buttons/links (and not automatically generated nav elements in the drawer/header). Regardless, nothing I've tried seems to resolve the issue. Any help would be very much appreciated. Thanks in advance!