Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Add Bottom Tabs to a React Native App with React Navigation

    react-nativeReact Native
    javascriptJavaScript
    androidAndroid
    iosiOS

    Tabs are another popular navigation paradigm on mobile, so we’ll add tabs to the bottom of the screen, which will make it easy to switch between the primary screens of our application.

    Code

    Code

    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In
    Discuss

    Discuss

    Transcript

    Transcript

    Instructor: Let's open app.js and make some tabs on the bottom of the screen. We can import createBottomTabNavigator from react-navigation and make some tab by calling it. Then, we have to make a decision.

    When we press the info button or any stack navigation push, do we want the new screens to come up over the tabs, or do we want our bottom tabs to always be on the bottom of the screen? Whatever we want is the root or base navigator will be the one we want to export.

    Let's switch the tabs to be the default export from app. Then, we can name our stack navigator, and make that stack navigator as the first tab in the bottom tabs. When we run that, we get a bottom tab that's says list.

    When we press the info button, you can see the stack navigator push the screen, but the tab is still visible, because the tab navigator is what contains the stack navigator. Let's add a new about screen which will make this more clear.

    I'll make the new about.js file index body component with the header, an icon, and some dummy text, and some styles, so looks OK. Then, we can import that into app.js and set that as a second tab called about. We can run that to see there's two tabs now.

    If we press the info button now, the stack navigator pushes on to the lists tab. We can still select the about tab which shows us the about screen. If we go back to the list tab, we see the list tab is still on the same info screen.

    The tab looks pretty bad here, so let's import the Font Awesome icons in app.js. Just like for stack navigator, we can specify navigation options for the tab bar. We want different icons for each tab, so we'll specify a function for the navigation options, which has the navigation object as a param.

    We can set the tab bar icon key on that object which is a function itself that will give us the tint color to use for each icon. Then, we can extract the route name from the navigation object and use that to set the proper icon for the proper tab.

    If we reload now, each tab has an icon and that icon changes color based on which tab is active. If we add some tab bar options to the navigation options with the tab, then we can add more distinction to the currently selected tab by specifying an active background color, which changes the background color of the selected tab.