[ReactNative]Drawer Layout

์•„๋ž˜๋Š” Drawer Layout๊ด€๋ จ ์ฝ”๋“œ ์ž…๋‹ˆ๋‹ค.
Below is the code related to Drawer Layout.

์ด๋ฏธ ๋ฉ”๋‰ด์–ผ์ด ์žˆ์ง€๋งŒ ์ง์ ‘ ๋ฉ”๋‰ด์–ผ๋ณด๊ณ  ๋”ฐ๋ผํ•ด๋ณด๋ฉด ์‹คํ–‰๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
There is already a manual, but if you try to read the manual and follow it, it may not work.

์•„๋ž˜๋Š” ์ฝ”๋“œ๋Š” ์ œ๊ฐ€ ํ…Œ์ŠคํŠธ ํ–ˆ์„๋•Œ ์ •์ƒ ์ž‘๋™ํ•˜๋Š” ์ฝ”๋“œ ์ž…๋‹ˆ๋‹ค.
Below is the code that works properly when I tested it.

package.json

module install : https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started/

{
  "name": "App1",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "@react-native-community/masked-view": "^0.1.11",
    "@react-navigation/drawer": "^6.7.2",
    "@react-navigation/native": "^6.1.18",
    "react": "18.3.1",
    "react-native": "0.75.3",
    "react-native-gesture-handler": "^2.19.0",
    "react-native-reanimated": "^3.15.2",
    "react-native-safe-area-context": "^4.11.0",
    "react-native-screens": "^3.34.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "0.75.3",
    "@react-native/eslint-config": "0.75.3",
    "@react-native/metro-config": "0.75.3",
    "@react-native/typescript-config": "0.75.3",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.3.1",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  }
}

babel.config.js

module.exports = {
  presets: ['module:@react-native/babel-preset'],
  plugins: ['react-native-reanimated/plugin'],
};

index.js

/**
 * @format
 */

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => App);

App.js( test code : https://reactnavigation.org/docs/drawer-based-navigation/)

import * as React from 'react';
import { Button, View } from 'react-native';
import { createDrawerNavigator } from '@react-navigation/drawer';
import { NavigationContainer } from '@react-navigation/native';

function HomeScreen({ navigation }) {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Button
        onPress={() => navigation.navigate('Notifications')}
        title="Go to notifications"
      />
    </View>
  );
}

function NotificationsScreen({ navigation }) {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Button onPress={() => navigation.goBack()} title="Go back home" />
    </View>
  );
}

const Drawer = createDrawerNavigator();

export default function App() {
  return (
    <NavigationContainer>
      <Drawer.Navigator initialRouteName="Home">
        <Drawer.Screen name="Home" component={HomeScreen} />
        <Drawer.Screen name="Notifications" component={NotificationsScreen} />
      </Drawer.Navigator>
    </NavigationContainer>
  );
}

Leave a Reply