1.0.2 • Published 4 years ago

react-native-drag-flatlist v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

React Native Drag FlatList

Inspired by react-native-draggable-flatlist. No other dependencies. Support typescript.

Usage

Props

all props will be spread onto FlatList

NameTypeDescription
dataT[]items to be rendered
renderItem(params: { item: T; index: number; drag: () => void; }) => React.ReactElementwhen need to drag the item, call drag method
keyExtractor(item: T, index: number) => stringto get unique key
onMoveEnd(data: T[]) => voidcalled when drag end, return the updated data
horizontalbooleanorientation of list
autoscrollThresholdnumberdistance from edge of container where list begins to autoscroll when dragging. default 0.05

Example

import React, { useState } from "react";
import { Text, TouchableOpacity, StyleSheet } from "react-native";

import FlatList from "react-native-drag-flatlist";

const colors = ["#d3f261", "#7cb305", "#5b8c00", "#3f6600", "#254000"];

const originalData = new Array(100).fill(0).map((item, index) => ({
  text: index,
  color: colors[index % colors.length]
}));

const App = () => {
  const [data, setData] = useState(originalData);

  const keyExtractor = item => item.text.toString();

  const renderItem = ({ item, drag }) => (
    <TouchableOpacity
      style={[styles.item, { backgroundColor: item.color }]}
      onLongPress={drag}
    >
      <Text>{item.text}</Text>
    </TouchableOpacity>
  );

  return (
    <FlatList
      data={data}
      keyExtractor={keyExtractor}
      renderItem={renderItem}
      onMoveEnd={setData}
    />
  );
};

const styles = StyleSheet.create({
  item: {
    justifyContent: "center",
    alignItems: "center",
    width: 100,
    height: 100
  }
});

export default App;
1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago