React Native Top Tab Navigator
Last Updated :
11 Jan, 2025
To create a Top Tab Navigator, we need to use the createMaterialTopTabNavigator function available in the react-navigation library. It is designed with the material theme tab bar on the top of the screen. It allows switching between various tabs by tapping them or swiping horizontally. Default transition animations are available.
Props: In React Native the when components are created they must be customized according to the need that properties are called props.
- initialRouteName: initialRouteName is the props that are used to route the name that is rendered on the initial load of the navigator.
- screenOptions: screenOptions are the props in the React Native that are used as default options for the screens inside the navigator. The default option is used to apply all the screen navigators.
- tabBarPosition: This type of prop is used to set the position of the tab bar in tab view with the default value being set on the 'top'.
- lazy: The lazy props are used to check whether the boolean value indicating whether the screens will be lazily rendered or not. By default, the screen is shown in the viewport experience.
- lazyPlaceholder: The lazyPlaceholder props in React Native a function that returns a React element to be rendered for those routes that have not been rendered yet. By default, the render value is Null.
- removeClippedSubviews: The removeClippedSubviewsa is used to improve the memory hierarchy. It takes the boolean value which indicates whether to remove invisible views from the view hierarchy.
- keyboardDismissMode: This prop is used to take the string value which indicates whether the keyboard gets dismissed as a response to the drag gesture. The other values in keyboard Dismiss mode are auto,on-drag, none.
- timingConfig: timingConfig the props timing a configuration object used for the timing animation, which occurs when tabs are pressed. The other properties of timingConfig are duration and number.
- position: an animated value used to listen to the position updates. From time to time, it will change when the user presses the tabs.
Options: The options in React Native are used for configuration purposes. Configuration is executed when configuring the screens in the navigator.
- title: The option title is generally used as a fallback for the headerTitle and tabBarLabel.
- tabBarIcon: The tabBarIcon options return React.A node that is used to display in the tab bar section is color: string in reacts Native widget.
- tabBarLabel:The tabBarLabel in the title string of a tab that is displayed in the tab bar section of the widget of the screen in React Native.
- tabBarAccessibilityLabel: It is an options can be an accessibility label that is read by the screen reader when the user presses the tab.
- tabBarTestID:The tabBarTestID option can be an ID used to locate this tab button in tests.
Events:
- tabPress: the tabPress event set goes off when the user presses the current screen's tab button in the tab bar section. By default, it is used when we scroll it to the top .
- tabLongPress: the event which is fired when the user presses the current screen's tab button in the tab bar for a long duration of a time .
Helpers:
- jumpTo: The Helpers jumpTo is used to execute a function to navigate an existing screen in the tab navigator, which accepts names and params as its arguments, where name is string and params is an object .
Now let’s see how to create a Top Tab Navigator:
Step 1: Open your terminal and install expo-cli by the following command.
npm install -g expo-cli
Step 2: Now create a project by the following command.
expo init top-tab-navigator-demo
Step 3: Now go into your project folder i.e. top-tab-navigator-demo
cd top-tab-navigator-demo
Step 4: Install the required packages using the following command:
npm install --save react-navigation react-navigation-tabs react-native-paper react-native-vector-icons
Project Structure: The project directory should look like the following:

Example:
Now, let's set up our Top Tab Navigator in our App.js file. There will be 3 screens in our demo application: Home Screen, User Screen, and Settings Screen. Thus, we will have 3 tabs to navigate between these 3 screens.
Example: First, we will add our App.js file which will hold the Material Bottom Tab Navigator logic. Along with the basic information regarding the screen and label, we will also add icons and basic styles while setting it up.
App.js
</p><pre><code class="language-javascript"></code></pre><p></p><pre></pre><p><br></p><pre><code><span>import React from "react";</span></code><br><code><span>import { Ionicons } from "@expo/vector-icons";</span></code><br><code><span>import { createAppContainer } from "react-navigation";</span></code><br><code><span>import { createMaterialTopTabNavigator } from "react-navigation-tabs";</span></code><br><br><code><span>import ProfileScreen from "./screens/ProfileScreen";</span></code><br><code><span>import ImagesScreen from "./screens/ImagesScreen";</span></code><br><code><span>import VideoScreen from "./screens/VideosScreen";</span></code><br><br><code><span>const TabNavigator = createMaterialTopTabNavigator(</span></code><br><code><span> {</span></code><br><code><span> Profile: {</span></code><br><code><span> screen: ProfileScreen,</span></code><br><code><span> navigationOptions: {</span></code><br><code><span> tabBarLabel: "Profile",</span></code><br><code><span> showLabel: ({ focused }) => {</span></code><br><code><span> console.log(focused);</span></code><br><code><span> return focused ? true : false;</span></code><br><code><span> },</span></code><br><code><span> tabBarIcon: (tabInfo) => (</span></code><br><code><span> </span></code><br><code><span> ),</span></code><br><code><span> },</span></code><br><code><span> },</span></code><br><code><span> Images: {</span></code><br><code><span> screen: ImagesScreen,</span></code><br><code><span> navigationOptions: {</span></code><br><code><span> tabBarLabel: "Images",</span></code><br><code><span> tabBarIcon: (tabInfo) => (</span></code><br><code><span> </span></code><br><code><span> ),</span></code><br><code><span> },</span></code><br><code><span> },</span></code><br><code><span> Video: {</span></code><br><code><span> screen: VideoScreen,</span></code><br><code><span> navigationOptions: {</span></code><br><code><span> tabBarLabel: "Videos",</span></code><br><code><span> tabBarIcon: (tabInfo) => (</span></code><br><code><span> </span></code><br><code><span> ),</span></code><br><code><span> },</span></code><br><code><span> },</span></code><br><code><span> },</span></code><br><code><span> {</span></code><br><code><span> tabBarOptions: {</span></code><br><code><span> showIcon: true,</span></code><br><br><code><span> style: {</span></code><br><code><span> backgroundColor: "#006600",</span></code><br><code><span> marginTop: 28,</span></code><br><code><span> },</span></code><br><code><span> },</span></code><br><code><span> }</span></code><br><code><span>);</span></code><br><br><code><span>const Navigator = createAppContainer(TabNavigator);</span></code><br><br><code><span>export default function App() {</span></code><br><code><span> return (</span></code><br><code><span> </span></code><br><code><span> </span></code><br><code><span> </span></code><br><code><span> );</span></code><br><code><span>}</span></code><br></pre><p dir="ltr"><br></p><p dir="ltr"><gfg-tabs data-run-ide="false" data-mode="light"><gfg-tab slot="tab">Profile.js
import React from "react";
import { Text, View } from "react-native";
import { Ionicons } from "@expo/vector-icons";
const Profile = () => {
return (
Profile Screen!
);
};
export default Profile;
Images.js
</p><pre><code class="language-javascript"></code></pre><p></p><pre></pre><p><br></p><pre><code><span>import React from "react";</span></code><br><code><span>import { Text, View } from "react-native";</span></code><br><code><span>import { Ionicons } from "@expo/vector-icons";</span></code><br><br><code><span>const Images = () => {</span></code><br><code><span> return (</span></code><br><code><span> </span></code><br><code><span> </span></code><br><code><span> Images Screen!</span></code><br><code><span> </span></code><br><code><span> </span></code><br><code><span> </span></code><br><code><span> );</span></code><br><code><span>};</span></code><br><br><code><span>export default Images;</span></code></pre><p dir="ltr"><br></p><p dir="ltr"><gfg-tabs data-run-ide="false" data-mode="light"><gfg-tab slot="tab">Videos.js
import React from "react";
import { Text, View } from "react-native";
import { Ionicons } from "@expo/vector-icons";
const Videos = () => {
return (
Videos Screen!
);
};
export default Videos;
Start the server by using the following command.
expo start
Output:
Similar Reads
React Native Tab Navigation Component In this article, we are going to see how to implement Tab Navigation in react-native. For this, we are going to use createBottomTabNavigator component. It is basically used for navigation from one page to another. These days mobile apps are made up of a single screen, so create various navigation co
3 min read
React MUI Tabs Navigation React MUI is a UI library that provides fully-loaded components, bringing our own design system to our production-ready components. MUI is a user interface library that provides predefined and customizable React components for faster and easy web development, these Material-UI components are based o
4 min read
How to create Material Bottom Tab Navigator in React Native ? To create a Bottom Tab Navigator using Material, we need to use the createMaterialBottomTabNavigator function available in the react-navigation library. It is designed with the material theme tab bar on the bottom of the screen. It provides you with pleasing UI features and allows you to switch betw
3 min read
How to Use Routing with React Navigation in React Native ? Almost every mobile application requires navigating between different screens. React Native provides an elegant and easy-to-use library to add navigation to native applications: react-navigation. It is one of the most popular libraries used for routing and navigating in a React Native application.Tr
4 min read
React MUI Menu Navigation React MUI is a UI library that provides fully-loaded components, bringing our own design system to our production-ready components. MUI is a user interface library that provides predefined and customizable React components for faster and easy web development, these Material-UI components are based o
4 min read
React Chakra UI Navigation React Chakra UI Navigation Bar is used in every website to make it more user-friendly so that the navigation through the website becomes easy and the user can directly search for the topic of their interest. Prerequisites:NPM and NodeReact JSHTML, CSS, and JavaScriptReactJS ChakraUIWe will use the f
3 min read