Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 71 ยท Navigation

Tab and Drawer Navigators

Build bottom tabs, badges, a drawer and top tabs with React Navigation, nest stacks inside tabs, and try a runnable tab navigator stand-in.

A stack answers "where did I come from?". Tabs and drawers answer a different question: "what are the main areas of this app?". Instagram has Home, Search and Profile at the bottom. Gmail hides Inbox, Sent and Settings in a side menu. These are tab navigators and drawer navigators, and real apps usually combine them with stacks.

This lesson covers the bottom tab navigator, badges and icons, the drawer, top tabs, and the most important idea in navigation architecture: nesting. It builds on Stack Navigation with React Navigation and Route Params and Typed Navigation.

What runs on this site. These navigators need native gestures, so the real code is read-only. The runnable examples are stand-ins: a state object holds one stack per tab, which is how a tab navigator keeps each tab's history separate, and a drawer stand-in opens and closes with plain state. There are no swipe gestures or animations.

Bottom tabs

Install the package and create the navigator the same way as a stack:

Terminal
npm install @react-navigation/bottom-tabs
JSX
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { Ionicons } from '@expo/vector-icons';

const Tab = createBottomTabNavigator();

function MainTabs() {
  return (
    <Tab.Navigator
      screenOptions={({ route }) => ({
        tabBarIcon: ({ color, size }) => (
          <Ionicons name={route.name === 'Home' ? 'home' : 'person'} size={size} color={color} />
        ),
        tabBarActiveTintColor: '#2563eb',
      })}
    >
      <Tab.Screen name="Home" component={HomeScreen} />
      <Tab.Screen name="Inbox" component={InboxScreen} options={{ tabBarBadge: 3 }} />
      <Tab.Screen name="Profile" component={ProfileScreen} />
    </Tab.Navigator>
  );
}

Each Tab.Screen becomes a button in the tab bar. The useful options are:

  • tabBarIcon: a function that receives { focused, color, size } and returns an icon.
  • tabBarLabel and title: the text under the icon and in the header.
  • tabBarBadge: a number or string drawn on the icon; leave it undefined to hide it. Use it for unread counts, and update it from state, for example options={{ tabBarBadge: unread > 0 ? unread : undefined }}.
  • tabBarActiveTintColor and tabBarStyle: colors and bar styling.
  • headerShown: tabs get a header by default; turn it off when a nested stack draws its own.

Tab screens are mounted lazily by default: a tab's component is created the first time you open it, and then stays mounted, so its state survives switching tabs. Set lazy: false to render all tabs at start, or freezeOnBlur: true to pause rendering of tabs you left, which saves work in busy apps.

Three navigators, three jobs

Stack Drill down and go back.
Tabs Switch between main areas.
Drawer A side menu for many areas.
1 / 2

Nesting: stacks inside tabs

This is the pattern you will use most. The tab bar stays visible at the bottom, and each tab has its own stack with its own history:

JSX
const HomeStack = createNativeStackNavigator();
function HomeStackScreen() {
  return (
    <HomeStack.Navigator>
      <HomeStack.Screen name="Feed" component={FeedScreen} />
      <HomeStack.Screen name="Post" component={PostScreen} />
    </HomeStack.Navigator>
  );
}

function MainTabs() {
  return (
    <Tab.Navigator screenOptions={{ headerShown: false }}>
      <Tab.Screen name="HomeTab" component={HomeStackScreen} />
      <Tab.Screen name="SettingsTab" component={SettingsStackScreen} />
    </Tab.Navigator>
  );
}

Now if you open a post in the Home tab, switch to Settings, and come back, the post is still open. Tapping the already-selected Home tab icon pops that tab's stack back to its first screen. Two details prevent most confusion:

  1. Hide the outer header. headerShown: false on the tabs stops two headers (one from the tab, one from the stack) from stacking up.
  2. Navigation actions bubble up. navigation.navigate('Post') first looks in the current navigator, then in its parents. To reach a screen in a different nested navigator, name the parent and the child screen:
JSX
navigation.navigate('SettingsTab', {
  screen: 'Account',
  params: { section: 'billing' },
});

The screen key is the target inside the nested navigator, and params are its params. If a nested navigator is not rendered yet, React Navigation mounts it with that screen on top.

The reverse tree also exists: a stack at the root with the tabs as one screen, and screens like "Login" or a full-screen "Photo viewer" above the tabs. Anything that must hide the tab bar belongs in the outer stack.

Where does each screen live?

Root stack Login, full-screen viewers.
Tabs One screen of the root stack.
Tab stacks Each tab has its own history.

Put a screen in the outermost navigator if it should cover the tab bar.

1 / 2
Tabs with a stack per tab (stand-in)

Open two detail screens in Home, switch to Inbox and back: the Home stack is unchanged. Tap the active Home tab and its stack shrinks to the first screen.

Drawer navigator

The drawer slides in from the edge and fits apps with many top-level destinations. It needs two native peers, react-native-gesture-handler and react-native-reanimated, so install them with Expo's installer and follow the Reanimated setup for your SDK version:

Terminal
npm install @react-navigation/drawer
npx expo install react-native-gesture-handler react-native-reanimated
JSX
import { createDrawerNavigator } from '@react-navigation/drawer';

const Drawer = createDrawerNavigator();

function AppDrawer() {
  return (
    <Drawer.Navigator
      initialRouteName="Home"
      screenOptions={{ drawerType: 'front', drawerPosition: 'left' }}
    >
      <Drawer.Screen name="Home" component={HomeScreen} />
      <Drawer.Screen name="Settings" component={SettingsScreen} options={{ drawerLabel: 'Preferences' }} />
    </Drawer.Navigator>
  );
}

The drawer adds a hamburger button to the header automatically. Inside any screen you can control it with navigation.openDrawer(), navigation.closeDrawer() and navigation.toggleDrawer(), and a drawerContent prop lets you replace the whole menu with your own component (a profile photo at the top, a logout button at the bottom).

A drawer works like tabs for nesting: stacks go inside its screens, and headerShown: false hides the drawer's header if a nested stack draws one. Many apps use tabs for the three or four most important areas and a drawer, or a settings stack, for everything else. As a rule of thumb, use tabs for up to five peer destinations people jump between often, and a drawer when you have more or when they are rarely used.

A drawer that toggles (stand-in)

Drawer options worth knowing

Most drawer behavior is set in screenOptions (or per screen in options):

Option Meaning
drawerType "front" (slides over), "back" (content slides away), "slide" (both move), "permanent" (always shown, good for tablets)
drawerPosition "left" or "right"
swipeEnabled allow opening by swiping from the edge (set false on screens with horizontal gestures)
swipeEdgeWidth how wide the edge swipe zone is (older versions called this edgeWidth)
overlayColor the colour of the dim layer over the content while the drawer is open
drawerStyle style of the drawer panel: width, background colour
sceneStyle style of the screen area (older versions called this sceneContainerStyle)
drawerLabel, drawerIcon the label and icon of each item
drawerActiveTintColor, drawerInactiveTintColor item colours
headerShown hide the built-in header
backBehavior on Drawer.Navigator: what the Android back button does: "firstRoute", "initialRoute", "order", "history" or "none"

backBehavior="history" goes back through the screens you visited, "initialRoute" returns to the first screen before exiting, and "firstRoute" jumps to the first screen in the list. Bottom tabs have the same backBehavior option.

JSX
<Drawer.Navigator
  backBehavior="history"
  screenOptions={{
    drawerType: 'front',
    swipeEnabled: true,
    swipeEdgeWidth: 40,
    overlayColor: 'rgba(15, 23, 42, 0.5)',
    drawerStyle: { width: 280, backgroundColor: '#f8fafc' },
  }}
>

You may see old tutorials that configure tabs with tabBarOptions and tabBarComponent. In React Navigation 5 and later these became screenOptions (for example tabBarActiveTintColor, tabBarStyle, tabBarShowLabel) and the tabBar prop of the navigator, which takes a function that renders your own tab bar. Translate old names when you copy code.

Material top tabs

For swipeable tabs under the header (a "Following / For you" switcher) there is @react-navigation/material-top-tabs, built on react-native-tab-view and react-native-pager-view:

JSX
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';

const TopTab = createMaterialTopTabNavigator();

function Feeds() {
  return (
    <TopTab.Navigator screenOptions={{ tabBarIndicatorStyle: { backgroundColor: '#2563eb' } }}>
      <TopTab.Screen name="Following" component={FollowingScreen} />
      <TopTab.Screen name="ForYou" component={ForYouScreen} options={{ title: 'For you' }} />
    </TopTab.Navigator>
  );
}

It follows the same rules as every other navigator: screens with names, options, nesting. Swiping sideways between tabs is built in, so avoid placing horizontally scrolling lists at the same screen edge.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. You want a tab bar plus a separate history for each tab. What structure fits?

    Nesting a stack inside each tab screen gives every tab its own history while the tab bar stays visible.
  2. 2. Which option shows an unread count on a tab icon?

    tabBarBadge accepts a number or string and draws a small badge on the icon. Setting it to undefined hides it.
  3. 3. How do you navigate from one tab into a screen inside another tab's nested stack?

    Name the parent screen and pass the nested target in the screen param. Actions bubble up to parents, but they do not search sibling navigators on their own.
  4. 4. Where should a screen that must cover the tab bar, such as a login screen, live?

    Screens in an outer stack render above the whole tab navigator, so the tab bar is hidden while they are shown.

Summary

  • Bottom tabs (createBottomTabNavigator) switch between main areas; use tabBarIcon, tabBarBadge and headerShown to shape them. Tabs mount lazily and keep their state.
  • Nest a stack inside each tab so every tab has its own history, and hide the outer header to avoid two headers.
  • Reach a screen in another navigator with navigate('Parent', { screen: 'Child', params }).
  • The drawer adds a side menu (needs gesture-handler and Reanimated); openDrawer, closeDrawer and toggleDrawer control it.
  • Material top tabs give swipeable tabs below the header.
  • On this site the real navigators are read-only and the TryIts are state-based stand-ins.

Next, let the file system define your routes with File-Based Routing with Expo Router.