-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeetFlatList.js
More file actions
144 lines (136 loc) · 4.92 KB
/
MeetFlatList.js
File metadata and controls
144 lines (136 loc) · 4.92 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import React, { Component } from 'react';
import { AppRegistry, FlatList, StyleSheet, Text, View, Image, Alert, Platform, TouchableHighlight } from 'react-native';
import FlatListData from './FlatListData';
import Swipeout from 'react-native-swipeout';
import AddMett from './AddMett';
class FlatListItem extends Component {
constructor(props) {
super(props);
this.state = {
activeRowKey: null
};
}
render() {
const swipeSettings = {
autoClose: true,
onClose: (secId, rowId, direction) => {
if(this.state.activeRowKey != null) {
this.setState({ activeRowKey: null });
}
},
onOpen: (secId, rowId, direction) => {
this.setState({ activeRowKey: this.props.item.key });
},
right: [
{
onPress: () => {
const deletingRow = this.state.activeRowKey;
Alert.alert(
'Alert',
'Are you sure you want to delete ?',
[
{text: 'No', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
{text: 'Yes', onPress: () => {
FlatListData.splice(this.props.index, 1);
//Refresh FlatList !
this.props.parentFlatList.refreshFlatList(deletingRow);
}},
],
{ cancelable: true }
);
},
text: 'Delete', type: 'delete'
}
],
rowId: this.props.index,
sectionId: 1
};
return (
<Swipeout {...swipeSettings}>
<View style={{
flex: 1,
flexDirection:'column',
}}>
<View style={{
flex: 1,
flexDirection:'row',
backgroundColor: 'mediumseagreen'
}}>
<View style={{
flex: 1,
flexDirection:'column',
height: 100
}}>
<Text style={styles.flatListItem}>{this.props.item.name}</Text>
<Text style={styles.flatListItem}>{this.props.item.description}</Text>
</View>
</View>
<View style={{
height: 1,
backgroundColor:'white'
}}>
</View>
</View>
</Swipeout>
);
}
}
const styles = StyleSheet.create({
flatListItem: {
color: 'white',
padding: 10,
fontSize: 16,
}
});
export default class MeetFlatList extends Component {
constructor(props) {
super(props);
this.state = ({
deletedRowKey: null,
});
this._onPressAdd = this._onPressAdd.bind(this);
}
refreshFlatList = (activeKey) => {
this.setState((prevState) => {
return {
deletedRowKey: activeKey
};
});
this.refs.flatList.scrollToEnd();
}
_onPressAdd () {
// alert("You add Item");
this.refs.AddMett.showAddMett();
}
render() {
return (
<View style={{flex: 1, marginTop: Platform.OS === 'ios' ? 34 : 0}}>
<View style={{
backgroundColor: 'tomato',
flexDirection: 'row',
justifyContent:'flex-end',
alignItems: 'center',
height: 64}}>
<TouchableHighlight
style={{marginRight: 10}}
underlayColor='tomato'
onPress={this._onPressAdd}
>
</TouchableHighlight>
</View>
<FlatList
ref={"flatList"}
data={FlatListData}
renderItem={({item, index})=>{
return (
<FlatListItem item={item} index={index} parentFlatList={this}>
</FlatListItem>);
}}
>
</FlatList>
<AddMett ref={'AddMett'} parentFlatList={this} >
</AddMett>
</View>
);
}
}