React Native Show Tab Navigator Inside Drawer Navigator Example Tutorial

Tab Navigator inside Drawer Navigator is used by hundreds of mobile applications where developer wants to manage multiple activities(screen) in single mobile app. Tab Navigator show all the screens into a single screen with already implemented animated swipeable feature, Activity names will show at the top of the mobile app. In Drawer Navigator there is a slide menu panel present at the left side of screen which contains all the screen names as menus and when user clicks any of them it will open a new activity. So in this tutorial we would going to implement Tab Navigator Inside Drawer Navigator in react native android iOS mobile app Example Tutorial.

Screenshot : Below is the screenshot of our application.


Contents in this project Show Tab Navigator Inside Drawer Navigator in React Native Android iOS App Example Tutorial :

1. Before getting started we need  to install the latest version of React Navigation library in our project to use the activity implementation structure. To install react navigation in your project open your project folder in CMD – Terminal and execute below command.

Screenshot of CMD:

2. Next step is to install the react-native-gesture-handler library in your react native app. So again open your project folder in command prompt or Terminal and execute the below command.

Screenshot:

3. Now we need to execute react-native link command in your react native project. This command will re-arranged your complete react native project and index all the newly installed libraries in it.

Screenshot:

4. Now there is no extra steps for iOS configuration.

5. To configure the react-native-gesture-handler library for react native project we need to add some additional libraries in our MainActivity.java file.

So goto YourProject – > android -> app -> src- >main -> java -> com-> YourProject -> MainActivity.java file.Open MainActivity.java file in edit mode in notepad or any text editor and put below files.

You need to also put the return function for ReactActivityDelegate.

Complete source code of MainActivity.java file, It will help you to understand all the changes after adding above code:

6. Now your project is good to go, Its time to start coding .

7. Open your react native project folder and open App.js file and import StyleSheet, Text, View, Button, TouchableOpacity and Image component in your project.

8. Import createAppContainer, createMaterialTopTabNavigator, createDrawerNavigator and createStackNavigator component from react navigation library in your project.

createAppContainer : This component is used as main default export parent, Means if you have created any Tab Navigator or Drawer navigator or Stack Navigator in your project. At the final step you have to call them using createAppContainer.

createMaterialTopTabNavigator : Is used to creating material style top level tab navigation in react native for both android and iOS mobile apps.

createDrawerNavigator : Is used to create navigational drawer in both android and iOS mobile applications.

createStackNavigator : Its make the every individual class as an Activity screen.

9. Creating a class named as HamburgerIcon in your project. This class is used to put a Hamburger Icon at the top left side of Drawer Navigator.

this.props.navigationProps.toggleDrawer() : We would call this function on Hamburger icon click event, This function will open and close the navigational drawer.

10. Creating 2 Activity classes named as Home_Screen and Settings_Screen. These 2 classes is will be grouped together and shows inside Tab Navigator.

title : Is used to show the activity title in Title bar.

Screenshots:

Show Tab Navigator Inside Drawer Navigator

11. Creating another two classes named as Student_Screen and Details_Screen. These classes is also grouped together as Tab Navigator.

Screenshots:

12. Creating a constant view named as Tab_1 with createMaterialTopTabNavigator component and pass the two activity classes Home_Screen and Settings_Screen inside it. This will group them together as a Tab Navigator.

13. Creating another constant view named as Tab_2 and with createMaterialTopTabNavigator component and pass the another two renaming activities Student_Screen, Details_Screen inside it. It will also group them together and make another tab navigator view.

14. Next step is to pass the both Tab_1 and Tab_2 Views into individual createStackNavigator views. This will make the complete Tab Navigator View into Stack navigator. So create 2 createStackNavigator views named as First_2_Tabs and Second_2_Tabs in your project.

15. Create a constant named as MyDrawerNavigator with createDrawerNavigator component and pass both the First_2_Tabs and Second_2_Tabs inside it as individual screens. Now at the final step we need to pass the complete MyDrawerNavigator into createAppContainer component in order to show on screen.

16. Creating Style.

17. Complete source code for App.js File :

Screenshots:

Show Tab Navigator Inside Drawer Navigator