jemise111 / react-native-swipe-list-view

A React Native ListView component with rows that swipe open and closed
https://www.npmjs.com/package/react-native-swipe-list-view
MIT License
2.78k stars 528 forks source link

onRightAction gets called with a delay. #594

Open JorensM opened 2 years ago

JorensM commented 2 years ago

Hello, I have problem. I put a function into the onRightAction prop. The problem is that it gets called with about 1-2 second delay. I'd like for it to be called instantly as soon as the action occurs.

edurib17 commented 2 years ago

Hello, I have problem. I put a function into the onRightAction prop. The problem is that it gets called with about 1-2 second delay. I'd like for it to be called instantly as soon as the action occurs.

Hello, I have the same problem, did you manage to solve it?

numsu commented 2 years ago

Stumbled upon the same issue. For the time being I went with a temporary solution:

onSwipeRightAction = (data) => {
    this.isRightSwipeActivated = data.isActivated;
    if (data.isActivated) {
        this.activatedKey = data.key;
    } else {
        this.activatedKey = undefined;
    }
}

onSwipeTouchEnd = () => {
    if (this.isRightSwipeActivated) {
        // do something with this.activatedKey
    }
}

...

<SwipeListView
    ...
    onRightActionStatusChange={data => this.onSwipeRightAction(data)}
    onTouchEnd={() => this.onSwipeTouchEnd()} />
vanso-hubsi commented 2 years ago

Hi! I just came across the same issue.

The issue is that the onRightAction only gets called after the swipeout animation has finished (see here and here). That animation being a 'spring' type animation actually takes some time to finish "bouncing" off-screen, thus the delay.

I solved this by sticking to the method used in the example, which is to "listen" on the onSwipeValueChange, check if the row has been swiped off-screen (±value > ±screenwidth), and if so execute my rightAction. This way it will be executed right after the row has gone invisible. (make sure to have something like animationIsRunning in place, as onSwipeValueChange gets still called on every tiny move during the invisible animation)