forked from deanmcpherson/react-native-sortable-listview
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.js
55 lines (49 loc) · 1.28 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
let SortableListView = require('./SortableListView');
let React = require('react-native');
let {
View,
Text,
TouchableHighlight
} = React;
let data = {
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 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'}} onLongPress={this.props.onLongPress}>
<Text>{this.props.data.text}</Text>
</TouchableHighlight>
}
})
let MyComponent = React.createClass({
render: function() {
return <SortableListView
style={{flex: 1}}
data={data}
order={order}
onRowMoved={e => {
order.splice(e.to, 0, order.splice(e.from, 1)[0]);
this.forceUpdate();
}}
renderRow={row => <RowComponent data={row} />}
/>
}
});
module.exports = MyComponent;