react-native: [Flatlist] initialScrollIndex doesn't work at all
Is 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.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (3 by maintainers)
@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.
I had same issue. Here’s my working workaround:
contentOffset = {{x: ITEM_WIDTH * this.props.startAtIndex, y: 0}}
@DevSzurmanski - I am also encountering the same issue. What was the problem with your getItemLayout function?
This is my current code:
Can you reproduce this using Snack?