Open In App

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 components in React Native. We want to use React Navigation.

Syntax:



const Tab = createBottomTabNavigator();
<Tab.Navigator >
   <Tab.Screen/>
</Tab.Navigator>

Props in Tab Navigation:



 

Now let’s start with the implementation:

For React Tab Navigation: This can be used in React Native as well

https://reactnavigation.org/docs/tab-based-navigation/

Project Structure:

Example: Now let’s implement Tab Navigation.




import * as React from 'react';
import { Text, View } from 'react-native';
import { NavigationContainer } 
         from '@react-navigation/native';
import { createBottomTabNavigator } 
         from '@react-navigation/bottom-tabs';
  
function Home() {
  return (
    <View style={{ flex: 1, justifyContent: 'center'
                   alignItems: 'center' }}>
      <Text>Home!</Text>
    </View>
  );
}
  
function Setting() {
  return (
    <View style={{ flex: 1, justifyContent: 'center'
                   alignItems: 'center' }}>
      <Text>Settings!</Text>
    </View>
  );
}
  
function Notification() {
  return (
    <View style={{ flex: 1, justifyContent: 'center',
                   alignItems: 'center'}}>
      <Text>Notifications!</Text>
    </View>
  );
}
  
const Tab = createBottomTabNavigator();
  
export default function App() {
  return (
    <NavigationContainer >
      <Tab.Navigator initialRouteName={Home} >
        <Tab.Screen name="Home" component={Home}  />
        <Tab.Screen name="Notifications" 
                    component={Notification} />
        <Tab.Screen name="Settings" component={Setting} />
      </Tab.Navigator>
    </NavigationContainer>
  );
}

Start the server by using the following command.

npm run android

Output: If your emulator did not open automatically then you need to do it manually. First, go to your android studio and run the emulator. Now start the server again. 

Reference: https://reactnative.dev/docs/navigation#react-navigation


Article Tags :