Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a StackNavigator inside TabNavigator possible?

I have created a custom tab navigator using createMaterialTopTabNavigator but inside one of the tabs I would like to create a StackNavigator. Is this possible?

I have found lots of examples of Tabs nested inside a Stack or Drawer but not an example of a Stack inside a Tab!

In essence I want to have a few buttons on one of the Tab Screens that navigate to some other screens but I don't want to navigate out of the Tab. (the initial Tab is always visible/selected)- just that you can click on a button and go to another screen and then back.

TabNavigator: 
 - Settings Screen (Tab 1)
       -About Us (Button when clicked opens up the About Us Screen)
       -Account Settings (Button when clicked opens up the About Us Screen)
       -Contact Us (Button when clicked opens up the About Us Screen)
 - Search Screen (Tab 2)
 - Profile Screen (Tab 3)

Any suggestions on if they is possible would be greatly appreciated! :)

like image 610
Tamsyn Jennifer Avatar asked Sep 10 '18 16:09

Tamsyn Jennifer


People also ask

How do I combine stacknavigator and tabnavigator?

What do you mean by combining StackNavigator and TabNavigator? if you want to combine them, then just put the screen in one navigator.

What does the stack navigator look & feel like?

By default the stack navigator is configured to have the familiar iOS and Android look & feel: new screens slide in from the right on iOS, fade in from the bottom on Android. On iOS the stack navigator can also be configured to a modal style where screens slide in from the bottom.

How do I use the @react-navigation/stack navigator?

To use this navigator, ensure that you have @react-navigation/native and its dependencies (follow this guide), then install @react-navigation/stack: You also need to install react-native-gesture-handler.

What are the options for the router and navigator?

Options for the router: initialRouteName - Sets the default screen of the stack. Must match one of the keys in route configs. navigationOptions - Navigation options for the navigator itself, to configure a parent navigator


1 Answers

Yes you can do that

You can nest StackNavigator inside TabNavigator by doing something similar to this -

import { TabNavigator, StackNavigator } from 'react-navigation'

export const TabNavigator = TabNavigator({
    SettingsScreenStack: { screen: SettingsScreenStack },
    SearchScreen: { screen: SearchScreen },
    ProfileScreen: { screen: ProfileScreen },
  }, {
    order: ['SettingsScreenStack', 'SearchScreen', 'ProfileScreen'],
    initialRouteName: 'SettingsScreenStack',
});

export const SettingsScreenStack = StackNavigator({
    AboutUsScreen: { screen: AboutUsScreen },
    AccountSettingsScreen: { screen: AccountSettingsScreen },
    ContactUsScreen: { screen: ContactUsScreen },
  }, {
    initialRoute: 'AboutUsScreen',
})

...

Hope it helped.

like image 157
Arpit Kapadia Avatar answered Oct 16 '22 03:10

Arpit Kapadia