Reputation: 2429
I have Horizontal FlatList & now I changed phone language to Arabic (RTL). scrollToIndex() is not working in RTL, without RTL it's working fine as expected. Any suggestions?
FlatList
<FlatList
style={myStyles.flatListStyle}
horizontal={true}
data={this.props.dataForFlatList}
renderItem={this.renderItem}
ref={(ref) => { this.flatListRef = ref; }}
keyExtractor={item => item.id.toString()} />
renderItem function on Press() am passing item id
this.flatListRef.scrollToIndex({ animated: true, index: id }); // Working fine without RTL - NOT WORKING WITH RTL
Thanks in advance.
Upvotes: 0
Views: 1150
Reputation: 25353
Found this solution.
flatListRef.current.scrollToIndex({
index: I18nManager.isRTL && Platform.OS === "ios" ? list.length - 1 - index : index,
});
For some reason ios scrolls to the opposite value in RTL localization. That is, when choosing the latter to the first. When choosing the penultimate to the second and so on.
Upvotes: 3
Reputation: 242
If you are scrolling outside of the render window you need to specifying the getItemLayout
props
Upvotes: 0