meliorence / meliorence/react-native-snap-carousel

Calling carouselRef.current.snapToItem() invoke carousel onSnapToItem twice for Android

Open
#893 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.