question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

firstItem doesn't work reliably

See original GitHub issue

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 - put an x character between the square brackets ([]).)

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?

It’s reproducible on both platforms but has slightly different behaviour on each. On iOS index 14 is shown, on Android, index 6 is shown, when firstItem is 30.

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

Yes

Environment

Here’s a snack which reproduces the behaviour: https://snack.expo.io/@thekevinbrown/snap-carousel-first-item-bug

That environment’s details: react-native-snap-carousel: 3.8.0 Expo v33.0.0

Expected Behavior

Expected carousel to load with a green screen focused (slide index 30)

Actual Behavior

Carousel loads with slide index 14 focused or 6 focused depending on platform.

Reproducible Demo

https://snack.expo.io/@thekevinbrown/snap-carousel-first-item-bug

Steps to Reproduce

  1. Load more than a few pages of any type of slide into snap-carousel
  2. Set firstItem to a number > 14
  3. Carousel starts on various indexes which are not the one you passed in as a prop.

Other Notes

I commented with this snack on #496, but I don’t think it was noticed, and is likely to be a different issue now that I read that issue more closely, so I figured I’d open a new one. Thanks for your help!

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:8
  • Comments:32 (6 by maintainers)

github_iconTop GitHub Comments

12reactions
GH974commented, Jun 14, 2019

@thekevinbrown Hi, I have the same issue, i resolve this in use initialNumToRender={data.length}, but i slow performance

10reactions
rontalxcommented, Jul 2, 2019

@thekevinbrown Did you pass to the Carousel component the relevant getItemLayout & initialScrollIndex properties for your use-case? for example:

          firstItem={this.props.firstSlideIndex}
          initialScrollIndex={this.props.firstSlideIndex}
          getItemLayout={(_: ListItemData, index: number) => ({
            length: CARD_WIDTH,
            offset: CARD_WIDTH * index,
            index,
          })}

The branch just enables usage of them, so using the branch without implementing the props wouldn’t make any change. I haven’t tested your snack specifically but I’ve reproduced exactly the same issue and now it’s resolved also in my production environment on bigger lists. LMK how it goes

Read more comments on GitHub >

github_iconTop Results From Across the Web

Combo Box Default Items don't load reliably
Solved: I have two combo boxes on a Power App that are inconsistent on loading the default values. The default items are driven...
Read more >
CSS selector for first element with class - Stack Overflow
I have provided an alternative answer that should be more reliable and, as a bonus, works in IE7+, unlike :nth-of-type() . @Dan Mundy:...
Read more >
setTimeout() - Web APIs | MDN
The global setTimeout() method sets a timer which executes a function or specified piece of code once the timer expires.
Read more >
Move from Android to iPhone, iPad, or iPod touch
Turn on your new Apple device and place it near your Android device. ... Get help if Messages doesn't work as expected after...
Read more >
The 12 Most Common Reasons for Returns - Chargeback Gurus
The customer was wardrobing ... “Wardrobing” is the practice of purchasing an item with the intention of returning it once it has been...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found