meliorence / meliorence/react-native-snap-carousel

Prepending items to the data prop changes firstItem

Open
#522 5 comments 2 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

Is this a bug report, a feature request, or a question?

Question and/or a bug report.

Have you followed the required steps before opening a bug report?
Have you made sure that it wasn't a React Native bug?

I believe so.

Is the bug specific to iOS or Android? Or can it be reproduced on both platforms?

Only testing in iOS at the moment

Is the bug reproductible in a production environment (not a debug one)?

Have not tried in production.

Environment
React: 16.8.3
React native: 0.59.5
react-native-snap-carousel: 3.7.5
Expected Behavior

For performance with a large data list I am basically doing what is described in this issue: https://github.com/archriss/react-native-snap-carousel/issues/384

I am managing a smaller list specifically for in the data prop. I am handling infinite scrolling/pagination manually by detecting the start and end indexes in onBeforeSnapToItem. I want to be able to land in the middle of a list of items and as I swipe right AND left, new items will be loaded into the list in regards to the direction I was swiping (prepending or appending)

Actual Behavior

It works fine for when you are swiping forward (or 'right') and you reach the end. I append the new items in the list and everything is okay.

The issue is when you swipe backwards (or left) and load some more data. I prepend the data to the list and the firstItem is completely lost and the carousel renders the very first item in the list, which is incorrect. The firstItem prop should remain unchanged when prepending data to the list.

Reproducible Demo

I will provide a reproducible demo if needed. I wanted to ask to see if you knew a quick solution or if this was a limitation of FlatList.

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 with the Carousel data, firstItem, and onBeforeSnapToItem behavior described in the report, then inspect how the underlying FlatList responds when items are prepended. Reproduce the case on iOS with react-native-snap-carousel 3.7.5, beginning from a middle item and loading items while swiping backward. Done means the carousel preserves the selected firstItem after prepending while existing forward pagination still works.

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
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.