ScrolltoIndex not working react-native on a flatlist
Try adding reference to your FlatList
component like below :
<View>
<FlatList
getItemLayout={(data, index) => { return {length: 33, index, offset: 33 * index} }}
ItemSeparatorComponent={ () => <View style={ { width:"100%", height: .7, backgroundColor: 'rgba( 52,52,52,1)' } } /> }
data={this.state.outverse}
ref={(ref) => { this.flatListRef = ref; }}
renderItem={({item,index}) =>
<View style={styles2.flatview}>
<Text style={styles2.name}>{++index} {item} </Text>
</View>
}
/>
</View>
And in goIndex
function:
goIndex = () => {
this.refs.flatListRef.scrollToIndex({animated: true,index:5});
};
Try the following:
<FlatList
style={{
marginLeft: 50,
paddingTop: 0,
paddingRight: 0
}}
ref={ref => {
this.flatList_Ref = ref; // <------ ADD Ref for the Flatlist
}}
removeClippedSubviews={false}
enableEmptySections={false}
data={this.props.list}
keyExtractor={this._keyExtractor}
renderItem={this._renderItem1}
ItemSeparatorComponent={this._renderSeparator}
/>
And then call a goIndex function:
goIndex = () => {
this.flatList_Ref.scrollToIndex({animated: true,index:5});
};