Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
computerjazz committed Jul 16, 2018
1 parent c8226f0 commit be4afb7
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions README.md
Expand Up @@ -31,17 +31,30 @@ import DraggableFlatList from 'react-native-draggable-flatlist'
class Example extends Component {

state = {
data: [0, 1, 2, 3, 4, 5]
data: [...Array(20)].map((d, index) => ({
key: `item-${index}`,
label: index,
backgroundColor: `rgb(${Math.floor(Math.random() * 255)}, ${index * 5}, ${132})`,
}))
}

renderItem = ({ item, index, move, moveEnd, isActive }) => {
return (
<TouchableOpacity
style={{ height: 100, backgroundColor: isActive ? 'red' : 'blue' }}
style={{
height: 100,
backgroundColor: isActive ? 'blue' : item.backgroundColor,
alignItems: 'center',
justifyContent: 'center'
}}
onLongPress={move}
onPressOut={moveEnd}
>
<Text>{item}</Text>
<Text style={{
fontWeight: 'bold',
color: 'white',
fontSize: 32,
}}>{item.label}</Text>
</TouchableOpacity>
)
}
Expand All @@ -52,8 +65,7 @@ class Example extends Component {
<DraggableFlatList
data={this.state.data}
renderItem={this.renderItem}
keyExtractor={(item, index) => `draggable-item-${item}`}
contentContainerStyle={{ padding: 10 }}
keyExtractor={(item, index) => `draggable-item-${item.key}`}
scrollPercent={5}
onMoveEnd={({ data }) => this.setState({ data })}
/>
Expand All @@ -63,7 +75,5 @@ class Example extends Component {
}

export default Example


```

0 comments on commit be4afb7

Please sign in to comment.