Drawer-based Navigation

Learn how to navigate in React Native applications using a drawer.

Along with stack-based and tab-based navigation, drawer-based navigation is another form of navigation used inside React Native applications. It is similar to tab-based navigation. The only difference is that instead of the tabs being located at the bottom of the application, we are provided with a drawer containing many options. Users can navigate to different parts of the application by clicking these options. The drawer is commonly placed on the left side of the application. However, it can also be placed on the right side. The illustration below shows how drawer-based navigation works.

Press + to interact
Mobile application representing the behavior of drawer-based navigation
Mobile application representing the behavior of drawer-based navigation

Usage

To implement and use drawer-based navigation, we first have to import NavigationContainer from the @react-navigation/native library.

Press + to interact
import { NavigationContainer } from '@react-navigation/native'

Next, we need to wrap our whole application inside the NavigationContainer using the <NavigationContainer></NavigationContainer> tag.

Press + to interact
import React from "react";
import { NavigationContainer } from '@react-navigation/native'
const App = () => {
return (
<NavigationContainer>
{/* Children components */}
</NavigationContainer>
);
};
export default App;

Now we have to import createDrawerNavigator from the @react-navigation/drawer library and use it to create an instance of the drawer-based navigator.

Press + to interact
import React from "react";
import { NavigationContainer } from '@react-navigation/native'
import { createDrawerNavigator } from '@react-navigation/drawer';
const Drawer = createDrawerNavigator();
const App = () => {
return (
<NavigationContainer>
{/* Children components */}
</NavigationContainer>
);
};
export default App;

Adding screen details

Once all the steps above have been completed successfully, we can use the Navigator and Screen methods of the created drawer-navigator instance to add screen details. Users will be ...

Access this course and 1400+ top-rated courses and projects.