forked from deanmcpherson/react-native-sortable-listview
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.js
63 lines (58 loc) · 1.38 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
let SortableListView = require('./index')
let React = require('react')
let { View, Text, TouchableHighlight } = require('react-native')
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
class RowComponent extends React.Component {
render() {
return (
<TouchableHighlight
underlayColor={'#eee'}
style={{
padding: 25,
backgroundColor: '#F8F8F8',
borderBottomWidth: 1,
borderColor: '#eee',
}}
{...this.props.sortHandlers}
>
<Text>{this.props.data.text}</Text>
</TouchableHighlight>
)
}
}
class MyComponent extends React.Component {
render() {
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} />}
/>
)
}
}
export default MyComponent