반응형
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
- vsCode
- PYTHON
- 리눅스
- IOS
- androidstudio
- linux
- jest
- ReactNative
- Android
- TensorFlow
- 티스토리챌린지
- build
- xcode
- qunit
- MAC
- Chrome
- 오블완
- VirtualBox
- 네트워크
- localserver
- MachineLearning
- centos
- 개발
- 맥
- 센토스
- unittest
- webpack
- node
- react
Archives
- Today
- Total
로메오의 블로그
[React Native] Draggable FlatList 본문
반응형
프로젝트 생성
$ npx react-native init dragableList --template react-native-template-typescript
React Native Reanimated 설치
$ npm install --save react-native-reanimated
babel.config.js
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: ['react-native-reanimated/plugin'],
};
plugins에 react-native-reaminated/plugin을 추가합니다.
react-native-gesture-handler 설치
$ npm install --save react-native-gesture-handler
react-native-draggable-flatlist 설치
$ npm install --save react-native-draggable-flatlist
App.tsx
import React, {useState} from 'react';
import {Text, StyleSheet, TouchableOpacity} from 'react-native';
import DraggableFlatList, {
ScaleDecorator,
RenderItemParams,
} from 'react-native-draggable-flatlist';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
export default function Basic() {
const initialData = [
{
text: '1',
key: '1',
},
{
text: '2',
key: '2',
},
{
text: '3',
key: '3',
},
];
const [data, setData] = useState(initialData);
const renderItem = ({item, drag, isActive}: RenderItemParams<any>) => {
return (
<ScaleDecorator>
<TouchableOpacity
activeOpacity={1}
onLongPress={drag}
disabled={isActive}
style={[
styles.rowItem,
{backgroundColor: isActive ? 'red' : item.backgroundColor},
]}>
<Text style={styles.text}>{item.text}</Text>
</TouchableOpacity>
</ScaleDecorator>
);
};
return (
<GestureHandlerRootView style={{flex: 1}}>
<DraggableFlatList
data={data}
onDragEnd={({data}) => setData(data)}
keyExtractor={item => item.key}
renderItem={renderItem}
/>
</GestureHandlerRootView>
);
}
const styles = StyleSheet.create({
rowItem: {
height: 100,
alignItems: 'center',
justifyContent: 'center',
borderWidth: 1,
borderColor: 'black',
},
text: {
color: 'black',
fontSize: 24,
fontWeight: 'bold',
textAlign: 'center',
},
});
반응형
'Frontend > React' 카테고리의 다른 글
[React Native] Redux toolkit & Network call (0) | 2022.11.09 |
---|---|
[React Native] Redux toolkit (0) | 2022.11.08 |
[React Native] props (0) | 2022.10.20 |
[React Native] custom font 설정 (0) | 2022.10.17 |
[React Native] redux (0) | 2022.10.17 |
Comments