react-native-snap-carousel icon indicating copy to clipboard operation
react-native-snap-carousel copied to clipboard

[BUG] carousel not showing correct first item

Open Arshit257 opened this issue 2 years ago • 5 comments

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

Yes, 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?

Yes

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

This is specific to both the platforms

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

Yes

Environment

Environment: React: 16.13.1 React native: 0.63.2 react-native-snap-carousel: 3.9.1

Target Platform: Android (12.0) iOS (15.5)

Expected Behavior

When using the carousel with enabling loop, and setting loopClonesPerSide to 1, the initial first item shown in expected to be the first item of data. Screenshot 2022-08-17 at 12 30 30 PM

Actual Behavior

When component renders for the first time it is not showing the first item of the data prop. Screenshot 2022-08-17 at 12 27 41 PM

Here I am passing exactly 2 item to each carousel. I want to show the first item first and then second item as per the image in the expected behaviour.

I tried setting firstItem to 0, 1, 2 but in all the case it is not working as expected.

Reproducible Demo

Carousel implementation:

<Carousel
  ref={carouselRef}
  data={carouselItemList}
  loop={true}
  loopClonesPerSide={1}
  enableSnap={true}
  renderItem={renderItem}
  scrollEnabled={false}
  onSnapToItem={handleOnSnapToItem}
/>

Steps to Reproduce

  1. Implement the carousel as I mentioned above.
  2. Give it exactly array of 2 items.

Arshit257 avatar Aug 17 '22 07:08 Arshit257

Hi, I have the same issue, i resolve this in use loopClonesPerSide={data.length} and firstItem={-data.length}

purrseus avatar Aug 29 '22 04:08 purrseus

thiendo261

Quickfix, but mostly not practicable because of the performance

cgo123 avatar Sep 06 '22 16:09 cgo123

first load your data models and then render the <Carousel .... firstItem={x} /> also the first Item number should be updated as well.

you can load it in a useEffect and then pass it to Carousel data and you can see it will work.

if you need more information I can provide a sample for you.

Salman-Samian avatar Sep 14 '22 17:09 Salman-Samian

try using useScrollView

p-schlickmann avatar Jan 13 '23 18:01 p-schlickmann

The main reason this is happening is because when using FlatList to render the Carousel it only render item in batches with respect to initialNumToRender prop. So, if your firstItem value is greater than the initialNumToRender prop value, the Carousel won't be able to pick the correct firstItem up

try setting the initialNumToRender prop and ensuring useScrollView is false. initialNumToRender={Math.ceil(startIndex / 10) * 10} startIndex is a variable

Jokotoye18 avatar May 10 '23 08:05 Jokotoye18