react-native-swipe-gestures icon indicating copy to clipboard operation
react-native-swipe-gestures copied to clipboard

GestureRecognizer slow down app

Open divsbhalala opened this issue 7 years ago • 12 comments

when GestureRecognizer in a list of item array it slow down scrolling <GestureRecognizer> <View> .... . . . . . . . </GestureRecognizer>

divsbhalala avatar Oct 18 '17 10:10 divsbhalala

same here, scrollview inside GestureRecognizer is hard to scroll need the ability to disable vertical swipe or horizontal swipe separately

ptquang86 avatar Nov 06 '17 06:11 ptquang86

I am experiencing same problems as I am not using the up / down gestures. You guys will find your scroll up/down has been moved to 2 fingers as a result of GestureRecognizer being used.

flikQ avatar Nov 07 '17 16:11 flikQ

You can use this lib: https://github.com/blackstar217/react-native-swipe-gestures I fixed this issue.

trustme217 avatar Mar 04 '18 02:03 trustme217

The same problem here. Who does solve this bug?

DavitVosk avatar Mar 11 '18 11:03 DavitVosk

@blackstar217 does your fork work for ScrollView? When I use GestureRecognizer, my scrolling becomes very and very slow.

DavitVosk avatar Mar 11 '18 14:03 DavitVosk

Did you fix?

ivangainutsa21 avatar Mar 22 '18 03:03 ivangainutsa21

@sergeyunz21 Nope. But handled what I want with Animated. You can have a look here: https://medium.com/appandflow/react-native-collapsible-navbar-e51a049b560a

DavitVosk avatar Mar 22 '18 03:03 DavitVosk

Try to put GestureRecognizer components into each list item. If there is no empty space on the screen except the list, it will work.

ghost avatar May 10 '18 16:05 ghost

any solution here? or other package please

luongs3 avatar Sep 18 '18 11:09 luongs3

I've solved this issue by editing the lib file(like that) in order not to recognize swipes up and down. ScrollView now works as fast as it should be.

'use strict';

import React, {Component} from 'react';
import {View, PanResponder} from 'react-native';

export const swipeDirections = {
  SWIPE_LEFT: 'SWIPE_LEFT',
  SWIPE_RIGHT: 'SWIPE_RIGHT'
};

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

function isValidSwipe(velocity, velocityThreshold, directionalOffset, directionalOffsetThreshold) {
  return Math.abs(velocity) > velocityThreshold && Math.abs(directionalOffset) < directionalOffsetThreshold;
}

class GestureRecognizer extends Component {

  constructor(props, context) {
    super(props, context);
    this.swipeConfig = Object.assign(swipeConfig, props.config);
  }

  componentWillReceiveProps(props) {
    this.swipeConfig = Object.assign(swipeConfig, props.config);
  }

  componentWillMount() {
    const responderEnd = this._handlePanResponderEnd.bind(this);
    const shouldSetResponder = this._handleShouldSetPanResponder.bind(this);
    this._panResponder = PanResponder.create({ //stop JS beautify collapse
      onStartShouldSetPanResponder: shouldSetResponder,
      onMoveShouldSetPanResponder: shouldSetResponder,
      onPanResponderRelease: responderEnd,
      onPanResponderTerminate: responderEnd
    });
  }

  _handleShouldSetPanResponder(evt, gestureState) {
    return evt.nativeEvent.touches.length === 1 && !this._gestureIsClick(gestureState);
  }
  
  _gestureIsClick(gestureState) {
    return Math.abs(gestureState.dx) < 5;
  }

  _handlePanResponderEnd(evt, gestureState) {
    const swipeDirection = this._getSwipeDirection(gestureState);
    this._triggerSwipeHandlers(swipeDirection, gestureState);
  }

  _triggerSwipeHandlers(swipeDirection, gestureState) {
    const {onSwipe, onSwipeLeft, onSwipeRight} = this.props;
    const {SWIPE_LEFT, SWIPE_RIGHT,} = swipeDirections;
    onSwipe && onSwipe(swipeDirection, gestureState);
    switch (swipeDirection) {
      case SWIPE_LEFT:
        onSwipeLeft && onSwipeLeft(gestureState);
        break;
      case SWIPE_RIGHT:
        onSwipeRight && onSwipeRight(gestureState);
        break;
    }
  }

  _getSwipeDirection(gestureState) {
    const {SWIPE_LEFT, SWIPE_RIGHT} = swipeDirections;
    const {dx} = gestureState;
    if (this._isValidHorizontalSwipe(gestureState)) {
      return (dx > 0)
        ? SWIPE_RIGHT
        : SWIPE_LEFT;
    } 
    return null;
  }

  _isValidHorizontalSwipe(gestureState) {
    const {vx, dy} = gestureState;
    const {velocityThreshold, directionalOffsetThreshold} = this.swipeConfig;
    return isValidSwipe(vx, velocityThreshold, dy, directionalOffsetThreshold);
  }

  _isValidVerticalSwipe(gestureState) {
    const {vy, dx} = gestureState;
    const {velocityThreshold, directionalOffsetThreshold} = this.swipeConfig;
    return isValidSwipe(vy, velocityThreshold, dx, directionalOffsetThreshold);
  }

  render() {
    return (<View {...this.props} {...this._panResponder.panHandlers}/>);
  }
};

export default GestureRecognizer;

miralinochka avatar Nov 05 '18 12:11 miralinochka

@alya98 Thanks.It's working perfect.

abdulrahman18 avatar Mar 12 '19 09:03 abdulrahman18

Still getting stuck sometimes when scroll vertical.

Achilles718611 avatar Jun 24 '19 17:06 Achilles718611