React Native Drawer Navigation
A drawer is a hidden side panel that slides in from the screen edge. It holds links to the main areas of an app, such as Home, Profile, Settings, and Help. Email apps, news apps, and dashboards use drawers when the number of sections is too large for a bottom tab bar.
How a Drawer Works
Closed Open ┌─────────────────┐ ┌────────┬────────┐ │ ☰ Home │ │ Menu │ Home │ │ │ ───► │ Home │ (dim) │ │ Screen │ swipe │ Profile│ │ │ content │ │ Settings │ └─────────────────┘ └────────┴────────┘
Users open the drawer with an edge swipe or by tapping the menu icon. Tapping a link switches screens and closes the panel.
Install the Packages
Drawer navigation builds on React Navigation, plus two helper libraries for gestures and animation.
npm install @react-navigation/drawer
npx expo install react-native-gesture-handler react-native-reanimated
Add the Reanimated plugin to babel.config.js as the last entry, then restart the development server with a cleared cache.
module.exports = function (api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
plugins: ['react-native-reanimated/plugin'],
};
};
Create a Basic Drawer
Build screens as normal components. Register each one inside a drawer navigator.
import { NavigationContainer } from '@react-navigation/native';
import { createDrawerNavigator } from '@react-navigation/drawer';
const Drawer = createDrawerNavigator();
export default function App() {
return (
<NavigationContainer>
<Drawer.Navigator initialRouteName="Home">
<Drawer.Screen name="Home" component={HomeScreen} />
<Drawer.Screen name="Profile" component={ProfileScreen} />
<Drawer.Screen name="Settings" component={SettingsScreen} />
</Drawer.Navigator>
</NavigationContainer>
);
}
Each Drawer.Screen becomes one link in the panel. The name value serves as the default label.
Customize Labels and Icons
The options prop controls the title, label, and icon of each entry.
<Drawer.Screen
name="Profile"
component={ProfileScreen}
options={{
drawerLabel: 'My Profile',
title: 'Profile',
drawerIcon: ({ color, size }) => (
<Ionicons name="person" size={size} color={color} />
),
}}
/>
Style the Drawer
Set colors and width through screenOptions on the navigator.
<Drawer.Navigator
screenOptions={{
drawerActiveTintColor: '#007AFF',
drawerInactiveTintColor: '#555',
drawerStyle: { width: 260, backgroundColor: '#fafafa' },
headerStyle: { backgroundColor: '#007AFF' },
headerTintColor: 'white',
}}
>
Open and Close from Code
The navigation object offers drawer commands. Wire them to your own buttons.
navigation.openDrawer();
navigation.closeDrawer();
navigation.toggleDrawer();
Build a Custom Drawer Content
Replace the default list with your own design. Add a profile header, a logout button, or section dividers.
import {
DrawerContentScrollView,
DrawerItemList,
} from '@react-navigation/drawer';
function CustomDrawer(props) {
return (
<DrawerContentScrollView {...props}>
<View style={{ padding: 20 }}>
<Text style={{ fontSize: 18, fontWeight: 'bold' }}>Asha Kumar</Text>
<Text>asha@example.com</Text>
</View>
<DrawerItemList {...props} />
</DrawerContentScrollView>
);
}
<Drawer.Navigator drawerContent={(props) => <CustomDrawer {...props} />}>
┌──────────────────┐ │ Asha Kumar │ ← custom header │ asha@example.com │ │ ──────────────── │ │ Home │ ← DrawerItemList │ Profile │ │ Settings │ └──────────────────┘
Combine Drawer with Stack
Real apps nest navigators. Place a stack navigator inside a drawer screen so detail pages keep a back button while the drawer stays available on top-level screens.
Drawer ├── Home (Stack) │ ├── HomeList │ └── ItemDetail ├── Profile └── Settings
Drawer or Tabs?
- Choose tabs for three to five equal, frequent destinations
- Choose a drawer for many destinations or rarely used sections
- Combine both when the app has primary tabs and secondary utilities
Summary
A drawer navigator hides many destinations behind one swipe or menu tap. Install the drawer package with its gesture and animation helpers, register screens, and customize icons and colors through options. Build custom drawer content for profile headers, and nest stacks inside drawer screens for detail pages.
