简体   繁体   中英

Have a shared profile screen for multiple tab screens in react native

I have a react native app with expo that uses react navigation v6 with a bottom tab navigator and I want to have a Profile Screen in the same stack without showing up on the bottom tab, and only accessible when manually navigated.

export function AppStack() {
 return (
<Tab.Navigator
  screenOptions={{ headerShown: false }}
  tabBar={(props) => <NavBar {...props} />}
>
  <Tab.Screen name="Timeline" component={TimelineScreen} />
  <Tab.Screen name="Goals" component={GoalScreen} />
  <Tab.Screen name="Notes" component={NoteScreen} />
  <Tab.Screen name="Schedule" component={ScheduleScreen} />
</Tab.Navigator>
  );
}

You can pass a custom component to a Screen using tabBarButton . Then just return null to show nothing.

export function AppStack() {
 return (
    <Tab.Navigator
      screenOptions={{ headerShown: false }}
      tabBar={(props) => <NavBar {...props} />}
    >
      <Tab.Screen name="Timeline" component={TimelineScreen} />
      <Tab.Screen name="Goals" component={GoalScreen} />
      <Tab.Screen name="Notes" component={NoteScreen} />
      <Tab.Screen name="Schedule" component={ScheduleScreen} />
      <Tab.Screen name="Settings" component={SettingsScreen} options={() => ({
        tabBarButton: () => null,
      })}/>
    </Tab.Navigator>
  );
}

You can navigate to the Settings screen from another screen by doing:

navigation.navigate('Settings');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM