marekrozmus / react-swipeable-list

Swipeable list component for React supporting several behaviours (e.g. iOS)
https://marekrozmus.github.io/react-swipeable-list/
MIT License
110 stars 20 forks source link

Allow for swiping right even if a leading action does not exist #2

Closed alaycock closed 3 years ago

alaycock commented 3 years ago

In cases where only "trailing" actions exist for an item, it appears that the item can be put into such a state that the trailing action cannot be closed. I have some trouble reproducing this state, since logging or using a debugger affects the timing of it, preventing the bug from occurring, but I attached a video of the issue occurring below. The bug first appears at 12 seconds.

When swiping right to close an item, it often still has the dragDirection value of 3 (left), since that is what was used to open the element, this is likely incorrect, but produces the correct result. In the case where the bug appears, the dragDirection is changed to 5 (unknown), because it cannot be set to 4 (right), because no leadingActionsElement exists. While this PR doesn't resolve the problem of the dragDirection incorrectly being set to left, it allows the dragDirection to be right, even without a leading element, which allows the item to close the action.

I'm not entirely sure what effect this has on all other use cases, so maybe you can provide some insight into why these conditions exist in the first place. If this isn't an appropriate fix, let me know if you have a better recommendation for a fix.

https://user-images.githubusercontent.com/894797/110275879-30c1f300-7f8f-11eb-8297-af3bbbc87462.mov

marekrozmus commented 3 years ago

Hi :) Great catch 🥇

After "some time" ;) debugging I've found that if you swipe quite fast sometimes updatePosition is called after dragEnd event. That breaks state of trailingActionsOpened and that is why dragStart does not work anymore.

What we are missing here is cancelling animation frame on dragEnd so that no more updatePosition is called.

Will fix it in and make new release. Thanks again.

alaycock commented 3 years ago

Thanks @marekrozmus! This didn't seem like the right fix, even if it achieved the correct result, so I'm glad you tracked this down. Looking forward to the latest version.

marekrozmus commented 3 years ago

@all-contributors please add @alaycock for bug

allcontributors[bot] commented 3 years ago

@marekrozmus

I've put up a pull request to add @alaycock! :tada:

marekrozmus commented 3 years ago

@alaycock - new version is published. Thanks again and enjoy 🎉