# react-native-drag

> A wrapper makes components draggable.

Latest version **1.0.2** (published 2018-05-16) · MIT license · 0 weekly downloads

## Install

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

## 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 | 2018-05-16 |
| First published | 2018-05-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | ShizukuIchi |
| Maintainers | shizuku |
| Keywords | react-native, draggable, drag, drop |

## Links

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

## Dependencies (1)

- [prop-types](https://npm.io/package/prop-types.md) ^15.6.1

## Recent versions

- 1.0.2 (latest) — 2018-05-16
- 1.0.1 — 2018-05-16
- 1.0.0 — 2018-05-16

## README

React Native Drag
===

A components wrapper makes them draggable.

## Usage

Install library via `npm`

```
npm install react-native-drag
```
To make components draggable, simply wrap them in a `Draggable` component.

```jsx
import Draggable from 'react-native-drag';

<Draggable 
  setRef={this.setRef} 
  containerStyle={styles.draggable} 
  onDragStart={this.handlePressIn} 
  onDragRelease={this.handlePressOut}
  onLongPress={this.handleLongPress} 
  longPressTimeout={500} 
>
  <View>
    <Text>Hello World!</Text>
  </View>
</Draggable>
```

## API

### Properties
| Porperty | Description | Type | Default |
| -------- | -------- | -------- | -- |
| containerStyle | specify style for the wrapper | number, object | -- |
| longPressTimeout | specify timeout to invoke `onLongPress`  | number | 500 |

### Callback
| Event | Description | Type | Parameters |
| -------- | -------- | -------- | -- |
| onDragStart | invoke when press in | func | none |
| onDragRelease | invoke when press out and with the latest screen coordinates of the recently-moved touch | func | (lastX, lastY) |
| onLongPress | invoke after a specified `longPressTimeout` | func | none

### Get Component Reference

Use a `setRef` function to get the draggable component's ref.  
All props send to `Draggable` will also send to the wrapper `View` component.

```jsx
class Demo extends React.Component {
  setRef = (r) => {
    this.myDraggable = r;
    console.log(this.myDraggble.props.id) // 123
  }
  render() {
    return (
      <Draggable id={123} setRef={this.setRef}>
        <View />
      </Draggable>
    )
  }
}
```

## Demo

Codes in `example/Demo.js`

![demo](demo/demo.gif)

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