'scrollToIndex is not working in RTL FlatList React-Native
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.
Solution 1:[1]
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.
Solution 2:[2]
If you are scrolling outside of the render window you need to specifying the getItemLayout props
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Muhammad Numan |
| Solution 2 | Hayk Shakhbazyan |
