Socket
Socket
Sign inDemoInstall

react-native-gesture-responder

Package Overview
Dependencies
1
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-native-gesture-responder

A more convenient and powerful gesture responder than the official PanResponder.


Version published
Weekly downloads
1.2K
increased by3.44%
Maintainers
1
Install size
45.8 kB
Created
Weekly downloads
 

Readme

Source

react-native-gesture-responder

A more convenient and powerful gesture responder than the official PanResponder.

Using this library, gestures are easy to detect:

  • scroll distance
  • pinch distance
  • single tap
  • double tab
  • single tap confirmed (not followed by a double tap)

Install

npm install --save react-native-gesture-responder@latest

Documentation

import {createResponder} from 'react-native-gesture-responder';
...
componentWillMount() {
  this.gestureResponder = createResponder({
    onStartShouldSetResponder: (evt, gestureState) => true,
    onStartShouldSetResponderCapture: (evt, gestureState) => true,
    onMoveShouldSetResponder: (evt, gestureState) => true,
    onMoveShouldSetResponderCapture: (evt, gestureState) => true,
    onResponderGrant: (evt, gestureState) => {},
    onResponderMove: (evt, gestureState) => {},
    onResponderTerminationRequest: (evt, gestureState) => true,
    onResponderRelease: (evt, gestureState) => {},
    onResponderTerminate: (evt, gestureState) => {},
    
    onResponderSingleTapConfirmed: (evt, gestureState) => {}
    
    moveThreshold: 2
    debug: false
  });
}

render() {
  
  return (
    <View
      {...this.gestureResponder}>
		...
    </View>
  );
}

The API is quite same with the official gesture responder system. Differences are:

  1. Every lifecycle callback is called with an additional argument gestureState, like the PanResponder.

  2. onResponderSingleTapConfirmed: called after a single tap (not a double tap).

  3. moveThreshold: default is 2. Use this to avoid too sensitive move events when simply tap the screen(mainly on Android).

  4. debug: a boolean value. If true, lifecycle logs will be printed.

The gestureState object has the following(a super set of PanResponder):

  • stateId
  • moveX and moveY
  • x0 and y0
  • dx and dy: accumulated distance of the gesture since the touch started(confusing names)
  • vx and vy: per millisec(PanResponder is inconsistant with different react-native version, as this issue mentioned)
  • numberActiveTouches
  • previousMoveX and previousMoveY: you can use moveX - previousMoveX to calculate latest move distance
  • pinch and previousPinch: useful number values when implementing zoom feature. Will be undefined if no pinch occured
  • singleTapUp: a bool value indicating if a single tap up occured
  • doubleTapUp: a bool value indicating if a double tap up occured

Refer to Demo folder for a simple demonstration, as below shows:

FAQs

Last updated on 21 Jul 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc