scrollToIndex is not working in RTL FlatList React-Native

917 views Asked by At

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.

2

There are 2 answers

4
Hayk Shakhbazyan On

If you are scrolling outside of the render window you need to specifying the getItemLayout props

0
Muhammad Numan On

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.