Lesson 44 of 60 – Bottom Tab Navigation in React Native
73%

Bottom Tab Navigation in React Native

Bottom Tab Navigation is a popular navigation pattern in mobile applications. It places navigation options at the bottom of the screen and allows users to quickly switch between the main sections of an application.

For example, a mobile application may have tabs such as Home, Courses, Profile and Settings.

--------------------------------
|                              |
|          Screen              |
|                              |
|                              |
--------------------------------
| Home | Courses | Profile | More |
--------------------------------
Note: Bottom tabs are generally useful for the main sections of an application that users need to access frequently.

1. What is Bottom Tab Navigation?

Bottom Tab Navigation displays multiple navigation options at the bottom of the application screen.

Each tab normally represents a different screen or section.

Home
Courses
Profile
Settings

Users can tap a tab to switch between these sections.

2. Why Use Bottom Tabs?

Bottom tabs are useful when an application has several primary sections that users need to access regularly.

  • Home
  • Search
  • Courses
  • Profile
  • Settings

They provide quick access without requiring the user to open another menu.

3. Installing Bottom Tab Navigator

React Navigation provides a bottom tab navigator through a separate package.

npm install @react-navigation/bottom-tabs

The core React Navigation package should already be installed in the project.

4. Importing NavigationContainer

import {
    NavigationContainer
} from '@react-navigation/native';

The NavigationContainer contains the application's navigation structure.

5. Importing createBottomTabNavigator

import {
    createBottomTabNavigator
} from '@react-navigation/bottom-tabs';

This function is used to create a bottom tab navigator.

6. Creating the Tab Object

const Tab =
    createBottomTabNavigator();

The Tab object provides the components required to create the tab navigation structure.

7. Creating Tab.Navigator

<Tab.Navigator>

    {/* Tab Screens */}

</Tab.Navigator>

The Tab.Navigator contains the screens that will appear as tabs.

8. Creating Tab.Screen

<Tab.Screen
    name="Home"
    component={HomeScreen}
/>

Tab.Screen registers a screen as one of the available tabs.

9. Creating Multiple Tabs

<Tab.Navigator>

    <Tab.Screen
        name="Home"
        component={HomeScreen}
    />

    <Tab.Screen
        name="Courses"
        component={CoursesScreen}
    />

    <Tab.Screen
        name="Profile"
        component={ProfileScreen}
    />

</Tab.Navigator>

The application now has three bottom tabs.

10. Creating a Home Screen

import React from 'react';

import {
    View,
    Text
} from 'react-native';

export default function HomeScreen() {

    return (

        <View>

            <Text>
                Home Screen
            </Text>

        </View>

    );

}

This component can be registered as the Home tab.

11. Creating a Courses Screen

import React from 'react';

import {
    View,
    Text
} from 'react-native';

export default function CoursesScreen() {

    return (

        <View>

            <Text>
                Courses Screen
            </Text>

        </View>

    );

}

This component can be registered as the Courses tab.

12. Creating a Profile Screen

import React from 'react';

import {
    View,
    Text
} from 'react-native';

export default function ProfileScreen() {

    return (

        <View>

            <Text>
                Profile Screen
            </Text>

        </View>

    );

}

This component can be registered as the Profile tab.

13. Basic Bottom Tab Example

const Tab =
    createBottomTabNavigator();

export default function App() {

    return (

        <NavigationContainer>

            <Tab.Navigator>

                <Tab.Screen
                    name="Home"
                    component={HomeScreen}
                />

                <Tab.Screen
                    name="Courses"
                    component={CoursesScreen}
                />

                <Tab.Screen
                    name="Profile"
                    component={ProfileScreen}
                />

            </Tab.Navigator>

        </NavigationContainer>

    );

}

14. Switching Between Tabs

Users can switch between tabs by tapping the corresponding tab at the bottom of the screen.

Home
   ↓
Courses
   ↓
Profile

The selected tab displays its associated screen.

15. Setting the Initial Tab

The initialRouteName option can specify which tab should be selected when the application starts.

<Tab.Navigator
    initialRouteName="Home"
>

    <Tab.Screen
        name="Home"
        component={HomeScreen}
    />

    <Tab.Screen
        name="Courses"
        component={CoursesScreen}
    />

</Tab.Navigator>

16. Changing Tab Titles

The options property can be used to customize the tab label.

<Tab.Screen
    name="Courses"
    component={CoursesScreen}
    options={{
        title: 'My Courses'
    }}
/>

The title can be changed without changing the route name.

17. Using Tab Bar Labels

The tab bar label can be customized using tabBarLabel.

<Tab.Screen
    name="Profile"
    component={ProfileScreen}
    options={{
        tabBarLabel: 'My Profile'
    }}
/>

This changes the text displayed in the tab bar.

18. Using Tab Icons

Tab icons can be configured using the tabBarIcon option.

<Tab.Screen
    name="Home"
    component={HomeScreen}
    options={{
        tabBarIcon: ({
            focused,
            color,
            size
        }) => (
            <Text>
                🏠
            </Text>
        )
    }}
/>

In a real application, an icon library can be used instead of an emoji.

19. Active and Inactive Tabs

The tab bar can provide different visual states for the selected and unselected tabs.

<Tab.Navigator
    screenOptions={{
        tabBarActiveTintColor: 'blue',
        tabBarInactiveTintColor: 'gray'
    }}
>

The active tab can therefore be visually distinguished from inactive tabs.

20. Hiding Tab Bar on a Screen

The tab bar can be configured through screen options when a different navigation structure requires it.

For example, an application may use a stack navigator for detailed screens and keep the bottom tabs for the main application sections.

Home
  |
  └── Details

This is commonly achieved by combining navigators.

21. Bottom Tabs with Stack Navigation

Bottom tabs and stack navigation can be combined.

Bottom Tabs
    |
    ├── Home Stack
    │     ├── Home
    │     └── Details
    │
    ├── Courses
    │
    └── Profile

This structure is useful for real-world applications.

22. Tab Navigation with Parameters

Parameters can also be passed to screens through navigation.

navigation.navigate(
    'Profile',
    {
        userId: 101
    }
);

The destination screen can read the parameter through its route object.

23. Tab Navigation Use Cases

Bottom tabs are commonly suitable for applications such as:

  • Education apps
  • Shopping apps
  • Social media apps
  • Banking apps
  • Fitness apps
  • News apps
  • Business apps

The tabs should normally represent the main sections of the application.

24. Tab Navigation for an Education App

An education application could use:

Home
Courses
Assignments
Profile

Each tab can open a different section of the application.

25. Tab Navigation for a Shopping App

A shopping application could use:

Home
Categories
Cart
Orders
Profile

This allows users to quickly access the most important shopping sections.

26. Common Bottom Tab Mistakes

  • Forgetting to install the bottom-tabs package.
  • Forgetting NavigationContainer.
  • Using duplicate route names.
  • Adding too many tabs.
  • Using unclear tab labels.
  • Not providing useful active and inactive states.
  • Using inappropriate icons.
  • Creating complicated nested navigation unnecessarily.

27. Complete Bottom Tab Example

import React from 'react';

import {
    View,
    Text
} from 'react-native';

import {
    NavigationContainer
} from '@react-navigation/native';

import {
    createBottomTabNavigator
} from '@react-navigation/bottom-tabs';

const Tab =
    createBottomTabNavigator();

function HomeScreen() {

    return (

        <View>

            <Text>
                Home Screen
            </Text>

        </View>

    );

}

function CoursesScreen() {

    return (

        <View>

            <Text>
                Courses Screen
            </Text>

        </View>

    );

}

function ProfileScreen() {

    return (

        <View>

            <Text>
                Profile Screen
            </Text>

        </View>

    );

}

export default function App() {

    return (

        <NavigationContainer>

            <Tab.Navigator
                initialRouteName="Home"
                screenOptions={{
                    tabBarActiveTintColor:
                        'blue',
                    tabBarInactiveTintColor:
                        'gray'
                }}
            >

                <Tab.Screen
                    name="Home"
                    component={HomeScreen}
                />

                <Tab.Screen
                    name="Courses"
                    component={CoursesScreen}
                />

                <Tab.Screen
                    name="Profile"
                    component={ProfileScreen}
                />

            </Tab.Navigator>

        </NavigationContainer>

    );

}

28. Bottom Tab Best Practices

  • Use tabs for the main sections of the application.
  • Keep the number of tabs manageable.
  • Use clear and short labels.
  • Use familiar icons when appropriate.
  • Keep active and inactive states visually clear.
  • Keep navigation consistent across screens.
  • Combine tabs with stack navigation when required.
  • Test the tab navigation on different screen sizes.

29. Important Bottom Tab Properties

Property / Component Purpose
createBottomTabNavigator() Creates a bottom tab navigator
Tab.Navigator Contains the tab screens
Tab.Screen Registers a screen as a tab
initialRouteName Sets the initial tab
tabBarLabel Customizes the tab label
tabBarIcon Provides an icon for a tab
tabBarActiveTintColor Sets the active tab color
tabBarInactiveTintColor Sets the inactive tab color
screenOptions Configures common screen and tab options

30. Complete Bottom Tab Navigation Workflow

Create React Native Project
          ↓
Install React Navigation
          ↓
Install Bottom Tabs
          ↓
Create Screen Components
          ↓
Create NavigationContainer
          ↓
Create Bottom Tab Navigator
          ↓
Register Tab Screens
          ↓
Set Initial Tab
          ↓
Customize Labels
          ↓
Add Icons
          ↓
Configure Active/Inactive States
          ↓
Combine with Stack Navigation if Required
          ↓
Test All Tabs

Bottom Tab Navigation is useful when an application has several important sections that users need to access quickly. It can also be combined with Stack Navigation to build complete mobile application navigation systems.

📌 Key Points

  • Bottom Tab Navigation displays navigation options at the bottom of the screen.
  • @react-navigation/bottom-tabs provides the bottom tab navigator.
  • createBottomTabNavigator() creates a tab navigator.
  • Tab.Navigator contains the tab screens.
  • Tab.Screen registers an individual tab.
  • initialRouteName can select the starting tab.
  • tabBarLabel customizes tab labels.
  • tabBarIcon can be used to display tab icons.
  • Active and inactive tab colors can be customized.
  • Bottom tabs are useful for the main sections of an application.
  • Bottom tabs can be combined with Stack Navigation.

🧠 Quick Quiz

Question: Which function is used to create a Bottom Tab Navigator in React Navigation?