0

I have a FlatList inside of a Modal in my application the Flatlist is filled with ListItem components from 'react-native-elements'.

The ListItems just have a title and an onPress method and nothing else, but the list has 250-300 items. The list is very laggy. I understand that is going to happen with a lot of items, but with the list I cant scroll to the bottom immediately. I can scroll a certain distance then it loads up the next few items then scroll a bit more then load a bit etc. This makes picking an item lower on the list or at the bottom incredibly slow.

My data is an array of { imgnames: "imglink" } objects and the list is sorted alphabetically.

I was wondering if this performance issue is going to happen no matter what because of the amount of items, or if its because it is inside of the module.

I just want to be able to scroll the entire length of the list immediately, so I can scroll to the 'M' or 'P' sections straightaway and then have a small delay while the list renders.

What would be the best list implementation for this.

FlatList Code:

<FlatList 
        data={this.props.list} 
        renderItem={
            ({item}) => <ListItem hideChevron = {true} onPress={() => this._setImage(item.imgLink)} title={item.key} removeClippedSubviews = {true} initialNumToRender={5}/>
  }/>
14
  • have you tried setting Initial Number To Render? Commented Sep 5, 2017 at 20:38
  • @bennygenel yes I have i have it set to 250 currently and I have this issue, I dont know if there is a limit to that setting but it seems to only load 5-20 at a time Commented Sep 5, 2017 at 20:41
  • You should set it to a small number so the FlatList renders fast and then when you scroll down you don't have a performance issue. Commented Sep 5, 2017 at 20:45
  • @bennygenel I just tried with setting it to 5 but i still get stop/start scrolling instead of being able to scroll straight to the bottom smoothly Commented Sep 5, 2017 at 20:47
  • 1
    @bennygenel holy poop, it was because I added the initailRenderNum and removeClipping to the ListItem not the FlatList. you could write that as an actual anwer for me to accept if you like, I appreciate the help Commented Sep 5, 2017 at 21:19

1 Answer 1

2

Setting initailRenderNum and removeClipping props should help with the performance problems of the FlatList.

Example:

<FlatList 
    data={this.props.list} 
    removeClippedSubviews={true} 
    initialNumToRender={5}
    renderItem={
        ({item}) => <ListItem hideChevron={true} onPress={() => this._setImage(item.imgLink)} title={item.key} />
  }/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.