React Native Drawer Navigation - Complete Implementation Guide

Mahesh Mahesh Waghmare
3 min read

Drawer navigation provides a slide-out menu for navigating between screens in React Native apps. It’s a common pattern for mobile apps with multiple sections.

This guide covers implementing drawer navigation using React Navigation with complete examples.

Introduction to Drawer Navigation

Drawer navigation (hamburger menu) slides in from the side, providing access to app sections and screens.

Key Features:

  • Slide-out menu
  • Customizable design
  • Gesture support
  • Multiple screens
  • Header integration

Use Cases:

  • App navigation
  • Settings access
  • User profile
  • Main sections
  • Secondary navigation

Installation

Install Dependencies

npm install @react-navigation/native @react-navigation/drawer
npm install react-native-screens react-native-safe-area-context
npm install react-native-gesture-handler react-native-reanimated

iOS Additional Setup

cd ios && pod install
Advertisement

Basic Setup

Create Drawer Navigator

import { createDrawerNavigator } from '@react-navigation/drawer';
import { NavigationContainer } from '@react-navigation/native';

const Drawer = createDrawerNavigator();

function MyDrawer() {
  return (
    <Drawer.Navigator>
      <Drawer.Screen name="Home" component={HomeScreen} />
      <Drawer.Screen name="Profile" component={ProfileScreen} />
      <Drawer.Screen name="Settings" component={SettingsScreen} />
    </Drawer.Navigator>
  );
}

export default function App() {
  return (
    <NavigationContainer>
      <MyDrawer />
    </NavigationContainer>
  );
}

Screen Components

function HomeScreen({ navigation }) {
  return (
    <View>
      <Button
        title="Open Drawer"
        onPress={() => navigation.openDrawer()}
      />
    </View>
  );
}

Customization

Custom Drawer Content

function CustomDrawerContent(props) {
  return (
    <DrawerContentScrollView {...props}>
      <DrawerItemList {...props} />
      <DrawerItem
        label="Logout"
        onPress={() => {/* Handle logout */}}
      />
    </DrawerContentScrollView>
  );
}

<Drawer.Navigator drawerContent={(props) => <CustomDrawerContent {...props} />}>

Styling

<Drawer.Navigator
  screenOptions={{
    drawerStyle: {
      backgroundColor: '#f0f0f0',
      width: 240,
    },
    drawerActiveTintColor: '#2196F3',
    drawerInactiveTintColor: '#666',
  }}
>

Per-Screen Options

<Drawer.Screen
  name="Home"
  component={HomeScreen}
  options={{
    title: 'Home',
    drawerIcon: ({ color, size }) => (
      <Icon name="home" color={color} size={size} />
    ),
  }}
/>

Header Configuration

screenOptions={{
  headerShown: true,
  headerTitle: 'My App',
  headerStyle: {
    backgroundColor: '#2196F3',
  },
}}
Advertisement

Best Practices

1. Organize Screens

Group related screens logically.

2. Use Icons

Add icons to drawer items for better UX.

3. Limit Items

Don’t overcrowd the drawer menu.

4. Customize Design

Match drawer style to app design.

5. Handle Gestures

Ensure smooth gesture interactions.

Conclusion

Drawer navigation provides:

  • Easy navigation between screens
  • Customizable design and behavior
  • Gesture support for mobile
  • Flexible screen organization

Key Points:

  • Install React Navigation drawer
  • Create drawer navigator
  • Customize appearance
  • Add icons and styling
  • Handle navigation properly

Drawer navigation is essential for React Native apps with multiple screens and sections.

Advertisement
Mahesh Waghmare

Written by Mahesh Waghmare

I bridge the gap between WordPress architecture and modern React frontends. Currently building tools for the AI era.

Follow on Twitter

Read Next