forked from deanmcpherson/react-native-sortable-listview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
122 lines (112 loc) · 2.37 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
let SortableListView = require('react-native-sortable-listview');
let React = require('react');
let {
StyleSheet,
Text,
TouchableHighlight,
View,
} = require('react-native');
let list1 = {
hello: {text: 'world'},
how: {text: 'are you'},
test: {text: 123},
this: {text: 'is'},
a: {text: 'a'},
real: {text: 'real'},
drag: {text: 'drag and drop'},
bb: {text: 'bb'},
cc: {text: 'cc'},
dd: {text: 'dd'},
ee: {text: 'ee'},
ff: {text: 'ff'},
gg: {text: 'gg'},
hh: {text: 'hh'},
ii: {text: 'ii'},
jj: {text: 'jj'},
kk: {text: 'kk'}
}
let shortlist = {
hello: {text: 'world'},
how: {text: 'are you'},
test: {text: 123},
this: {text: 'is'},
}
let list3 = {
hello: 'world',
how: 'are you',
test: 123,
these: 'is',
a: 'a',
real: 'real',
drag: 'drag and drop',
bb: 'bb',
cc: 'cc',
dd: 'dd',
ee: 'ee',
ff: 'ff',
gg: 'gg',
hh: 'hh',
ii: 'ii',
jj: 'jj',
kk: 'kk'
}
let list4 = {
v0: 0,
v1: 1,
v2: 2,
v3: 3,
v4: 4,
v5: 5,
v6: 6,
v7: 7,
v8: 8,
v9: 9,
v10: 10,
v11: 11,
v12: 12,
v13: 13,
v14: 14,
v15: 15,
v16: 16,
}
let data = list3;
let order = Object.keys(data); //Array of keys
let RowComponent = React.createClass({
render: function() {
return <TouchableHighlight underlayColor={'#eee'} style={{padding: 25, backgroundColor: "#F8F8F8", borderBottomWidth:1, borderColor: '#eee'}} {...this.props.sortHandlers}>
<Text style={{fontSize: 20}}>{data === list3 || data === list4? this.props.data: this.props.data.text}</Text>
</TouchableHighlight>
}
})
let MyComponent = React.createClass({
render: function() {
return (
<View style={styles.container}>
<View style={{height: 64, backgroundColor: 'lightblue'} /* fake nav bar */} >
<Text style={styles.welcome} > Sortable </Text>
</View>
<SortableListView
style={{flex: 1, marginBottom: 0}}
data={data}
order={order}
onRowMoved={e => {
order.splice(e.to, 0, order.splice(e.from, 1)[0]);
this.forceUpdate();
}}
renderRow={row => <RowComponent data={row} />}
/>
</View> );
}
});
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
});
module.exports = MyComponent;