kkemple/react-native-sideswipe

Offset is ignored on first render when currentIndex != 0

deadlinc opened this issue · 2 comments

When I set the currentIndex = 1, the offset is not applied until the sideswipe is interacted with. Setting the currentIndex = 0 works correctly.

First load (incorrect):
first-load

After Interaction (correct):
after-interaction

Thank you!

I also have this issue but on component mount the carousel often end up between two slides.
The only way I can prevent this, is by delaying the index init/update with a setTimeout of 10ms. That's not very elegant but internally SideSwipe seems to do a similar thing:
https://github.com/kkemple/react-native-sideswipe/blob/master/src/carousel.js#L91

I suspect the issue is coming from the FlatList offset being computed before the slides layout are fully resolved or something like that. Maybe there's a better workaround using onLayout.

I'm also having this issue, and haven't had luck avoiding it with a setTimeout