I'm trying to create a Drawer navigation in my app using react-navigation, but I'm having difficult to hide one item. What I want: create some screens (to navigate inside app), but NOT display those screens in Drawer. I'm using this doc: (https://reactnavigation.org/docs/nesting-navigators/#navigator-specific-methods-are-available-in-the-navigators-nested-inside)
But I have two problems: 1) Root
still being displayed; 2) I can't navigate direct to 'hidden' screen, it says that screen doesn't exist.
This is my current code:
const Stack = createStackNavigator();
function Root2() {
return (
<Stack.Navigator>
<Stack.Screen name="NewEditPilot" component={NewEditPilot} />
<Stack.Screen name="Settings" component={Settings} />
</Stack.Navigator>
);
}
const Drawer = createDrawerNavigator();
function MyDrawer() {
return (
<Drawer.Navigator drawerContent={props => <SideBar2 {...props} />}>
<Drawer.Screen name="Home" component={Home} />
<Drawer.Screen name="PilotMgnt" component={PilotMgnt} />
<Drawer.Screen name="Root2" component={Root2} />
</Drawer.Navigator>
);
}
export default function App() {
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<Root>
<NavigationContainer>
<MyDrawer />
</NavigationContainer>
</Root>
</PersistGate>
</Provider>
);
}
In this case, I'm trying to hidde NewEditPilot
and Settings
screens. This is how I was navigating to these screens: navigation.navigate('NewEditPilot')
(this was working on react-navigation 4x).
Also, this is how I was using (and working!) in react-navigation 4x:
// Telas principais
const Drawer = DrawerNavigator(
{
Home: { screen: Home },
PilotMgnt: { screen: PilotMgnt},
CurRace: { screen: CurRace},
Settings: { screen: Settings},
LogViewScreen: { screen: LogViewScreen},
},
{
initialRouteName: "Home",
contentOptions: {
activeTintColor: "#e91e63"
},
contentComponent: props => <SideBar {...props} />
}
);
// sub-telas
const AppNavigator = StackNavigator(
{
Drawer: { screen: Drawer },
NewEditPilot: { screen: NewEditPilot },
PersonalRank: { screen: PersonalRank },
RCharts: { screen: RCharts},
RChartsArchive: { screen: RChartsArchive},
Archive: { screen: Archive },
ArchiveView: { screen: ArchiveView },
ArchivePersonalRank: { screen: ArchivePersonalRank },
},
{
initialRouteName: "Drawer",
headerMode: "none"
}
);
export default () =>
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<Root>
<AppNavigator />
</Root>
</PersistGate>
</Provider>
;