React Navigation 5 Tutorials [ #5 ]

์กฐํŒ”๋กœยท2020๋…„ 10์›” 1์ผ
1

React-Navigation-5 Tutorials

๋ชฉ๋ก ๋ณด๊ธฐ
5/6
post-thumbnail

React Navigation 5 Tutorials

๐Ÿ“Œ ํŠœํ† ๋ฆฌ์–ผ์„ ๋”ฐ๋ผํ•œ ํ”„๋กœ์ ํŠธ์ž…๋‹ˆ๋‹ค!

์‚ฌ๋ผ์ง„ ์ƒ๋‹จ๋ฐ” ์ƒ์„ฑํ•˜๊ธฐ

Home / Details Stack ์ƒ์„ฑํ•˜๊ธฐ

1. Stack์„ ๋ณต์‚ฌํ•ด์„œ HomeStack / DetailsStack์„ ์ƒ์„ฑํ•ด์ค์‹œ๋‹ค

const HomeStack = createStackNavigator();
const DetailsStack = createStackNavigator();

2. Stack์„ ์‚ฌ์šฉํ•˜์—ฌ HomeStackScreen ์ปดํฌ๋„ŒํŠธ์™€ DetailsStackScreen ์ปดํฌ๋„ŒํŠธ ์ƒ์„ฑํ•˜๊ธฐ

const HomeStackScreen = ({navigation}) => {
  return (
    <HomeStack.Navigator screenOptions={{
      headerStyle:{
        backgroundColor: '#009387',
    },
      headerTintColor: '#fff',
      headerTitleStyle: {
        fontWeight: 'bold',
      }
    }}>
      <HomeStack.Screen name="Home" component={HomeScreen} options={{
        title : 'Home'
      }}/>
    </HomeStack.Navigator>
  );
};

const DetailsStackScreen = ({navigation}) => {
  return (
    <DetailsStack.Navigator screenOptions={{
      headerStyle:{
        backgroundColor: '#009387',
    },
      headerTintColor: '#fff',
      headerTitleStyle: {
        fontWeight: 'bold',
      }
    }}>
      <DetailsStack.Screen name="Details" component={DetailsScreen} options={{
        title : 'Details'
      }}/>
    </DetailsStack.Navigator>
  );
};

3. APP ์ปดํฌ๋„ŒํŠธ์— ์žˆ๋Š” Drawer.Screen ์ˆ˜์ •ํ•˜๊ธฐ

const App = () => {
  return (
    <NavigationContainer>
      <Drawer.Navigator initialRouteName="Home">
        <Drawer.Screen name="Home" component={HomeStackScreen} />
        <Drawer.Screen name="Details" component={DetailsStackScreen} />
      </Drawer.Navigator>
    </NavigationContainer>
  );
};

์ƒ๋‹จ๋ฐ”์— menu icon ์ถ”๊ฐ€ํ•˜๊ธฐ

1. Icons import ํ•˜๊ธฐ

  1. ์„ค์น˜
npm install react-native-vector-icons
  1. import ํ•˜๊ธฐ
import Icon from 'react-native-vector-icons/Ionicons';

2. menu icon ์ถ”๊ฐ€ํ•˜๊ธฐ

๊ฐ HomeStackScreen/DetailsStackScreen์— headerLeft ์†Œ์Šค๋ฅผ ์ถ”๊ฐ€ํ•ด์ค์‹œ๋‹ค.

      <HomeStack.Screen name="Home" component={HomeScreen} options={{
        title : 'Home',
        headerLeft: () => (
          <Icon.Button name='ios-menu' size={25}
          backgroundColor= '#009387' onPress = {() => {navigation.openDrawer()}}>
          </Icon.Button>
        )
      }}/>

๊ฒฐ๊ณผ๋ณด๊ธฐ

profile
ํ˜„์‹ค์— ์•ˆ์ฃผํ•˜์ง€ ์•Š๊ณ  - ๊ฐœ๋ฐœ์ž

0๊ฐœ์˜ ๋Œ“๊ธ€