Bottom tab navigation helps users switch between main sections of an app easily by tapping icons at the bottom.
Tab Navigator (Bottom Tabs) in React Native
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; import { NavigationContainer } from '@react-navigation/native'; const Tab = createBottomTabNavigator(); function MyTabs() { return ( <Tab.Navigator> <Tab.Screen name="Home" component={HomeScreen} /> <Tab.Screen name="Settings" component={SettingsScreen} /> </Tab.Navigator> ); } export default function App() { return ( <NavigationContainer> <MyTabs /> </NavigationContainer> ); }
Wrap your tab navigator inside NavigationContainer to manage navigation state.
Each Tab.Screen needs a unique name and a component to render.
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; const Tab = createBottomTabNavigator(); function MyTabs() { return ( <Tab.Navigator> <Tab.Screen name="Home" component={HomeScreen} /> <Tab.Screen name="Profile" component={ProfileScreen} /> </Tab.Navigator> ); }
<Tab.Navigator screenOptions={{ tabBarActiveTintColor: 'tomato', tabBarInactiveTintColor: 'gray' }}>
<Tab.Screen name="Feed" component={FeedScreen} />
<Tab.Screen name="Messages" component={MessagesScreen} />
</Tab.Navigator><Tab.Navigator>
<Tab.Screen
name="Settings"
component={SettingsScreen}
options={{ tabBarLabel: 'Config' }}
/>
</Tab.Navigator>This app shows two tabs at the bottom: Home and Settings. Tapping each tab changes the screen content.
import React from 'react'; import { Text, View } from 'react-native'; import { NavigationContainer } from '@react-navigation/native'; import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; function HomeScreen() { return ( <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> <Text>Home Screen</Text> </View> ); } function SettingsScreen() { return ( <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> <Text>Settings Screen</Text> </View> ); } const Tab = createBottomTabNavigator(); export default function App() { return ( <NavigationContainer> <Tab.Navigator> <Tab.Screen name="Home" component={HomeScreen} /> <Tab.Screen name="Settings" component={SettingsScreen} /> </Tab.Navigator> </NavigationContainer> ); }
Make sure to install @react-navigation/native and @react-navigation/bottom-tabs packages before using.
Use icons with tabs by adding tabBarIcon option inside options.
Bottom tabs are best for main app sections, not for deep navigation inside a section.
Bottom tab navigator shows tabs at the bottom for easy switching between main screens.
Wrap tabs inside NavigationContainer and define each tab with Tab.Screen.
You can customize labels, colors, and icons for better user experience.
Practice
Solution
Step 1: Understand the role of Bottom Tab Navigator
The Bottom Tab Navigator provides a set of tabs at the bottom of the screen for easy navigation between main app screens.Step 2: Compare with other options
Options A, B, and D describe different app features unrelated to tab navigation.Final Answer:
To allow users to switch between main screens using tabs at the bottom -> Option CQuick Check:
Bottom Tab Navigator = Easy screen switching [OK]
- Confusing tab navigator with list views
- Thinking it handles login or alerts
- Mixing up navigation types
Solution
Step 1: Identify correct wrapping order
The Bottom Tab Navigator must be inside the NavigationContainer to manage navigation state properly.Step 2: Check each option
<NavigationContainer><Tab.Navigator></Tab.Navigator></NavigationContainer> correctly wraps Tab.Navigator inside NavigationContainer. <Tab.Navigator><NavigationContainer></NavigationContainer></Tab.Navigator> reverses the order, which is incorrect. <NavigationContainer><Stack.Navigator></Stack.Navigator></NavigationContainer> uses Stack.Navigator, not Tab.Navigator. <Tab.Screen><NavigationContainer></NavigationContainer></Tab.Screen> incorrectly wraps NavigationContainer inside Tab.Screen.Final Answer:
<NavigationContainer><Tab.Navigator></Tab.Navigator></NavigationContainer> -> Option BQuick Check:
NavigationContainer wraps Tab.Navigator [OK]
- Placing NavigationContainer inside Tab.Navigator
- Using Stack.Navigator instead of Tab.Navigator
- Wrapping NavigationContainer inside Tab.Screen
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
const Tab = createBottomTabNavigator();
function MyTabs() {
return (
);
}Solution
Step 1: Check the tabBarLabel option for the second tab
The second Tab.Screen has options={{ tabBarLabel: 'Config' }}, which overrides the default label.Step 2: Understand default vs custom labels
Without tabBarLabel, the label would be the name prop 'Settings'. But here, it is replaced by 'Config'.Final Answer:
Config -> Option AQuick Check:
tabBarLabel overrides name label [OK]
- Using the name prop as label ignoring tabBarLabel
- Confusing component name with label
- Assuming default label always shows
const Tab = createBottomTabNavigator();
function App() {
return (
);
}Solution
Step 1: Check for NavigationContainer
The code does not wrap Tab.Navigator inside NavigationContainer, which is required to manage navigation state.Step 2: Verify Tab.Screen usage
Tab.Screen components are correctly inside Tab.Navigator, and name props are strings, which is correct.Final Answer:
Missing NavigationContainer wrapping the Tab.Navigator -> Option DQuick Check:
NavigationContainer must wrap Tab.Navigator [OK]
- Forgetting NavigationContainer
- Placing Tab.Screen outside Tab.Navigator
- Using invalid name prop types
tabBarIcon option. Which approach correctly adds a simple icon component to the tabs?Solution
Step 1: Understand tabBarIcon usage
The tabBarIcon option expects a function returning a React element, typically an icon component.Step 2: Evaluate each option
Use <Tab.Screen options={{ tabBarIcon: () => <Icon name='home' /> }} /> inside Tab.Navigator correctly uses a function returning <Icon name='home' /> inside options. Add <Icon name='home' /> directly inside Tab.Navigator without options incorrectly places Icon directly inside Tab.Navigator. Wrap Tab.Navigator inside <Icon> component wraps Tab.Navigator inside Icon, which is invalid. Set tabBarIcon as a string like 'home' in Tab.Screen options sets tabBarIcon as a string, which is not supported.Final Answer:
Use <Tab.Screen options={{ tabBarIcon: () => <Icon name='home' /> }} /> inside Tab.Navigator -> Option AQuick Check:
tabBarIcon needs a function returning icon component [OK]
- Placing icon components outside options
- Using strings instead of functions for tabBarIcon
- Wrapping navigator inside icon components
Ready to prove it?
Pass the test and this pattern moves unknown
