Search code examples
react-nativereact-navigationreact-navigation-stackreact-navigation-bottom-tab

Manage multiple navigators (stack navigator and bottomtabsnavigator) in react navigation


I have a react native application which has got a stack navigator and a bottom tabs navigator. Bottom tabs navigator and stack navigator has common screens between them. Here is the structure:

const ExploreNavigator = createStackNavigator({
    Explore: {
        screen: ExploreScreen
    },
    Read: {
        screen: ReadScreen
    },
    CreateImage: {
        screen: CreateImageScreen
    }
})




const TabsNavigator = createBottomTabNavigator({
    ExploreTab: {
        screen: ExploreNavigator,
        navigationOptions: {
            tabBarLabel: "Explore"
        }
    },
    ReadTab: {
        screen: ReadScreen,
        navigationOptions: {
            tabBarLabel: "Read"
        }
    }
})

Now, if I directly move to Reading screen from Bottom tab navigator and move to CreateImage screen of stack navigator, when I press the back button I come back to default screen that is explore screen?

So, what is the best approach to solve the issue? I know I can create another stack navigator and add the relevant screens. Also, if this approach is followed can I name the stack navigator screens same?


Solution

  • I think this doesn't need keed one screen in the bold stack and bottom tab. So I suggestion like this

    const ExploreNavigator = createStackNavigator({
        Tabs: {
            screen: TabsNavigator
        },
        CreateImage: {
            screen: CreateImageScreen
        }
    })
    
    
    
    
    const TabsNavigator = createBottomTabNavigator({
        Explore: {
            screen: ExploreScreen,
            navigationOptions: {
                tabBarLabel: "Explore"
            }
        },
        ReadTab: {
            screen: ReadScreen,
            navigationOptions: {
                tabBarLabel: "Read"
            }
        }
    })