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 | 31 |
Tags
- 프로그래머스
- 안드로이드 다이얼로그
- react
- Java
- 이펙티브코틀린
- Firebase
- Kotiln
- Rxjava 안드로이드
- 잡담
- 코루틴
- 반응형 프로그래밍
- 알고리즘
- 개발자
- 안드로이드 개발자
- Dev6
- 코틀린
- RxKotiln
- RxJava
- android compose
- Flutter
- swift map
- android
- Swift 문법
- MVVM
- 안드로이드
- 안드로이드 컴포즈
- 일상
- 코딩테스트
- Go언어
- 이펙티브 코틀린
Archives
- Today
- Total
최데브는 오늘도 프로그래밍을 한다.
리액트 네이티브에서 화면이동하기 본문
반응형
안드로이드에서는 intent 를 이용해서 쉽게 화면간 이동을 할 수 있었다.
React-native 에서는 아쉽게도 intent 는 없는데 이를 쉽게 할 수 있게 만들어준 라이브러리가 있다.
바로 Navigator 라는 것인데 나는 많은 Navigator중에서도stackNavigator를
사용해봤다.
안드로이드의 intent도 Activity 가 stack 형식으로 쌓이는데 이 동작과 매우 유사해서 사용해봤다.
사실 정확한 사용방법이 아닐수도 있다. 정답이 아닌 기록을 위해 적는것이니 참고만 하면 좋을 것 같다.
먼저 App.js 에서
const Stack = createStackNavigator();
function App() {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="메인">
<Stack.Screen name="메인" component={HomeScreen} />
<Stack.Screen name="로그인" component={LoginScreen} />
<Stack.Screen name="회원가입" component={JoinScreen} />
<Stack.Screen name="메인2" component={MainScreen2} options={{headerShown: false}}/>
</Stack.Navigator>
</NavigationContainer>
);
}
이렇게 Stack 으로 사용될 요소들을 미리 적어놓는다.
function HomeScreen({ navigation }) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<View style = {styles.container}>
<Image style={{width : 170 , height : 170}} source = {require("./assets/monglogo2.png")} />
</View>
<View style = {styles.bottomcontainer}>
<CustomButton
buttonColor={'#023e71'}
title={'로그인'}
onPress={() => navigation.navigate('로그인')}/>
<CustomButton
buttonColor={'#023e71'}
title={'회원가입'}
onPress={() => navigation.navigate('회원가입')}/>
</View>
</View>
);
}
그리고 onPress={() => navigation.navigate('로그인')}/> 이런식으로 버튼을 눌렀을때
Stack.Screen name = "로그인" 으로 적어준 name을 적어주면 그 화면으로 이동하게 된다.
반응형
'React' 카테고리의 다른 글
리액트 네이티브에서 firebase 으로 로그인하기 (0) | 2021.01.19 |
---|---|
Virtual DOM 은 뭘까? (0) | 2021.01.19 |
리액트 네이티브 - 커스텀 버튼 만들기 (0) | 2020.12.16 |
Comments