# react-native-drag-flatlist

> draggable FlatList of react-native

Latest version **1.0.2** (published 2020-05-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-drag-flatlist
pnpm add react-native-drag-flatlist
yarn add react-native-drag-flatlist
bun add react-native-drag-flatlist
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2020-05-18 |
| First published | 2019-12-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 36.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | ShengjieLu |
| Maintainers | clown_lsj |
| Keywords | react, react-native, FlatList, drag, sort |

## Links

- npm: https://www.npmjs.com/package/react-native-drag-flatlist
- Repository: https://github.com/JackClown/react-native-drag-flatlist
- Homepage: https://github.com/JackClown/react-native-drag-flatlist#readme
- Issues: https://github.com/JackClown/react-native-drag-flatlist/issues
- npm.io page: https://npm.io/package/react-native-drag-flatlist

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2020-05-18
- 1.0.1 — 2020-04-25
- 1.0.0 — 2019-12-15
- 0.0.3 — 2019-12-12
- 0.0.2 — 2019-12-11
- 0.0.1 — 2019-12-11

## README

# React Native Drag FlatList

Inspired by [react-native-draggable-flatlist](https://github.com/computerjazz/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<any> | 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

```javascript
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;
```

---
_Source: https://npm.io/package/react-native-drag-flatlist · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
