Skip to main content

Drawer

Drawer Navigator renders a navigation drawer on the side of the screen which can be opened and closed via gestures.

Installation

npm install @react-navigation/drawer

Then, you need to install and configure the libraries that are required by the drawer navigator:

  1. First, install react-native-gesture-handler and react-native-reanimated.
npm install react-native-gesture-handler react-native-reanimated
  1. Update babel.config.js to include the reanimated plugin:
babel.config.js
module.exports = {
presets: [
...
],
plugins: [
...
'react-native-reanimated/plugin',
],
};

Create drawer navigator

navigator/drawer.tsx
import {
createDrawerNavigator,
type DrawerNavigationEventMap,
type DrawerNavigationOptions,
} from '@react-navigation/drawer';
import type {
DrawerNavigationState,
ParamListBase,
} from '@react-navigation/native';
import { createNavigator } from 'react-native-auto-route';

const DrawerNavigator = createDrawerNavigator().Navigator;

export const Drawer = createNavigator<
DrawerNavigationState<ParamListBase>,
DrawerNavigationOptions,
DrawerNavigationEventMap,
Omit<React.ComponentProps<typeof DrawerNavigator>, 'id' | 'children'> & {
children?: React.ReactNode;
}
>(DrawerNavigator);

export default Drawer;

Example usage:

📂 app
┃ ┣ 📜 _layout.tsx
┃ ┣ 📂 (drawer)
┃ ┃ ┣ 📜 _layout.tsx
┃ ┃ ┣ 📜 home.tsx
┃ ┃ ┣ 📜 settings.tsx
app/_layout.tsx
import React from 'react';
import { Stack } from 'react-native-auto-route';

export default function Layout() {
return <Stack initialRouteName="(drawer)" />;
}