0

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.

Srihari
  • 2,387
  • 9
  • 51
  • 82

2 Answers2

2

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.

Muhammad Numan
  • 23,222
  • 6
  • 63
  • 80
0

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

Hayk Shakhbazyan
  • 242
  • 2
  • 15