question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Swipeable: onSwipeableOpen, onSwipeableClose, onSwipeableRightOpen and onSwipeableLeftOpen callback taking to long, about 2 seconds.

See original GitHub issue

onSwipeableOpen, onSwipeableClose, onSwipeableRightOpen and onSwipeableLeftOpen callback taking to long, about 2 seconds.

Suggestion: in Swipeable.js after line 173 rowTranslation.setValue(fromValue);

Add:

let animatedListenerId = rowTranslation.addListener(({value}) => {
        let threshold = 0.1;
        if(Math.abs(value.toFixed()) >= (Math.abs(toValue.toFixed()) - Math.abs(toValue.toFixed()) * threshold)) {
            
            if (toValue > 0 && this.props.onSwipeableLeftOpen) {
                this.props.onSwipeableLeftOpen();
            } else if (toValue < 0 && this.props.onSwipeableRightOpen) {
                this.props.onSwipeableRightOpen();
            }
    
            if (toValue === 0) {
                this.props.onSwipeableClose && this.props.onSwipeableClose();
            } else {
                this.props.onSwipeableOpen && this.props.onSwipeableOpen();
            }

            rowTranslation.removeListener(animatedListenerId);
        }
    });

Change:

From:

Animated.spring(rowTranslation, {
      velocity: velocityX,
      bounciness: 0,
      toValue,
      useNativeDriver: this.props.useNativeAnimations,
    }).start(({ finished }) => {
      if (finished) {
        if (toValue > 0 && this.props.onSwipeableLeftOpen) {
          this.props.onSwipeableLeftOpen();
        } else if (toValue < 0 && this.props.onSwipeableRightOpen) {
          this.props.onSwipeableRightOpen();
        }

        if (toValue === 0) {
          this.props.onSwipeableClose && this.props.onSwipeableClose();
        } else {
          this.props.onSwipeableOpen && this.props.onSwipeableOpen();
        }
      }
    });

To:

Animated.spring(rowTranslation, {
      velocity: velocityX,
      bounciness: 0,
      toValue,
      useNativeDriver: this.props.useNativeAnimations,
    }).start();

Now I can close any opened row at real time…

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
osdnkcommented, May 4, 2018

https://github.com/kmagiera/react-native-gesture-handler/pull/164 @Blah2014 @ptmt @kmagiera What do you think about this solution? I didn’t wish to add any listeners to native animation as it’s not a way of using this library. It seems to be a hacky workaround. However, mind that Spring has some given duration. You may use onSwipeableLeftStartOpen and then set a timeout.

2reactions
kmagieracommented, Jan 6, 2018

Thanks @Blah2014 for reaching out.

If this issue is about code changes you suggest it would be much easier to discuss them if you decided to send a pull request instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swipeable: onSwipeableOpen, onSwipeableClose ... - GitHub
onSwipeableOpen, onSwipeableClose, onSwipeableRightOpen and onSwipeableLeftOpen callback taking to long, about 2 seconds. Suggestion: in Swipeable.js after ...
Read more >
Swipeable | React Native Gesture Handler - Software Mansion
onSwipeableOpen ​. method that is called when action panel gets open (either right or left). Takes swipe direction as an argument. onSwipeableClose ​....
Read more >
React native swipe-able from gesture handler showing ...
It is working, what I am not able to achieve is that if the user keeps swiping I want the one of the...
Read more >
React Native Gesture Handler: Swipe, long-press, and more
Implementing gestures in a React Native app improves the user experience. Learn how to create swipeable, pan, long-press, and other ...
Read more >
How to Create a Swipeable Component in React Native
First of all, install react native gesture handler using any of the ... onSwipeableRightOpen, onSwipeableOpen, onSwipeableClose etc.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found