This is an example of Bottom Tab View inside Navigation Drawer / Sidebar with React Navigation in React Native. We will use react-navigation to make a navigation drawer and Tab in this example. I hope you have already seen our post on React Native Navigation Drawer because in this post we are just extending the last post to show the Bottom Tab View inside the Navigation Drawer.
In this example, we have a navigation drawer with 3 screens in the navigation menu and a Bottom Tab on the first screen of the Navigation Drawer. When we open Screen1 the Bottom Tab will be visible and on the other options, this Bottom Tab will be invisible.
<NavigationContainer>
<Drawer.Navigator
drawerContentOptions={{
activeTintColor: '#e91e63',
itemStyle: { marginVertical: 5 },
}}>
<Drawer.Screen
name="HomeScreenStack"
options={{ drawerLabel: 'Home Screen Option' }}
component={HomeScreenStack} />
<Drawer.Screen
name="SettingScreenStack"
options={{ drawerLabel: 'Setting Screen Option' }}
component={SettingScreenStack} />
</Drawer.Navigator>
</NavigationContainer>
<Tab.Navigator
initialRouteName="HomeScreen"
tabBarOptions={{
activeTintColor: 'tomato',
inactiveTintColor: 'gray',
style: {
backgroundColor: '#e0e0e0',
},
labelStyle: {
textAlign: 'center',
fontSize: 16
},
}}>
<Tab.Screen
name="HomeScreen"
component={HomeScreen}
options={{
tabBarLabel: 'Home Screen',
// tabBarIcon: ({ color, size }) => (
// <MaterialCommunityIcons name="home" color={color} size={size} />
// ),
}} />
<Tab.Screen
name="ExploreScreen"
component={ExploreScreen}
options={{
tabBarLabel: 'Explore Screen',
// tabBarIcon: ({ color, size }) => (
// <MaterialCommunityIcons name="settings" color={color} size={size} />
// ),
}} />
</Tab.Navigator>
In this example, we will make a Tab Navigator inside a Drawer Navigator so let’s get started.
Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli
command line utility. Open the terminal and go to the workspace and run
npm install -g react-native-cli
Run the following commands to create a new React Native project
react-native init ProjectName
If you want to start a new project with a specific React Native version, you can use the --version argument:
react-native init ProjectName --version X.XX.X
react-native init ProjectName --version react-native@next
This will make a project structure with an index file named App.js in your project directory.
#bottom navigation #drawer navigation #react #react navigation