meliorence / meliorence/react-native-snap-carousel
Calling carouselRef.current.snapToItem() invoke carousel onSnapToItem twice for Android
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.5k
- Forks
- 2.3k
- PR merge metrics
- No merged PRs in 30d
Description
For my particular case I need to go back to the previous slide if not all fields is filled. So I used carousel onSnapToItem callback to listen to the swipe events. But if I need to go back I call carouselRef.current.snapToItem(invalidFieldSlideIndex), but this cause onSnapToItem to call twice first time with correct index and second with bad index.
So for example I have 3 slides. Swiping from the first slide and then back I will get on onSnapToItem called three times with the following values:
1 // active slide index (swipe)
0 // active slide index (programmatically call carouselRef.current.snapToItem(0))
1 // active slide index (called from _onMomentumScrollEnd function passed to the ScrollViewComponent)
For iOS it is working perfectly well.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing snapToItem, onSnapToItem, and the _onMomentumScrollEnd callback through the Android ScrollViewComponent path. Reproduce the three-slide sequence on Android and compare it with iOS. Done means a programmatic snap does not produce the extra callback with the wrong index, while swipe behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react-native
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100