Skip to content

Commit f8227d7

Browse files
authored
Update README.md
1 parent 21c89b1 commit f8227d7

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

README.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,48 @@ All props are spread onto underlying [FlatList](https://facebook.github.io/react
5555
| `containerStyle` | `StyleProp<ViewStyle>` | Style of the main component. |
5656

5757
## Example
58-
58+
Example snack: https://snack.expo.io/@computerjazz/rndfl-example
5959
Example snack with scale effect on hover: https://snack.expo.io/@computerjazz/rndfl-dragwithhovereffect
6060

61-
```javascript
61+
```typescript
6262
import React, { Component } from "react";
6363
import { View, TouchableOpacity, Text } from "react-native";
64-
import DraggableFlatList from "react-native-draggable-flatlist";
64+
import DraggableFlatList, { RenderItemParams } from "react-native-draggable-flatlist";
65+
66+
const NUM_ITEMS = 10
67+
68+
function getColor(i: number) {
69+
const multiplier = 255 / (NUM_ITEMS - 1);
70+
const colorVal = i * multiplier;
71+
return `rgb(${colorVal}, ${Math.abs(128 - colorVal)}, ${255 - colorVal})`;
72+
}
6573

66-
const exampleData = [...Array(20)].map((d, index) => ({
67-
key: `item-${index}`, // For example only -- don't use index as your key!
68-
label: index,
69-
backgroundColor: `rgb(${Math.floor(Math.random() * 255)}, ${index *
70-
5}, ${132})`
71-
}));
74+
type Item = {
75+
key: string;
76+
label: string;
77+
backgroundColor: string;
78+
}
79+
80+
const exampleData: Item[] = [...Array(20)].map((d, index) => {
81+
const backgroundColor = getColor(index)
82+
return {
83+
key: `item-${backgroundColor}`,
84+
label: String(index),
85+
backgroundColor,
86+
}
87+
});
7288

7389
class Example extends Component {
7490
state = {
7591
data: exampleData
7692
};
7793

78-
renderItem = ({ item, index, drag, isActive }) => {
94+
renderItem = ({ item, index, drag, isActive }: RenderItemParams<Item>) => {
7995
return (
8096
<TouchableOpacity
8197
style={{
8298
height: 100,
83-
backgroundColor: isActive ? "blue" : item.backgroundColor,
99+
backgroundColor: isActive ? "red" : item.backgroundColor,
84100
alignItems: "center",
85101
justifyContent: "center"
86102
}}

0 commit comments

Comments
 (0)