반응형
react-native를 개발 할 때 항상 느끼는거지만 버전에 따른 개발이 달라져서 힘들었습니다.
반드시 버전을 확인해서 개발에 적용하시길 바랍니다.
- 모듈 버전
react-native : 0.64.0 @react-navigation/native : ^5.9.4 @react-navigation/stack : ^5.14.4 react-native-gesture-handler : ^1.10.3 react-native-safe-area-context : ^3.2.0 react-native-screens : ^3.0.0 |
- 모듈 설치
npm install @react-navigation/native npm install @react-navigation/stack npm install react-native-safe-area-context npm install react-native-gesture-handler npm install react-native-screens |
1. StackNavigator에 화면을 정의합니다.
// App.js
import * as React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import MainScreen from './MainScreen';
import DetailScreen from './DetailScreen';
const Stack = createStackNavigator();
function App() {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="MAIN">
<Stack.Screen name="MAIN" component={MainScreen}
options={{
title: '메인화면'
}}/>
<Stack.Screen name="DETAIL" component={DetailScreen}
options={{
title: '상세화면'
}}/>
</Stack.Navigator>
</NavigationContainer>
);
}
export default App;
2. 첫번째 화면(MainScreen.js)을 구성합니다.
//MainScreen.js
import React, { Component } from 'react';
import { View, Text, Button } from 'react-native';
export default class MainScreen extends Component {
render() {
return (
<View>
<Text style={{fontSize:30}}>Main Screen</Text>
<Button onPress={() => this.goMainScreen()} title='Go Detail Screen'/>
</View>
);
}
goMainScreen(){
// DetailScreen으로 화면 이동
this.props.navigation.navigate('DETAIL');
}
}
3. 두번째 화면(DetailScreen.js)을 구성합니다.
// DetailScreen.js
import React, { Component } from 'react';
import { View, Text, } from 'react-native';
export default class DetailScreen extends Component {
render() {
return (
<View>
<Text style={{fontSize:30}}>Detail Screen</Text>
</View>
);
}
}
반응형
'React-Native' 카테고리의 다른 글
React-Native - ITMS-90433: Invalid Swift Support - The file libswiftCore.dylib doesn’t have the correct code signature. (0) | 2021.04.07 |
---|---|
React-Native 0.64.0 화면간 데이터(파라미터) 전달하기 (1) | 2021.04.05 |
React-Native 0.62.2에서 iOS 14에 이미지 표시 안되는 현상 해결 방법 (0) | 2021.03.29 |
React-Native iOS 개발을 위한 VMWare Play 설정 (0) | 2021.03.28 |
React-Native Execution failed for task ':app:mergeDexDebug' (0) | 2021.03.28 |
댓글