Giter Site home page Giter Site logo

jqn / react-native-simple-gesture Goto Github PK

View Code? Open in Web Editor NEW

This project forked from christopherabouabdo/react-native-simple-gesture

0.0 1.0 0.0 5 KB

Wrapper for React Native gestureState that provides information about the type of gesture using a simple plain english API

License: MIT License

JavaScript 100.00%

react-native-simple-gesture's Introduction

react-native-simple-gesture

Wrapper for React Native gestureState that provides information about the type of gesture using a simple plain english API

Install

npm install react-native-simple-gesture --save

Write Code

import React from 'react-native';
import SimpleGesture from 'react-native-simple-gesture';
let { PanResponder, View, Text } = React;

class SuperAwesomeComponent extends React.Component {

  componentWillMount() {
    this._panResponder = PanResponder.create({
      // Only respond to movements if the gesture is a swipe up
      onMoveShouldSetPanResponder: (e, gs) => {
        let sgs = new SimpleGesture(e,gs);
        return sgs.isSwipeUp();
      }
    });
  }

  render() {
    return(
      <View { ...this._panResponder.panHandlers }>
        <Text>I'm gonna respond to swipes that go up</Text>
      </View>
    )
  }

}

What You Can Do

Relative Gesture Distance

Get the gesture distance relative to device screen size

let sgs = new SimpleGesture(e, gs);
console.log('Swiped ', sgs.relativeGestureDistance.x*100, '% of the screen horizontally');
console.log('Swiped ', sgs.relativeGestureDistance.y*100, '% of the screen vertically');

So far I've only written swipe tests. Gestures beyond swipes are next.

Vertical Gesture Tests

  • isVertical()
  • isSimpleSwipeUp()
  • isSwipeUp()
  • isLongSwipeUp()
  • isFastSwipeUp()
  • isMovingUp()
  • isSimpleSwipeDown()
  • isSwipeDown()
  • isLongSwipeDown()
  • isFastSwipeDown()
  • isMovingDown()

Horizontal Gesture Tests

  • isHorizontal()
  • isSimpleSwipeLeft()
  • isSwipeLeft()
  • isLongSwipeLeft()
  • isFastSwipeLeft()
  • isMovingLeft()
  • isSimpleSwipeRight()
  • isSwipeRight()
  • isLongSwipeRight()
  • isFastSwipeRight()
  • isMovingRight()

react-native-simple-gesture's People

Contributors

christopherabouabdo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.