docs/docs/guides/09-bottom-navigation.md
:::caution
The createMaterialBottomTabNavigator has been deprecated as of [email protected]. Instead, use @react-navigation/bottom-tabs version 7.x or later, combined with BottomNavigation.Bar to achieve a Material Design look.
For implementation details, see the dedicated example. :::
A material-design themed tab bar on the bottom of the screen that lets you switch between different routes with animation. Routes are lazily initialized - their screen components are not mounted until they are first focused.
This wraps the BottomNavigation component from react-native-paper, however if you configure the Babel plugin, it won't include the whole library in your bundle.
:::info
To use this navigator, ensure that you have @react-navigation/native and its dependencies (follow this guide):
:::
π For a complete example please visit
createMaterialBottomTabNavigatorsnack
To use this tab navigator, import it from react-native-paper/react-navigation:
import { createMaterialBottomTabNavigator } from 'react-native-paper/react-navigation';
const Tab = createMaterialBottomTabNavigator();
function MyTabs() {
return (
<Tab.Navigator>
<Tab.Screen name="Home" component={HomeScreen} />
<Tab.Screen name="Settings" component={SettingsScreen} />
</Tab.Navigator>
);
}
π For a complete usage guide please visit Tab Navigation
The Tab.Navigator component accepts following props:
idOptional unique ID for the navigator. This can be used with navigation.getParent to refer to this navigator in a child navigator.
initialRouteNameThe name of the route to render on first load of the navigator.
screenOptionsDefault options to use for the screens in the navigator.
backBehaviorThis controls what happens when goBack is called in the navigator. This includes pressing the device's back button or back gesture on Android.
It supports the following values:
firstRoute - return to the first screen defined in the navigator (default)initialRoute - return to initial screen passed in initialRouteName prop, if not passed, defaults to the first screenorder - return to screen defined before the focused screenhistory - return to last visited screen in the navigator; if the same screen is visited multiple times, the older entries are dropped from the historynone - do not handle back buttonshiftingWhether the shifting style is used, the active tab icon shifts up to show the label and the inactive tabs won't have a label.
By default, this is true when you have more than 3 tabs. Pass shifting={false} to explicitly disable this animation, or shifting={true} to always use this animation.
labeledWhether to show labels in tabs. When false, only icons will be displayed.
activeColorCustom color for icon and label in the active tab.
inactiveColorCustom color for icon and label in the inactive tab.
barStyleStyle for the bottom navigation bar. You can pass custom background color here:
<Tab.Navigator
initialRouteName="Home"
activeColor="#f0edf6"
inactiveColor="#3e2465"
barStyle={{ backgroundColor: '#694fad' }}
>
</Tab.Navigator>
If you have a translucent navigation bar on Android, you can also set a bottom padding here:
<Tab.Navigator
initialRouteName="Home"
activeColor="#f0edf6"
inactiveColor="#3e2465"
barStyle={{ paddingBottom: 48 }}
>
</Tab.Navigator>
themeEnables the customization of default theme attributes (e.g. colors) or facilitates the utilization of a personalized custom theme.
The following options can be used to configure the screens in the navigator:
titleGeneric title that can be used as a fallback for headerTitle and tabBarLabel.
tabBarIconFunction that given { focused: boolean, color: string } returns a React.Node, to display in the tab bar.
tabBarColor <div class="badge badge-deprecated">In v5.x works only with theme version 2.</div>Color for the tab bar when the tab corresponding to the screen is active. Used for the ripple effect. This is only supported when shifting is true.
tabBarLabelTitle string of a tab displayed in the tab bar. When undefined, scene title is used. To hide, see labeled option in the previous section.
tabBarBadgeBadge to show on the tab icon, can be true to show a dot, string or number to show text.
tabBarAccessibilityLabelAccessibility label for the tab button. This is read by the screen reader when the user taps the tab. It's recommended to set this if you don't have a label for the tab.
tabBarTestIDID to locate this tab button in tests.
The navigator can emit events on certain actions. Supported events are:
tabPressThis event is fired when the user presses the tab button for the current screen in the tab bar. By default a tab press does several things:
useScrollToTop to scroll it to toppopToTop action is performed on the stackTo prevent the default behavior, you can call event.preventDefault:
React.useEffect(() => {
const unsubscribe = navigation.addListener('tabPress', (e) => {
// Prevent default behavior
e.preventDefault();
// Do something manually
// ...
});
return unsubscribe;
}, [navigation]);
The tab navigator adds the following methods to the navigation prop:
jumpToNavigates to an existing screen in the tab navigator. The method accepts following arguments:
name - string - Name of the route to jump to.params - object - Screen params to pass to the destination route.navigation.jumpTo('Profile', { name: 'MichaΕ' });
import { createMaterialBottomTabNavigator } from 'react-native-paper/react-navigation';
import MaterialDesignIcons from '@react-native-vector-icons/material-design-icons';
const Tab = createMaterialBottomTabNavigator();
function MyTabs() {
return (
<Tab.Navigator
initialRouteName="Feed"
activeColor="#e91e63"
barStyle={{ backgroundColor: 'tomato' }}
>
<Tab.Screen
name="Feed"
component={Feed}
options={{
tabBarLabel: 'Home',
tabBarIcon: ({ color }) => (
<MaterialDesignIcons name="home" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Notifications"
component={Notifications}
options={{
tabBarLabel: 'Updates',
tabBarIcon: ({ color }) => (
<MaterialDesignIcons name="bell" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Profile"
component={Profile}
options={{
tabBarLabel: 'Profile',
tabBarIcon: ({ color }) => (
<MaterialDesignIcons name="account" color={color} size={26} />
),
}}
/>
</Tab.Navigator>
);
}