React-native-snap-carousel: Loop and firstItem parameters doesn't work together

Created on 9 Oct 2018  路  9Comments  路  Source: meliorence/react-native-snap-carousel

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

Bug Report

Have you followed the required steps before opening a bug report?

(Check the step you've followed - replace the space character between the square brackets ([]) by an x.)

Have you made sure that it wasn't a React Native bug?

It seems to be an plugin implementation bug.

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

Both Platforms

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

Both environments

Environment

"react": "16.5.0",
"react-native": "0.57.1",
"react-native-snap-carousel": "3.7.5",

Using scrollview implementation or flatlist

Expected Behavior

The first banner to appear in the screen must be the one at the index 0 or any configured with firstItem parameter.

Actual Behavior

Carousel starts showing the central banner of the array and ignores any argument used in firstItem parameter.

Sample Code

<Carousel
                              data={this.state.bannerList}
                              renderItem={({item, index}) => {
                                  return (<BannerCarrouselItem item={item}/>)
                              }}
                              sliderWidth={this.windowWidth}
                              itemWidth={this.windowWidth}
                              inactiveSlideOpacity={1}
                              inactiveSlideScale={1}
                              useScrollView={true}
                              loop={true} />

https://snack.expo.io/@calindratech/carousel-loop-vs-firstitem

Steps to Reproduce

The first render of the component is already enough to reproduce this behaviour.

reproduction?

Most helpful comment

+1, when set loop = true, first item rendered incorrect!

All 9 comments

@zupodaniel Can you please provide a Snack example in which the issue can be reproduced?

Of course, I thought it was too simple to make a snack.

https://snack.expo.io/@calindratech/carousel-loop-vs-firstitem

@zupodaniel I'm not sure that I've properly understood the issue at stake.

I've tried to reproduce it, but I don't see any conflict between the loop and firstItem props.

The default firstItem is equal to 0 and in the snack I sent to you is possible to see that the first image to open is the 3rd

@zupodaniel The problem has nothing to do with the plugin. You used this.windowWidth for props sliderWidth and itemWidth while never defining it.

Here is a working example with a proper value set: https://snack.expo.io/BJtCR0hq7

Still, there is apparently another issue with your example since the snap effect doesn't occur...

I understand your point, these vars was only in my production code and I made a mistake creating the snack. My real code does not have this undefined. ASAP I'll check and create another proper example of the problem.

I noticed that the error is occurring when I call a setState to update the data used as input of the carousel. My bannerList is generated by a http request to a server.

I made changes to the first snack using your sample and included a timeout simulating the change of state by http.

When I use the real data directly in the constructor the carousel opens at the correct position.

https://snack.expo.io/@calindratech/carousel-loop-vs-firstitem

This stills seems to not work.

+1, when set loop = true, first item rendered incorrect!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

niloufarMakhzani picture niloufarMakhzani  路  4Comments

radiosilence picture radiosilence  路  4Comments

SnowDang picture SnowDang  路  4Comments

KarlosQ picture KarlosQ  路  4Comments

duongkhoilinh picture duongkhoilinh  路  4Comments