createBottomTabNavigator
A simple tab bar on the bottom of the screen that lets you switch between different routes. Routes are lazily initialized -- their screen components are not mounted until they are first focused.
To use this navigator, ensure that you have @react-navigation/native
and its dependencies (follow this guide), then install @react-navigation/bottom-tabs
:
- npm
- Yarn
API Definition
To use this tab navigator, import it from @react-navigation/bottom-tabs
:
For a complete usage guide please visit Tab Navigation
Props
The Tab.Navigator
component accepts following props:
initialRouteName
The name of the route to render on first load of the navigator.
screenOptions
Default options to use for the screens in the navigator.
backBehavior
This controls how going back in the navigator is handled. This includes when the back button is pressed/back gesture is performed, or goBack
is called.
It supports the following values:
firstRoute
- return to the first tab (default)initialRoute
- return to initial taborder
- return to previous tab (in the order they are shown in the tab bar)history
- return to last visited tabnone
- do not handle back button
lazy
Defaults to true
. If false
, all tabs are rendered immediately. When true
, tabs are rendered only when they are made active for the first time. Note: tabs are not re-rendered upon subsequent visits.
detachInactiveScreens
Boolean used to indicate whether inactive screens should be detached from the view hierarchy to save memory. Make sure to call enableScreens
from react-native-screens to make it work. Defaults to true
.
sceneContainerStyle
Style object for the component wrapping the screen content.
tabBar
Function that returns a React element to display as the tab bar.
Example:
This example will render a basic tab bar with labels.
Note that you cannot use the useNavigation
hook inside the tabBar
since useNavigation
is only available inside screens. You get a navigation
prop for your tabBar
which you can use instead:
tabBarOptions
An object containing the props for the default tab bar component. If you're using a custom tab bar, these will be passed as props to the tab bar and you can handle them.
It can contain the following properties:
activeTintColor
Label and icon color of the active tab item.
inactiveTintColor
Label and icon color of the inactive tab item.
activeBackgroundColor
Background color of the active tab item.
inactiveBackgroundColor
Background color of the inactive tab item.
tabStyle
Style object for the tab item.
showLabel
Whether to show label for tab, default is true
.
labelStyle
Style object for the tab label text.
labelPosition
Whether the label is rendered below the icon or beside the icon. Possible values are:
below-icon
beside-icon
By default, in vertical
orientation (portrait mode), label is rendered below the icon and in horizontal
orientation (landscape mode)., it's rendered beside the icon.
adaptive
Should the tab icons and labels alignment change based on screen size? Defaults to true
. If false
, tab icons and labels align vertically all the time (labelPosition: 'below-icon'
). When true
, tab icons and labels align horizontally on tablets (labelPosition: 'beside-icon'
).
allowFontScaling
Whether label font should scale to respect Text Size accessibility settings, default is true.
keyboardHidesTabBar
Whether the tab bar is hidden when the keyboard opens. Defaults to false
.
safeAreaInsets
Safe area insets for the screen. This is used to avoid elements like notch and system navigation bar. By default, the device's safe area insets are automatically detected. You can override the behavior with this option.
Takes an object containing following optional properties:
top
- number - The value of the top inset, e.g. area containing the status bar and notch.right
- number - The value of the left inset.bottom
- number - The value of the bottom inset, e.g. area navigation bar on bottom.left
. - number - The value of the right inset.
style
Style object for the tab bar. You can configure styles such as background color here.
To show your screen under the tab bar, you can set the position
style to absolute:
You also might need to add a bottom margin to your content if you have a absolutely positioned tab bar. React Navigation won't do it automatically.
To get the height of the bottom tab bar, you can use BottomTabBarHeightContext
with React's Context API or useBottomTabBarHeight
:
or
Options
The following options can be used to configure the screens in the navigator:
title
Generic title that can be used as a fallback for headerTitle
and tabBarLabel
.
tabBarIcon
Function that given { focused: boolean, color: string, size: number }
returns a React.Node, to display in the tab bar.
tabBarLabel
Title string of a tab displayed in the tab bar or a function that given { focused: boolean, color: string }
returns a React.Node, to display in tab bar. When undefined, scene title
is used. To hide, see tabBarOptions.showLabel
in the previous section.
tabBarBadge
Text to show in a badge on the tab icon. Accepts a string
or a number
.
tabBarBadgeStyle
Style for the badge on the tab icon. You can specify a background color or text color here.
tabBarButton
Function which returns a React element to render as the tab bar button. It wraps the icon and label and implements onPress
. Renders TouchableWithoutFeedback
by default. tabBarButton: props => <TouchableOpacity {...props} />
would use TouchableOpacity
instead.
tabBarAccessibilityLabel
Accessibility 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.
tabBarTestID
ID to locate this tab button in tests.
unmountOnBlur
Whether this screen should be unmounted when navigating away from it. Unmounting a screen resets any local state in the screen as well as state of nested navigators in the screen. Defaults to false
.
Normally, we don't recommend enabling this prop as users don't expect their navigation history to be lost when switching tabs. If you enable this prop, please consider if this will actually provide a better experience for the user.
Header related options
You can find the list of header related options here. In addition to those, the following options are also supported in bottom tabs:
header
Function that returns a React Element to display as a header. It accepts an object containing the following properties as the argument:
navigation
- The navigation object for the current screen.route
- The route object for the current screen.options
- The options for the current screenlayout
- Dimensions of the screen, containsheight
andwidth
properties.
Example:
To set a custom header for all the screens in the navigator, you can specify this option in the screenOptions
prop of the navigator.
height
in headerStyle
Specify a If your custom header's height differs from the default header height, then you might notice glitches due to measurement being async. Explicitly specifying the height will avoid such glitches.
Example:
Note that this style is not applied to the header by default since you control the styling of your custom header. If you also want to apply this style to your header, use options.headerStyle
from the props.
headerShown
Whether to show or hide the header for the screen. The header is shown by default. Setting this to false
hides the header.
Events
The navigator can emit events on certain actions. Supported events are:
tabPress
This 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:
- If the tab is not focused, tab press will focus that tab
- If the tab is already focused:
- If the screen for the tab renders a scroll view, you can use
useScrollToTop
to scroll it to top - If the screen for the tab renders a stack navigator, a
popToTop
action is performed on the stack
- If the screen for the tab renders a scroll view, you can use
To prevent the default behavior, you can call event.preventDefault
:
If you have a custom tab bar, make sure to emit this event.
tabLongPress
This event is fired when the user presses the tab button for the current screen in the tab bar for an extended period. If you have a custom tab bar, make sure to emit this event.
Example:
Helpers
The tab navigator adds the following methods to the navigation prop:
jumpTo
Navigates 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 use for the destination route.