뭘잘못했는지 이유를 잘모르겠음
화면이 두번이상 안넘어가서 원인을 찾아보는중 App.js에서만 Navigatior선언을 해놔서 그런것이 아닌가 의심
구글링해서 내가 하고싶은대로 한거 찾아냄 정리함
App.js
import React, {Component} from 'react';
import {createStackNavigator, createAppContainer} from 'react-navigation';
import firstpage from './First';
import secondpage from './Second';
const App = createStackNavigator(
{
Home: {screen:firstpage},
Second: {screen:secondpage}
..
..
..이런식으로 계속 쌓아놓으면 다른곳에서 쓸수있을거라 생각됨
},
{initialRouteName: 'Home', headerMode: 'none'} //이걸로 아마 시작페이지를 결정하는것이 아닌가
);
export default createAppContainer(App);
App.js에 이런식으로 코드 해놓음
First.js
import React, {Component} from 'react';
import {View, Text, TouchableOpacity} from 'react-native';
class First extends Component {
render() {
const {navigation} = this.props;
return (
<View style={{flex: 1, justifyContent: 'center'}}>
<TouchableOpacity
onPress={()=> {navigation.navigate("Second")}}
>
<Text>
This is First
</Text>
</TouchableOpacity>
</View>
);
}
}
export default First;
이게 첫번째 화면 This is First를 누르면 Second로 넘어가는거같음
Second.js
import React, {Component} from 'react';
import {Text,View,TouchableOpacity} from 'react-native';
class Second extends Component {
render() {
const {navigation} = this.props;
return (
<View style={{flex:1,justifyContent: 'center'}} >
<TouchableOpacity
onPress={()=>{
navigation.goBack()
}}
>
<Text style={{alignItems: 'center'}}>Second Page</Text>
</TouchableOpacity>
</View>
);
}
}
export default Second;
본건 second까지지만 목표는 뒤로가는게 아니라 다음에 다음페이지 까지 만들어서 이동시키는것
보다가 헷갈리는거있으면 여기가서 다시보기
출처 : philip1994.tistory.com/96
[react-native] react-navigation사용하기
이번에는 react-native 에서 화면이동을 진행하려고한다. react-native에서 화면 이동은 여러가지 모듈이 있지만, 이 글에서는 facebook에서 만든 navigation을 이용할것이다. 모듈에 대한 설명과 메소드들
philip1994.tistory.com
화면이동1,2 가 안되는게아님 설정을 뭔가 잘못해서 그런거같음 두번이동이 하고싶을때 이거보기
'React-Native' 카테고리의 다른 글
React-Native 함수, 변수 사용 (0) | 2021.02.02 |
---|---|
React-Native 화면전환 최종 (0) | 2021.01.29 |
React-Native 화면전환2 (0) | 2021.01.26 |
React-Native CSS (0) | 2021.01.13 |
React-Native State (0) | 2021.01.12 |