반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- webpack
- 오블완
- ReactNative
- unittest
- Android
- 센토스
- vsCode
- MAC
- Chrome
- androidstudio
- xcode
- node
- jest
- IOS
- 티스토리챌린지
- 맥
- react
- linux
- 리눅스
- PYTHON
- build
- qunit
- 개발
- MachineLearning
- TensorFlow
- centos
- 네트워크
- VirtualBox
- localserver
Archives
- Today
- Total
로메오의 블로그
[React Native] Stack navigation 코드 분리하기 본문
반응형
App.js
import React, { Component } from 'react';
import { createAppContainer, createStackNavigator } from 'react-navigation'
import HomeScreen from './src/HomeScreen'
import DetailsScreen from './src/DetailScreen'
const RootStack = createStackNavigator(
{
Home: {
screen: HomeScreen,
},
Details: {
screen: DetailsScreen,
},
},
{
initialRouteName: 'Home',
}
);
const AppContainer = createAppContainer(RootStack);
export default class App extends React.Component {
render() {
return <AppContainer />;
}
}
./src/HomeScreen.js
$ touch src/HomeScreen.js
import React, { Component } from 'react';
import { View, Text, Button } from 'react-native';
export default class HomeScreen extends Component {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home Screen</Text>
<Button
title="Go to Details"
onPress={() => this.props.navigation.navigate('Details')}
/>
</View>
);
}
}
./src/DetailScreen.js
$ touch src/DetailScreen.js
import React, { Component } from 'react';
import { View, Text, Button } from 'react-native';
export default class HomeScreen extends Component {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Details Screen</Text>
<Button
title="Go to Details... again"
onPress={() => this.props.navigation.push('Details')}
/>
<Button
title="Go to Home"
onPress={() => this.props.navigation.navigate('Home')}
/>
<Button
title="Go back"
onPress={() => this.props.navigation.goBack()}
/>
</View>
);
}
}
iOS App Build
$ react-native run-ios
Android App Build
$ react-native run-android
반응형
'App & OS > Hybrid' 카테고리의 다른 글
[React Native] Android Call Log 통화내역 가지고 오기 (0) | 2019.06.25 |
---|---|
[React Native] Tab navigation 사용하기 (2019년 기준) (0) | 2019.06.23 |
[React Native] Stack navigation 사용하기 (2019년 기준) (0) | 2019.06.23 |
[React Native] Codepush 배포하기 [Appcenter deployment] (1) | 2019.06.22 |
[React Native] Codepush deployment key 설정 [Appcenter] (0) | 2019.06.22 |
Comments