Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FlatList automatically scrolls to first when data is too large in horizontal mode (RTL)

Environment

System:
    OS: Windows 10
    CPU: (4) x64 Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz
    Memory: 1.35 GB / 7.87 GB
  Binaries:
    Node: 10.15.3 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.17.3 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
  IDEs:
    Android Studio: Version  3.5.0.0 AI-191.8026.42.35.5791312

React Native version: 0.60.4

Code

<FlatList
    style={{
        flexDirection: 'row',
        marginHorizontal: -wp('3%'),
        zIndex: 40
    }}
    initialNumToRender={10}
    data={this.state.data}
    horizontal={true}
    key={item => item.groupNo}
    keyExtractor={(item, index) => index.toString()}
    showsHorizontalScrollIndicator={false}
    showsVerticalScrollIndicator={false}
    ref={ref => (this.flatList = ref)}
    renderItem={({ item }) => (
        <Item item={item} />
    )}
/>

Steps To Reproduce

  1. Added some data to my FlatList
  2. Add horizontal={true} property to flatlist
  3. Set I18nManager.allowRTL(true)
  4. Set I18nManager.forceRTL(true)
  5. Make my renderItem component extend as PureComponent.
  6. Using Real Android Device

As you see below when my app is running on RTL direction FlatList automatically scrolls to top/first of the list but LTR direction is OK!

RTL:

RTL_GIF

LTR:

LTR_GIF

like image 900
Matin Zadeh Dolatabad Avatar asked Oct 26 '25 01:10

Matin Zadeh Dolatabad


2 Answers

I also have a same this problem, and my solution (you add them in your Flatlist). Hope help you. This link maybe help you improve your list: https://github.com/filipemerker/flatlist-performance-tips

getItemLayout={(data, index) => (
        { length: LECTURE_ITEM_HEIGHT, offset: LECTURE_ITEM_HEIGHT * index, index }
      )}
maxToRenderPerBatch={20}
initialNumToRender={10}
windowSize={10}
removeClippedSubviews={true}
like image 178
Daniel Le Avatar answered Oct 28 '25 15:10

Daniel Le


it's a major issue, also causes a problem with react-native-calendars.

for now, you can check onScroll event, on init it causes major scroll event, you can simply return false there and block the scroll. I hope a better solution will come in the next verisons.

like image 32
user3086644 Avatar answered Oct 28 '25 15:10

user3086644



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!