App3.js 1.6 KB
Newer Older
YoonDongMin's avatar
YoonDongMin committed
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React, {useState} from 'react' ;
import {StyleSheet, Text, View, FlatList, TouchableOpacity} from 'react-native';
import { LongPressGestureHandler } from 'react-native-gesture-handler';
//ScrollView를 해야 밑에 내릴 수 있음
export default function App() {
    const [people, setPeople] = useState([
        { name : 'shaun', id: '1'},
        { name : 'yoshi', id: '2'},
        { name : 'shaun', id: '3'},
        { name : 'shaun', id: '4'},
        { name : 'shaun', id: '5'},
        { name : 'shaun', id: '6'},
        { name : 'shaun', id: '7'},
    ]);

    const pressHandler = (id) => {
        console.log(id);
        setPeople((prevPeople) => {
            return prevPeople.filter(person => person.id != id);
        });
    }

return (
    <View style = {styles.container}>
            <FlatList
            numColumns={2}
            keyExtractor = {(item) => item.id}
            data = {people}
            renderItem = {({item}) => (
                <TouchableOpacity OnPress = {()  => LongPressGestureHandler(item.id)}>
                    <Text style = {styles.item} > {item.name}</Text>
                </TouchableOpacity>
                
            )}
            />

    </View>
    ); //key를 나타내어주어야 error가 안뜸 
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#fff',
        paddingTop: 40,
        paddingHorizontal: 20 
    },
    item: {
        marginTop: 24,
        padding:30,
        backgroundColor: 'pink',
        fontSize: 24,
        marginHorizontal: 10,
        marginTop: 24,
    } //세로간격 나누기
});