Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Fat Arrow Function #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 49 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,33 @@
# react-native-swipe-gestures

React Native component for handling swipe gestures in up, down, left and right direction.

## Installation

`npm i -S react-native-swipe-gestures`

## Usage

```javascript
'use strict';

import React, {Component} from 'react';
import {View, Text} from 'react-native';
import GestureRecognizer, {swipeDirections} from 'react-native-swipe-gestures';

class SomeComponent extends Component {
state = {
myText: "I'm ready to get swiped!",
gestureName: 'none',
backgroundColor: '#fff',
};

constructor(props) {
super(props);
this.state = {
myText: 'I\'m ready to get swiped!',
gestureName: 'none',
backgroundColor: '#fff'
};
}

onSwipeUp(gestureState) {
onSwipeUp = gestureState => {
this.setState({myText: 'You swiped up!'});
}
};

onSwipeDown(gestureState) {
onSwipeDown = gestureState => {
this.setState({myText: 'You swiped down!'});
}
};

onSwipeLeft(gestureState) {
onSwipeLeft = gestureState => {
this.setState({myText: 'You swiped left!'});
}
};

onSwipeRight(gestureState) {
onSwipeRight = gestureState => {
this.setState({myText: 'You swiped right!'});
}
};

onSwipe(gestureName, gestureState) {
onSwipe = (gestureName, gestureState) => {
const {SWIPE_UP, SWIPE_DOWN, SWIPE_LEFT, SWIPE_RIGHT} = swipeDirections;
this.setState({gestureName: gestureName});
switch (gestureName) {
Expand All @@ -59,13 +44,12 @@ class SomeComponent extends Component {
this.setState({backgroundColor: 'yellow'});
break;
}
}
};

render() {

const config = {
velocityThreshold: 0.3,
directionalOffsetThreshold: 80
directionalOffsetThreshold: 80,
};

return (
Expand All @@ -78,9 +62,8 @@ class SomeComponent extends Component {
config={config}
style={{
flex: 1,
backgroundColor: this.state.backgroundColor
}}
>
backgroundColor: this.state.backgroundColor,
}}>
<Text>{this.state.myText}</Text>
<Text>onSwipe callback received gesture: {this.state.gestureName}</Text>
</GestureRecognizer>
Expand All @@ -89,48 +72,50 @@ class SomeComponent extends Component {
}

export default SomeComponent;
```

## Config
```
## Config

Can be passed within optional `config` property.
Can be passed within optional `config` property.

| Params | Type | Default | Description |
| -------------------------- |:-------------:| ------- | ------------ |
| velocityThreshold | Number | 0.3 | Velocity that has to be breached in order for swipe to be triggered (`vx` and `vy` properties of `gestureState`) |
| directionalOffsetThreshold | Number | 80 | Absolute offset that shouldn't be breached for swipe to be triggered (`dy` for horizontal swipe, `dx` for vertical swipe) |
| gestureIsClickThreshold | Number | 5 | Absolute distance that should be breached for the gesture to not be considered a click (`dx` or `dy` properties of `gestureState`) |
| Params | Type | Default | Description |
| -------------------------- |:-------------:| ------- | ------------ |
| velocityThreshold | Number | 0.3 | Velocity that has to be breached in order for swipe to be triggered (`vx` and `vy` properties of `gestureState`) |
| directionalOffsetThreshold | Number | 80 | Absolute offset that shouldn't be breached for swipe to be triggered (`dy` for horizontal swipe, `dx` for vertical swipe) |
| gestureIsClickThreshold | Number | 5 | Absolute distance that should be breached for the gesture to not be considered a click (`dx` or `dy` properties of `gestureState`) |

## Methods
## Methods

#### onSwipe(gestureName, gestureState)
#### onSwipe(gestureName, gestureState)

| Params | Type | Description |
| ------------- |:-------------:| ------------ |
| gestureName | String | Name of the gesture (look example above) |
| gestureState | Object | gestureState received from PanResponder |
| Params | Type | Description |
| ------------- |:-------------:| ------------ |
| gestureName | String | Name of the gesture (look example above) |
| gestureState | Object | gestureState received from PanResponder |


#### onSwipeUp(gestureState)
#### onSwipeUp(gestureState)

| Params | Type | Description |
| ------------- |:-------------:| ------------ |
| gestureState | Object | gestureState received from PanResponder |
| Params | Type | Description |
| ------------- |:-------------:| ------------ |
| gestureState | Object | gestureState received from PanResponder |

#### onSwipeDown(gestureState)
#### onSwipeDown(gestureState)

| Params | Type | Description |
| ------------- |:-------------:| ------------ |
| gestureState | Object | gestureState received from PanResponder |
| Params | Type | Description |
| ------------- |:-------------:| ------------ |
| gestureState | Object | gestureState received from PanResponder |

#### onSwipeLeft(gestureState)
#### onSwipeLeft(gestureState)

| Params | Type | Description |
| ------------- |:-------------:| ------------ |
| gestureState | Object | gestureState received from PanResponder |
| Params | Type | Description |
| ------------- |:-------------:| ------------ |
| gestureState | Object | gestureState received from PanResponder |

#### onSwipeRight(gestureState)
#### onSwipeRight(gestureState)

| Params | Type | Description |
| ------------- |:-------------:| ------------ |
| Params | Type | Description |
| ------------- |:-------------:| ------------ |
| gestureState | Object | gestureState received from PanResponder |

```