[React Native] React Navigation - 9. [Drawer] 설치 및 화면 Linking
2022. 1. 19. 13:55ㆍReact Native/Basic

9. [Drawer] 설치 및 화면 Linking
수많은 에러를 맞이했지만 이를 해결한 과정은 이전의 error/solution 4번에 정리해뒀다.
2022.01.05 - [React Native/Basic] - [React Native] error/solution
home_drawer.js
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, {Component} from 'react';
import {StyleSheet, Text, View, Button} from 'react-native';
class DrawerHomeScreen extends Component {
render() {
return (
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}}>
<Text>Home Screen</Text>
<Button
title="To User Screen"
onPress={() => {
this.props.navigation.navigate('User');
}}
/>
</View>
);
}
}
const styles = StyleSheet.create({});
export default DrawerHomeScreen;
user_drawer.js
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, {Component} from 'react';
import {StyleSheet, Text, View, Button} from 'react-native';
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
class DrawerUserScreen extends Component {
render() {
return (
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}}>
<Text>User Screen</Text>
</View>
);
}
}
const styles = StyleSheet.create({});
export default DrawerUserScreen;
App.js
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, {Component} from 'react';
import {StyleSheet, Text, View, Image, Button} from 'react-native';
import {DrawerActions, NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import {createDrawerNavigator} from '@react-navigation/drawer';
import HomeScreen from './src/home';
import UserScreen from './src/user';
import LogoTitle from './src/logo';
import DrawerHomeScreen from './src/home_drawer';
import DrawerUserScreen from './src/user_drawer';
const Stack = createNativeStackNavigator();
const Drawer = createDrawerNavigator();
class App extends Component {
logoTitle = () => {
return (
<Image
style={{width: 40, height: 40}}
source={require('./src/assets/pics/home_icon.png')}
/>
);
};
render() {
return (
<NavigationContainer>
<Drawer.Navigator>
<Drawer.Screen name="Home" component={DrawerHomeScreen} />
<Drawer.Screen name="User" component={DrawerUserScreen} />
</Drawer.Navigator>
</NavigationContainer>
// <NavigationContainer>
// <Stack.Navigator
// initialRouteName="Home"
// screenOptions={{
// headerStyle: {
// backgroundColor: '#a4511e',
// },
// headerTintColor: '#ffffff',
// headerTitleStyle: {
// fontWeight: 'bold',
// color: '#f3d612',
// },
// }}>
// <Stack.Screen
// name="Home"
// component={HomeScreen}
// options={{
// title: 'Home Screen',
// headerTitle: () => <this.logoTitle />,
// headerRight: () => (
// <Button
// title="info"
// onPress={() => alert('I am a button!!')}
// color="orange"
// />
// ),
// }}
// />
// <Stack.Screen
// name="User"
// component={UserScreen}
// initialParams={{
// userIdx: 50,
// userName: 'Gildong',
// userLastName: 'Go',
// }}
// options={{
// title: 'User Screen',
// headerStyle: {
// backgroundColor: 'pink',
// },
// headerTintColor: 'red',
// headerTitleStyle: {
// fontWeight: 'bold',
// color: 'purple',
// },
// }}
// />
// </Stack.Navigator>
// </NavigationContainer>
);
}
}
const styles = StyleSheet.create({});
export default App;
참고 자료
iOS/Android 앱 개발을 위한 실전 React Native - Basic - 인프런 | 강의
Mobile App Front-End 개발을 위한 React Native의 기초 지식 습득을 목표로 하고 있습니다. 진입장벽이 낮은 언어/API의 활용을 통해 비전문가도 쉽게 Native Mobile App을 개발할 수 있도록 제작된 강의입니다
www.inflearn.com
'React Native > Basic' 카테고리의 다른 글
[React Native] React Navigation - 11. [Drawer] Custom Component (0) | 2022.01.19 |
---|---|
[React Native] React Navigation - 10. [Drawer] Style 설정 (0) | 2022.01.19 |
[React Native] React Navigation - 8. [Stack] Header Bar에 버튼 추가 (0) | 2022.01.17 |
[React Native] React Navigation - 7. [Stack] Header Bar 커스터마이징 (0) | 2022.01.17 |
[React Native] React Navigation - 6. [Stack] 여러 화면에 공통 Style 적용 (0) | 2022.01.14 |