Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlatList blanks out when scrolled quickly (on large dataset) #23442

Closed
mkashlev opened this issue Feb 13, 2019 · 31 comments
Closed

FlatList blanks out when scrolled quickly (on large dataset) #23442

mkashlev opened this issue Feb 13, 2019 · 31 comments
Labels
Bug Component: FlatList Resolution: Locked This issue was locked by the bot.

Comments

@mkashlev
Copy link

mkashlev commented Feb 13, 2019

🐛 Bug Report

Contents of FlatList disappear upon quick scrolling

ezgif com-video-to-gif 1

To Reproduce

When a FlatList is scrolled with a pull to refresh and goes through multiple pages, and then scrolled up quickly, the content disappears.
Scroll down FlatList, going through multiple Pull to refresh instances until you have sufficiently large list. Then scroll up quickly, and the content disappears and does not come back. This behavior sometimes happens when you scroll down quickly as well.

img_7299

Expected Behavior

Content should not disappear when scrolled quickly up or down. This is the purpose of using FlatList over (deprecated) ListView.

img_7300

Code Example

<FlatList
        style={styles.nudgeScrollView}
        onRefresh={onRefresh}
        refreshing={refreshing || false}
        onScroll={onScroll}
        onEndReached={onEndReached}
        onViewableItemsChanged={onViewableItemsChanged}
        scrollEventThrottle={400}
        data={nudges}
        keyExtractor={item => item.id}
        ListFooterComponent={footer}
        scrollEnabled={scrollEnabled}
        renderItem={({ item }) => (
          <NudgeCard
            nudge={item}
            {...{
              onOpenNudge,
              onArchiveNudge,
              allowListScroll,
              userId,
              archived,
            }}
          />
        )}
      />
    )

Even if onScroll or viewableItemsChanged props are commented out, the issue still remains.

Environment

React Native Environment Info:
    System:
      OS: macOS 10.14
      CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
      Memory: 27.23 MB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.11.0 - /usr/local/bin/node
      Yarn: 1.10.1 - /usr/local/bin/yarn
      npm: 6.4.1 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
      Android SDK:
        API Levels: 23, 25, 26, 27, 28
        Build Tools: 27.0.3, 28.0.2, 28.0.3
        System Images: android-19 | ARM EABI v7a, android-22 | Google APIs Intel x86 Atom, android-27 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 3.2 AI-181.5540.7.32.5014246
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.6.3 => 16.6.3 
      react-native: 0.58.4 => 0.58.4 
    npmGlobalPackages:
      react-native-git-upgrade: 0.2.7
@react-native-bot

This comment has been minimized.

@mkashlev
Copy link
Author

react native upgraded, but issue persists @react-native-bot

@lucsky
Copy link

lucsky commented Feb 13, 2019

@mkashlev From the FlatList documentation:

In order to constrain memory and enable smooth scrolling, content is rendered asynchronously offscreen. This means it's possible to scroll faster than the fill rate and momentarily see blank content. This is a tradeoff that can be adjusted to suit the needs of each application, and we are working on improving it behind the scenes.

@mkashlev
Copy link
Author

@lucsky Thanks for a quick response! This makes sense. One thing I noticed that in some cases, the screen does not get re-rendered, no matter how long I wait. Its a different thing from screen rendering being delayed (at least content shows up later). In my case the content does not show up.

@mkashlev
Copy link
Author

Was wondering if anyone has experienced this area, or if I'm not doing it correctly? @sahrens

@akshetpandey
Copy link

@mkashlev : I have definitely faced the issue where the component never updates. Make sure your keyExtractor function is correct. Removing removeClippedSubviews and getItemLayout has fixed this for me but causes performance problems. Looks like there may be subtle bug in the flatlist implementation.

@ghost
Copy link

ghost commented Mar 4, 2019

I have the same issue, even for 100 items this happens to my flatlist

<FlatList
          ref={(ref) => (this.flatListRef = ref)}
          extraData={this.props.extraData}
          keyExtractor={this.keyExtractor}
          enableEmptySections
          automaticallyAdjustContentInsets={false}
          inverted={this.props.inverted}
          data={this.props.messages}
          style={styles.listStyle}
          renderItem={this.renderRow}
          onScroll={this.handleOnScroll}
          scrollEventThrottle={100}
        />

@ghost
Copy link

ghost commented Mar 4, 2019

@mkashlev did you find any solutions for this issue?

@mkashlev
Copy link
Author

mkashlev commented Mar 4, 2019

@muhammadwfa - still no solution.

@erennyuksell
Copy link

I have this issue too and onreachend event calling with delay

@alloy
Copy link
Contributor

alloy commented Mar 19, 2019

As noted by @lucsky, the documentation mentions this trade-off and thus it is currently considered to work as intended. What the docs don’t do a great job at is explaining to you how you can fine-tune this behaviour to make the right trade-offs for your situation, something that I’m sure PRs for would be much appreciated.

In an effort to reduce the noise in the issue tracker, I’ll close this issue, but will leave you with a few links that were helpful to me recently:

@johinsDev
Copy link

@muhammadwfa - still no solution.

do you have some solution for this problem?

@ghost
Copy link

ghost commented Jul 27, 2019

Now I am using scrollview, it works well.

@nihp
Copy link

nihp commented Oct 28, 2019

Any solution for this in Flatlist

@Rainsho
Copy link

Rainsho commented Nov 5, 2019

Keep watching.

@Rahulkishanm
Copy link
Contributor

getItemLayout has fixed this for me.

@nihp
Copy link

nihp commented Nov 13, 2019

@Rahulkishanm Can you give any code and how you have calculate the getItemLayout for entire list?

@nihp
Copy link

nihp commented Nov 13, 2019

@Rahulkishanm getItemLayout props not worked for me

getItemLayout(data, index) {
 return (
   {
     length: deviceHeight,
     offset: (deviceHeight) * index,
     index
   }
 );
}

 renderGrid(item) {
   return(
     <TouchableOpacity activeOpacity = { .5 } >
       <View style={{backgroundColor: 'white', alignItems: 'center'}}>
         <FastImage style={{width: deviceWidth, height: deviceHeight, margin:6}}
           resizeMode={FastImage.resizeMode.contain}
           source={item.uri}/>
       </View>
     </TouchableOpacity>
   );
 }

_handleMoreItems = () => {
   let { loadingMoreItems, } = this.state;
   let loadedItems = this.props.pagination.loadedItems;


   if (!loadingMoreItems && !loadedItems) {

       this.setState(
         (prevState, nextProps) => ({
           loadingMoreItems: true,
           page: prevState.page + 1
         }),
         () => {
           this.props.fetchItemsPerPage(this.state.page);
         }
       );
 
   }
 };

_renderFooter = () =>{
 return <ActivityIndicator color="#000000" style = {{marginBottom:10, marginTop:10}}/>;
}
 shouldItemUpdate(){
   return false;
 }

render(){
 return(
<View style = {{flex:1}}> 
 <FlatList
             ref={(ref) => { this.flatListRef = ref; }}
             data={filteredItems}
             renderItem={({ item }) => this.renderGrid(item)}
             numColumns={2}
             extraData={this.props.pagination}
             keyExtractor={item => item.id}
             onEndReached={this._handleMoreItems}
             onEndReachedThreshold={0.001}
             ListFooterComponent={this._renderFooter}
             legacyImplementation = {true}
             bounces = {false}
             maxToRenderPerBatch={4}
             getItemLayout={(data, index) => this.getItemLayout(data, index)}
             //initialNumToRender = {14}
             shouldComponentUpdate= {this.shouldItemUpdate()}
             //onScroll={event => {
               //this.yOffset = event.nativeEvent.contentOffset.y
             ///}}
             //onScrollEndDrag={() => this.endScreen()}
             //scrollEventThrottle={2}
             onMomentumScrollEnd={e => this.scroll(e.nativeEvent.contentOffset)}
           />
)
}

@Shanie1331
Copy link

@nihp Can you please post a full code of your flat list implementation as It can be improved with some props that I can help you with.

@nihp
Copy link

nihp commented Nov 13, 2019

@Shanie1331 I have updated my flatlist implementation above. Can you look into this?

I need solution for two issues

  1. Flatlist blanks out when scrolling
  2. Scrolling is not smooth in Flatlist

@nihp
Copy link

nihp commented Nov 13, 2019

Shanie1331 Any update

@Shanie1331
Copy link

Can you wait for a while as I need to replicate your implementation?

@nihp
Copy link

nihp commented Nov 13, 2019

Okay.

Thanks

@tootsweet
Copy link

Hello,

We are experiencing this bug as well with RN61.

@vishnusurabhirao
Copy link

Me tooo

@SelvaraniAlagumuthu
Copy link

Hi,
I am also faced while scrolling the list i got blank pages. After adding scrollview in flatlist now its working fine. Here my code please check may be its helpful.

<View style={{ flex: 1}}>
<FlatList
data={data }
renderItem={({ item }) => <this.Item item={item} />}
keyExtractor={item => item.id}
/>


Thanks

@nihp
Copy link

nihp commented Dec 13, 2019

@SelvaraniAlagumuthu Can you give your render Item method in brief

@androidsdkproject
Copy link

Hi,
I am also faced while scrolling the list i got blank pages. After adding scrollview in flatlist now its working fine. Here my code please check may be its helpful.

<View style={{ flex: 1}}>
<FlatList
data={data }
renderItem={({ item }) => <this.Item item={item} />}
keyExtractor={item => item.id}
/>

Thanks

Can you share your code of renderItem , i am facing same issue.

@nihp
Copy link

nihp commented Jan 6, 2020 via email

@androidsdkproject
Copy link

androidsdkproject commented Jan 7, 2020 via email

@NikGanyponko
Copy link

I have this issue too and onreachend event calling with delay

Yeah! Thank you, I had a problem => in some cases flatList's callback onEndReached didn't call by scrolling to the end. So, I've added setTimeout on endReached and it works perfect.

@facebook facebook locked as resolved and limited conversation to collaborators Mar 19, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Mar 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Component: FlatList Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests