일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 리액트 네이티브 설치 오류
- c++ 정보은닉
- 스탠실 버퍼 튜토리얼
- react native ios 기기 연결
- 스탠실 버퍼 사용
- react native accessible
- 싸이월드
- cyworld
- C++
- GitHub
- node
- react native typescript navigate
- node.js
- html
- react native mac
- 벡터와 리스트의 차이
- react native 타입스크립트
- unity stencil buffer
- react
- Expo
- react native typescript
- react native typescript navigation
- javascript
- react-native
- react native
- stencil buffer
- c++ using
- CSS
- 리액트 네이티브 맥
- 스탠실 버퍼 시작
Archives
- Today
- Total
혀니의 이거저거 뿌시기
react-native swipe 이용해서 화면 전환하기 본문
728x90
How to Create a Swipeable Component in React Native – REACT NATIVE FOR YOU
How to Create a Swipeable Component in React Native
Having swipeable components in your app is very useful for actions such as deleting and archiving. The swiping ability inside your app brings down the rigid nature of user interface and increase th…
reactnativeforyou.com
참고한 코드는 요기
package com.sampleapp3;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "SampleApp3";
}
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {
@Override
protected ReactRootView createRootView() {
return new RNGestureHandlerEnabledRootView(MainActivity.this);
}
};
}
}
1. MainActivity.java
//import liraries
import React, { Component } from 'react';
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
import SwipeableRow from './SwipeableRow';
// create a component
class App extends Component {
render() {
return (
<View style={styles.container}>
<SwipeableRow></SwipeableRow>
</View>
);
}
}
// define your styles
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
//make this component available to the app
export default App;
2.App.js
import React, { Component } from 'react';
import { Animated, StyleSheet, Text, View, Button} from 'react-native';
import { RectButton } from 'react-native-gesture-handler';
import Swipeable from 'react-native-gesture-handler/Swipeable';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
const Stack = createStackNavigator();
function HomeScreen({navigation}){
return(
<View style = {{flex : 1, alignItems : 'center', justifyContent : 'center',}}>
<Text>Home Screen입니다.</Text>
</View>
);
}
function ProfileScreen(){
return(
<View style = {{flex : 1, alignItems : 'center', justifyContent : 'center',}}>
<Text>ProfileScreen입니다.</Text>
</View>
);
}
export default class SwipeableRow extends Component {
renderLeftActions = (progress, dragX) => {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} options={{ title: 'Welcome' }}/>
</Stack.Navigator>
</NavigationContainer>
);
};
renderRightActions = (progress, dragX) => {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Profile" component={ProfileScreen} options={{ title: 'Profile' }}/>
</Stack.Navigator>
</NavigationContainer>
);
};
render() {
return (
<Swipeable renderLeftActions={this.renderLeftActions} renderRightActions={this.renderRightActions}>
<RectButton style={styles.rectButton}>
</RectButton>
</Swipeable>
);
}
}
const styles = StyleSheet.create({
leftAction: {
flex: 1,
backgroundColor: 'cyan',
justifyContent: 'center',
},
actionText: {
color: 'black',
fontSize: 16,
},
rectButton: {
width:'100%',
height: '100%',
backgroundColor: 'blue',
},
});
3.SwipeableRow.js
결과 화면
파란 화면을 메인이라고 했을 때 양 옆으로 움직일 시 각각 다른 메뉴가 나오는 것을 알 수 있다..
이제 이거를 최대한 우리가 만들기로 했던 프로토타입과 유사한 형태로 고쳐봐야겠지...^^
728x90
'FRONT > 리액트네이티브' 카테고리의 다른 글
expo (react-native를 쉽게 해주는) 깔고 동작해보기! (0) | 2021.07.30 |
---|---|
react-native-camera 카메라/비디오 작동시키기 성공 (0) | 2021.07.26 |
에러정리... (0) | 2021.07.25 |
native navigation으로 화면전환시키기! (2022.04.03 수정) (0) | 2021.07.23 |
리액트 시작.(Windows ver.) (0) | 2021.07.22 |