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 not working

See original GitHub issue

Hey, I’m having an issue with setting firstItem. Most of the time, the wrong item is selected. We are using a function which returns the children, so we got something like this:

<Carousel
                    ref={'covers'}
                    sliderWidth={viewportWidth}
                    itemWidth={240}
                    inactiveSlideScale={0.9}
                    inactiveSlideOpacity={0.6}
                    showsHorizontalScrollIndicator={false}
                    snapOnAndroid={true}
                    removeClippedSubviews={false}
                    onSnapToItem={this.onSnap}
                    firstItem={8}
                >
                    {this.getCovers()}
</Carousel>

In our case, the 8th item wasn’t selected when the component mounts. If we do something like this:

componentDidMount() {
    setTimeout(() => { this.refs.covers.snapToItem(8,false); },500);
}

…the correct item is selected. Are there any issues when generating the childrens via function?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

18reactions
balwinder4264commented, May 6, 2019
 I had same problem i add initialNumToRender={100} so Carousel working fine for first . 100 items 
        <Carousel
          ref={(c) => { this._carousel = c; }}
          initialNumToRender={100}
          data={this.state.picture}
          firstItem={this.state.index}
          renderItem={this._renderItem}
         sliderWidth={500}
          itemWidth={500}
          
          //onSnapToItem={(index) => this.setState({ activeSlide: index }) }
        />
    );
}

}

6reactions
sitorushcommented, Nov 17, 2017

I just had similar issue where the carousel has long list (eg. 90 items) and set the firstItem into high number will always select the 12th item. It turns out I have to add getItemLayout in order for FlatList to figure out how long the list will be.

<Carousel
...
getItemLayout={(data, index) => ({offset: viewportWidth * index, length: viewportWidth, index})}
...
/>

I hope this helps someone else related to firstItem issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native Snap Carousel - First Item - Stack Overflow
Currently when the carousel loads it loads the first index instead of the one I tell it to with FirstItem. When I refresh...
Read more >
Solved - FirstItem not working | OTLand
Hello my firstitems not working, with account menager and without account menager, i cant change eq on samples becouse after relog samples got...
Read more >
Solved: The Patch not updating the first item
If you use the ForAll backward, you will suffer high performance issues. ForAll is a function that produces a Table, not a for...
Read more >
recyclerview first item does not get focus by default with ...
I tried keeping and removing values 'yes', 'no' or 'auto' importantForAccessbility for Recyclerview in the xml file but nothing solved my issues ......
Read more >
Database: Pagination - The PHP Framework For Web Artisans
However, if you do not plan to show the total number of pages in your ... $paginator->firstItem(), Get the result number of the...
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