forked from jemise111/react-native-swipe-list-view
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
145 lines (135 loc) · 3.08 KB
/
example.js
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
145
import React, {
Component,
} from 'react';
import {
AppRegistry,
ListView,
StyleSheet,
Text,
TouchableOpacity,
TouchableHighlight,
View
} from 'react-native';
import { SwipeListView, SwipeRow } from './lib';
class App extends Component {
constructor(props) {
super(props);
this.ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.state = {
listViewData: Array(20).fill('').map((_,i)=>`item #${i}`)
};
}
deleteRow(secId, rowId, rowMap) {
rowMap[`${secId}${rowId}`].closeRow();
const newData = [...this.state.listViewData];
newData.splice(rowId, 1);
this.setState({listViewData: newData});
}
render() {
return (
<View style={styles.container}>
<View style={styles.standalone}>
<SwipeRow
leftOpenValue={75}
rightOpenValue={-75}
>
<View style={styles.standaloneRowBack}>
<Text style={styles.backTextWhite}>Left</Text>
<Text style={styles.backTextWhite}>Right</Text>
</View>
<View style={styles.standaloneRowFront}>
<Text>I'm a standalone SwipeRow</Text>
</View>
</SwipeRow>
</View>
<SwipeListView
dataSource={this.ds.cloneWithRows(this.state.listViewData)}
renderRow={ data => (
<TouchableHighlight
onPress={ _ => console.log('You touched me') }
style={styles.rowFront}
underlayColor={'#AAA'}
>
<View>
<Text>I'm {data} in a SwipeListView</Text>
</View>
</TouchableHighlight>
)}
renderHiddenRow={ (data, secId, rowId, rowMap) => (
<View style={styles.rowBack}>
<Text>Left</Text>
<View style={[styles.backRightBtn, styles.backRightBtnLeft]}>
<Text style={styles.backTextWhite}>Right</Text>
</View>
<TouchableOpacity style={[styles.backRightBtn, styles.backRightBtnRight]} onPress={ _ => this.deleteRow(secId, rowId, rowMap) }>
<Text style={styles.backTextWhite}>Delete</Text>
</TouchableOpacity>
</View>
)}
leftOpenValue={75}
rightOpenValue={-150}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
flex: 1
},
standalone: {
marginTop: 50,
marginBottom: 50,
},
standaloneRowFront: {
alignItems: 'center',
backgroundColor: '#CCC',
justifyContent: 'center',
height: 50,
},
standaloneRowBack: {
alignItems: 'center',
backgroundColor: '#8BC645',
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
padding: 15
},
backTextWhite: {
color: '#FFF'
},
rowFront: {
alignItems: 'center',
backgroundColor: '#CCC',
borderBottomColor: 'black',
borderBottomWidth: 1,
justifyContent: 'center',
height: 50,
},
rowBack: {
alignItems: 'center',
backgroundColor: '#DDD',
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
paddingLeft: 15,
},
backRightBtn: {
alignItems: 'center',
bottom: 0,
justifyContent: 'center',
position: 'absolute',
top: 0,
width: 75
},
backRightBtnLeft: {
backgroundColor: 'blue',
right: 75
},
backRightBtnRight: {
backgroundColor: 'red',
right: 0
}
});
export default App;