0Pricing
React Native Academy · 강의

서랍 내비게이터와 중첩 내비게이터

서랍 내비게이터를 설정하고 그중 한 화면 안에 스택을 중첩하며, 중첩 내비게이터가 헤더와 뒤로 가기 버튼에 어떻게 상호작용하는지 이해합니다.

서랍 내비게이터와 중첩 내비게이터은(는) CoddyKit의 무료 React Native Academy 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 React Native Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. React Native Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

What is a Drawer Navigator?

A drawer navigator shows a slide-out side menu (drawer) that the user can open by swiping from the left edge or tapping a hamburger icon. It is ideal for apps with many top-level sections that do not fit in a tab bar. React Navigation provides it via the @react-navigation/drawer package.

Installing the Drawer Package

The drawer navigator requires additional gesture and animation libraries. Install the drawer package and its peer dependencies. The drawer relies on react-native-gesture-handler and react-native-reanimated for smooth animations.

npm install @react-navigation/drawer
npx expo install react-native-gesture-handler react-native-reanimated

Configuring Reanimated Babel Plugin

React Native Reanimated requires a Babel plugin to work. Add 'react-native-reanimated/plugin' as the last entry in your babel.config.js plugins array. Restart Metro bundler after making this change to clear the cache.

// babel.config.js
module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: ['react-native-reanimated/plugin'],
  };
};

Creating a Drawer Navigator

Use createDrawerNavigator() and register screens with Drawer.Screen components. Each screen appears as a menu item in the drawer. The drawer also renders a header with a hamburger menu icon that opens the drawer when tapped.

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

const Drawer = createDrawerNavigator();

function MyDrawer() {
  return (
    <Drawer.Navigator initialRouteName='Home'>
      <Drawer.Screen name='Home' component={HomeScreen} />
      <Drawer.Screen name='Settings' component={SettingsScreen} />
      <Drawer.Screen name='About' component={AboutScreen} />
    </Drawer.Navigator>
  );
}

Opening and Closing the Drawer

From any screen inside the drawer navigator, call navigation.openDrawer() to open the side menu, navigation.closeDrawer() to close it, and navigation.toggleDrawer() to toggle between open and closed. Users can also swipe from the edge or tap the backdrop to close it.

function HomeScreen({ navigation }) {
  return (
    <Button
      title='Open Menu'
      onPress={() => navigation.openDrawer()}
    />
  );
}

Customizing Drawer Screen Options

Use the drawerIcon option on each Drawer.Screen to add an icon next to the menu item. Use drawerLabel to override the display name. These options follow the same pattern as tab navigator options, giving you a consistent API across navigators.

<Drawer.Screen
  name='Home'
  component={HomeScreen}
  options={{
    drawerLabel: 'Dashboard',
    drawerIcon: ({ color, size }) => (
      <Ionicons name='home-outline' size={size} color={color} />
    ),
  }}
/>

What Are Nested Navigators?

Nested navigators occur when you place one navigator inside a screen of another navigator. For example, a drawer navigator can contain a tab navigator, which can itself contain stack navigators inside each tab. This is how complex apps structure their navigation hierarchy.

Nesting a Stack Inside a Drawer Screen

To give each drawer section its own navigation history, use a Stack.Navigator as the component for a Drawer.Screen. The stack's header and the drawer header may conflict — set headerShown: false on the drawer to hide its header and rely on the stack header.

function HomeStack() {
  return (
    <Stack.Navigator>
      <Stack.Screen name='Home' component={HomeScreen} />
      <Stack.Screen name='Details' component={DetailsScreen} />
    </Stack.Navigator>
  );
}

<Drawer.Screen
  name='HomeSection'
  component={HomeStack}
  options={{ headerShown: false }}
/>

Navigation Across Nested Navigators

When navigating across nested navigators (e.g., from a screen inside a tab to a screen in another tab's stack), use the full screen name and navigator target. React Navigation resolves the correct navigator. You may also navigate to a parent navigator's screen using navigation.navigate('ParentScreen', { screen: 'ChildScreen' }).

// Navigate to a screen nested inside a different tab
navigation.navigate('ProfileTab', {
  screen: 'EditProfile',
  params: { userId: 5 },
});

The Back Button and Nested Stacks

When a stack is nested inside a tab or drawer, the back button in the stack header only pops the stack — it does not switch tabs or close the drawer. Each navigator manages its own history independently. This is intentional and matches the expected behavior users experience in native apps.

Custom Drawer Content

Replace the default drawer menu with a fully custom component using the drawerContent prop on Drawer.Navigator. Your custom component receives navigation and state props and can display a user avatar, subscription info, or any other content above or below the menu items.

function CustomDrawer(props) {
  return (
    <DrawerContentScrollView {...props}>
      <Image source={{ uri: user.avatar }} style={styles.avatar} />
      <Text>{user.name}</Text>
      <DrawerItemList {...props} />
    </DrawerContentScrollView>
  );
}

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

Quick Check

Test your understanding of Drawer Navigator and nested navigators from this lesson.

Lesson Recap

In this lesson you learned: create a drawer navigator with createDrawerNavigator, open and close the drawer programmatically with navigation.openDrawer/closeDrawer, and nest navigators by using a navigator component as a screen's component prop. Next up we explore the FlatList component for efficiently rendering large data sets.

자주 묻는 질문

“서랍 내비게이터와 중첩 내비게이터” 강의는 무료인가요?

네 — “서랍 내비게이터와 중첩 내비게이터” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 React Native Academy 강의 전체를 잠금 해제할 수 있습니다. React Native Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

“서랍 내비게이터와 중첩 내비게이터”에서 뭘 배우나요?

서랍 내비게이터를 설정하고 그중 한 화면 안에 스택을 중첩하며, 중첩 내비게이터가 헤더와 뒤로 가기 버튼에 어떻게 상호작용하는지 이해합니다. 브라우저에서 직접 실행하는 실습 코드로 React Native Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

React Native Academy을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 React Native Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“서랍 내비게이터와 중첩 내비게이터” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 React Native Academy 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 React Native Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. React Navigation 설치 및 구성
  2. 화면 간 이동과 매개변수 전달
  3. 하단 탭 내비게이터
  4. 서랍 내비게이터와 중첩 내비게이터
← React Native Academy(으)로 돌아가기