[Flatlist] initialScrollIndex doesn't work at all
See original GitHub issueIs this a bug report?
Yes
Have you read the Bugs section of the Contributing to React Native Guide?
Yes
Environment
react-native: 0.45.1
Steps to Reproduce
(Write your steps here:)
Made a horizontal flatlist with initialScrollIndex. It should go to the index and stay there.
<FlatList
data={list}
disableVisualisation="false"
keyExtractor={this.keyExtractor}
renderItem={this.renderItems}
horizontal={true}
scrollEventThrottle={2000}
pagingEnabled={true}
initialScrollIndex={8}
showsHorizontalScrollIndicator={false}
onScroll={this.scroll}
getItemLayout={this.layout}
initialNumToRender={3}
/>
Actual Behavior
It goes to the right index and after about a half second it goes back to the first item in the list.
No idea how to implement it, because method scrollToIndex didn’t work too.
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (3 by maintainers)
Top Results From Across the Web
initialScrollIndex not working for FlatList react native
I've solved this with setting: onContentSizeChange which will handle scroll to index whenever flatlist data is changed and all items rendered ( ...
Read more >FlatList issue with initialScrollIndex - Expo Snack
FlatList issue with initialScrollIndex. No description. Open with Expo Go. Open in editor. Need Expo? Don't have the Expo Go? Download the app...
Read more >initialScrollIndex not working for FlatList react native-React ...
Coding example for the question initialScrollIndex not working for FlatList react native-React Native.
Read more >FlatList - React Native
Instead of starting at the top with the first item, start at initialScrollIndex . This disables the "scroll to top" optimization that keeps...
Read more >FlatList initialScrollIndex Prop Not Working Properly Solution
If any of you know why it is not working then please share your opinion or code with me on comment section. It...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@hramos @jstheoriginal I resolved my problem - my getItemLayout was wrong, but now I have similar issue. It goes to the good index, then I’t blank for about 0.5s and then it’s rerendering the item on the good index. My component doesn’t rerender. OnScroll and scrollEventThrottle works and they have no affect on my issue. InitialNumToRender didn’t helped too even with higher number than initialScrollIndex.
@pcguru Could you give me some pointer about how to ‘Precompute the offset’ if each item has a different height? (my app is similar to the IM app, the item’s height depends on the comment’s length)
Thanks.