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

onEndReached callback trigger twice #18887

Closed
3 tasks done
tafelito opened this issue Apr 16, 2018 · 14 comments
Closed
3 tasks done

onEndReached callback trigger twice #18887

tafelito opened this issue Apr 16, 2018 · 14 comments
Labels
Bug Component: FlatList Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@tafelito
Copy link

FlatList onEndReached callback trigger twice sometimes or even 4 times.

Environment

Environment:
OS: macOS High Sierra 10.13.4
Node: 8.9.4
Yarn: 1.5.1
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.3 Build version 9E145
Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: 0.54.4 => 0.54.4

Steps to Reproduce

I'm using a FlatList with inverted={true}. I don't have exactly steps to reproduce it as it happens randomly. I saw a bunch of other issues having the same problem but none of them provided a solution. #14015 did not work for me. If I set the onEndReachedThreshold to 0.8 it doesn't happen all the time as opposed as using the default value of 0.5 that makes it happen constantly. I don't think a re-render is causing this either as it's only running once as you can see from the logs.

Expected Behavior

onEndReached to be called once.

Actual Behavior

this is the render method

render() {
    console.log("render messages", this.props.messages);
    return (
      <FlatList
        inverted
        data={this.props.messages}
        keyExtractor={this.keyExtractor}
        renderItem={this.renderItem}
        onEndReached={info => {
          console.log("onEndReached", info);
        }}
      />
    );
  }

And this is the output
image

@react-native-bot
Copy link
Collaborator

Thanks for posting this! It looks like your issue may refer to an older version of React Native. Can you reproduce the issue on the latest release, v0.55?

Thank you for your contributions.

@tafelito
Copy link
Author

same thing happens with latest version

@j0hnhan
Copy link

j0hnhan commented Apr 26, 2018

I have the same issue with react-native version 0.51.0, basically onEndReached triggered twice with different distanceFromEnd value but same state and props.

@nezaidu
Copy link

nezaidu commented May 16, 2018

same thing

@chunghalu
Copy link

This is my solution: #14015 (comment)

@z-zp
Copy link

z-zp commented Sep 10, 2018

onEndReached = () => {
    let time = (new Date()).getTime() - this.time
    if (time < 500) return
    this.time = (new Date()).getTime()
        //   TODO
  }

@DoGooRi
Copy link

DoGooRi commented Sep 20, 2018

same too.
so i used debounce : #14015 (comment)

@xuqingkuang
Copy link

xuqingkuang commented Oct 20, 2018

onEndReached = () => { let time = (new Date()).getTime() - this.time if (time < 500) return this.time = (new Date()).getTime() // TODO }

shit ... must be larger than 500ms, less delay won't work.

====

btw: if this.time initialized in componentDidMount() after data fetched at first time, onEndReached won't trigger forever.

@brunnohofmann
Copy link

Im facing the same problem, and my the following versions:
"react": "16.8.3",
"react-native": "0.59.1",

@hjaintech
Copy link

Is there any update on when this issue will be fixed ?

@hellpirat
Copy link

Same here

@brunnohofmann
Copy link

I saw that you cannot put FlatList inside a ScrolView.
So I did put my flatlist in a separated screen while this problem still happens and now its working. But

@stale
Copy link

stale bot commented Aug 4, 2019

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 Aug 4, 2019
@stale
Copy link

stale bot commented Aug 11, 2019

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 11, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Aug 12, 2019
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