GetStream / react-native-bidirectional-infinite-scroll

📜 React Native - Bidirectional Infinite Smooth Scroll
https://getstream.github.io/react-native-bidirectional-infinite-scroll/
MIT License
236 stars 27 forks source link

onStartReached gets triggered in the initial scroll down #27

Open borasumer opened 2 years ago

borasumer commented 2 years ago

This gets triggered when you start scrolling down, so technically before it has reaches the start. Not sure if this is an intended behaviour. I imagined it would be triggered only when you come back to the first element after you scroll down.

pierroo commented 2 years ago

Facing the same issue @borasumer , did you manage to find a fix for it? Basically from a chat app that fetches remote messages, then messages are added to the flatlist which triggers a scrollToEnd event, but at the start of the event we are at the top of the flatlist which triggers the onStartReached automatically (which we don't want, for obvious reasons)

I tried to add a state variable that gets activated and allows the triggered function under onStartReached to only work if this variable is true (after the list is initially mounted), however that also means it returns nothing at first which breaks the onStartReached function (if it ever returns nothing it assumes there is nothing left to return in the future either, which makes sense in a normal scenario)

EDIT: It's probably not ideal, but I "fixed" it by setting "onStartReachedThreshold" to 1. I would rather have it as 10 for a better UX, but then it gets caught on initial load of chat messages which we try to avoid here so... compromise until the team looks into it? (@vishalnarkhede )

sumit-do-it commented 4 months ago

I find out that onStartReached is now added in the FlatList Props and this module is passing all the props, we are passing, to the Flatlist in its implementation. Due to this, it is getting invoked initially by Flatlist. For now, I'm using it by overriding the prop onStartReached={null} and added the patch. Let me know, if there would be any better alternative and gives thumbs up, if it works for you!