meliorence / meliorence/react-native-snap-carousel

Strange behaviour when loop is enabled and data is dynamic!

Open
#469 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

reproduction?
Dominant language
JavaScript
Stars
10.5k
Forks
2.3k
PR merge metrics
No merged PRs in 30d

Description

Bug report (iOS)

criteria :
data is dynamic (like I got an initial length of 1, but the length gonna be change to 5 after 1 sec), and the loop is on.

behaviour:
after the number of rendered images changes, the carousel (gonna scrollTo) gonna render the last image, then the first again. (like it's not sure what to do).

possible workaround:
adding a key={data.length} to the Carousel, but of course that gonna destroy, and remount the component what is heavy and cause flickering.

<Carousel
   loop
   data={urls}
   renderItem={this._renderItem}
   slideStyle={{ width: viewportWidth }}
   sliderWidth={viewportWidth}
   itemWidth={viewportWidth}
   inactiveSlideOpacity={1}
   inactiveSlideScale={1}
   onSnapToItem={this.onSnapToItem}
   activeSlideAlignment="center"
/>

Environment:
React: 16.7
React native: 0.57.4
react-native-snap-carousel: 3.7.5

Target Platform:
iOS (12.1)

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 reproducing the issue on iOS with react-native-snap-carousel 3.7.5, using loop=true and data that grows from one item to five after a delay. Inspect the carousel's loop and item-index handling for dynamic data. Done means the carousel updates without rendering the last item followed by the first, and without requiring a remount via key={data.length}.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.