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 onViewableItemsChanged method does't trigger when first render? #25812

Closed
wenzhihao123 opened this issue Jul 25, 2019 · 13 comments
Closed
Labels
Bug Component: FlatList Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@wenzhihao123
Copy link

wenzhihao123 commented Jul 25, 2019

React Native version: +

Steps To Reproduce

When i used FlatList in Android, when i first entered the page, why onViewableItemsChanged method does't trigger? Generally speaking, first render also means that the visibility of items have changed?

Describe what you expected to happen:

When first enter the page , onViewableItemsChanged method will trigger without scroll event !

My code just like this:

const VIEWABILITY_CONFIG = {
    minimumViewTime: 300,
    viewAreaCoveragePercentThreshold: 10,
    waitForInteraction: false,
};
...

<FlatList
      ...
      horizontal={false}
      numColumns={2}
      renderItem={({ item, index }) => this.renderItem(item, index)}
      ItemSeparatorComponent={this.renderSeparator}
      ListFooterComponent={this.footerView}
      ListHeaderComponent={this.rederListHeader()}
      onViewableItemsChanged={this._onViewableItemsChanged}
      viewabilityConfig={VIEWABILITY_CONFIG} />

Please write soon, thanks !

@Ashwin-Mothilal
Copy link

Ashwin-Mothilal commented Aug 5, 2019

@wenzhihao123 Check whether any other child component creates an interaction handle. Disabling interaction handle from Child component fixed the problem for me.

@wenzhihao123
Copy link
Author

@Ashwin-Mothilal Thanks for your answer, my FlatList has header, and header also has other FlatList, but how to forbid item's FlatList to create an interaction handle?

@kalwaniyash
Copy link

I am facing the same issue, even though my waitForInteraction is set to false
Is there any progress or solution to this?

The list renders as soon as i scroll even a bit. I tried using the scrollToOffset to simulate a scroll, didn't work either.

@bigggge
Copy link

bigggge commented Sep 17, 2019

same issue

@kalwaniyash
Copy link

Hey, my issue was nothing related to FlatList. Everything was working fine in FlatlList, there was a library that i was using that was forcefully making the list wait for interaction. Basically it was using a interaction handler because of which my list would wait for interaction even though i had my waitForInteraction set as false

@bvangrimberge
Copy link

I had the same issue and was able to resolve it by adding initialScrollIndex={0.01} to the FlatList. It's dirty but it seems to trigger the onViewableItemsChanged method.

Using a value of 0 or going lower than 0.01 also did not trigger the method.

@Dylan0916
Copy link

+1

@personapp
Copy link

Adding key={uniqueKeyForEachRender} prop to FlatList solves the issue.

@stale
Copy link

stale bot commented Apr 21, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Apr 21, 2020
@Dlozitskiy
Copy link

+1

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Apr 23, 2020
@stale
Copy link

stale bot commented Jul 25, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jul 25, 2020
@stale
Copy link

stale bot commented Aug 1, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Aug 1, 2020
@pgajbhiye
Copy link

pgajbhiye commented Dec 15, 2020

const VIEWABILITY_CONFIG = {
    viewAreaCoveragePercentThreshold: 50,
    waitForInteraction: false, //setting this false, alone did not work for me
};

<FlatList
        ref={ref => {
          this.list = ref;
        }}
        onLayout={() => {
          if (this.list != null) {
            //Need this for initial widget lazy render
            this.list.recordInteraction();
          }
        }}
      renderItem={({ item, index }) => this.renderItem(item, index)}
      viewabilityConfig={VIEWABILITY_CONFIG} />

Hope this helps

Few tips:

  1. Make sure flat list is not inside parent ScrollView
  2. Use unique key in keyExtractor

@facebook facebook locked as resolved and limited conversation to collaborators Oct 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Component: FlatList Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

10 participants