React Native Drag FlatList
Inspired by react-native-draggable-flatlist. No other dependencies. Support typescript.
Usage
Props
all props will be spread onto FlatList
Name | Type | Description |
---|---|---|
data | T[] | items to be rendered |
renderItem | (params: { item: T; index: number; drag: () => void; }) => React.ReactElement | when need to drag the item, call drag method |
keyExtractor | (item: T, index: number) => string | to get unique key |
onMoveEnd | (data: T[]) => void | called when drag end, return the updated data |
horizontal | boolean | orientation of list |
autoscrollThreshold | number | distance from edge of container where list begins to autoscroll when dragging. default 0.05 |
Example
;; ; const colors = "#d3f261" "#7cb305" "#5b8c00" "#3f6600" "#254000"; const originalData = 100; const App = { const data setData = ; const keyExtractor = itemtext; const renderItem = <TouchableOpacity style=stylesitem backgroundColor: itemcolor onLongPress=drag > <Text>itemtext</Text> </TouchableOpacity> ; return <FlatList data=data keyExtractor=keyExtractor renderItem=renderItem onMoveEnd=setData /> ;}; const styles = StyleSheet; ;