React Native Drawer Navigator Android iOS Tutorial with Hamburger Icon

Drawer Navigator in react native also known as Navigation drawer is a full screen view UI(User Interface) that shows all the applications main navigational menus and activities on a let to right sliding panel. Navigational Drawer is basically hide when no need and can be viewed on left to right finger swipe gesture on mobile phone screen. React Native supports the Navigational drawer using React Navigation Library in both Android and iOS applications. So in this tutorial we would going to implement Drawer Navigator in Android iOS react native application example tutorial with Hamburger Icon placement. The drawer opening and closing will be controlled by pressing the Hamburger Icon at the top left side of application screen. So let’s get started .

Note : There are some error in this code with newly react native version, but the error has been solved and now this code is successfully compatible with newly launched react native version.

Contents in this project Drawer Navigator in Android iOS React Native App Example Tutorial with Hamburger Icon :

1. Before getting started the coding we need install the React Navigation Library in order to use the Drawer Navigator in our react native app. So to install this library you need to open your React Native Project folder path in Command Prompt(CMD), like i did in below screenshot and execute the below command.


Screenshot of CMD after successfully installed the library:

2. Import StyleSheet, Platform, View, Text, Image, TouchableOpacity and YellowBox component in your project.

3. Import DrawerNavigator and StackNavigator in your project. Here StackNavigator is for control the activity structure and DrawerNavigator for showing all the activities into drawer navigation format.

4. Create a new class in your App.js file named as HamburgerIcon, This class would render the Hamburger Icon on every activity present in Navigational drawer at the top left side of mobile screen. We have uploaded the Hamburger Icon on our website and calling directly using URL.

toggleDrawer : Inside this function we would call the this.props.navigationProps.toggleDrawer() inbuilt method of drawer navigator of react navigation library. This method would open the drawer navigator on Hamburger Icon onPress event.

5. Create a class named as MainActivity, this would be our First Activity class.

6. Create a Class named as SecondActivity, This would be our second activity in this project.

7. Create another class named as ThirdActivity, This would be our third activity in this project.

8. Now we need to create a StackNavigator constant object individually for each activity. Using this we can define each Activity action bar Title text color, Title background color and we also have to set the Hamburger Icon by setting up HamburgerIcon class at headerLeft prop.

9. Create the DrawerNavigator method and call both above created Stack Navigator constant object inside it. This would set all 3 activities into navigational drawer.

10. Creating Style.

11. Complete source code for App.js File :

Screenshots in Android device:

Drawer Navigator Android iOS Tutorial Screenshots in iOS device: