-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
Fix onEndReached
bugs for FlatList
#26444
Conversation
This is amazing!! |
some automated test would be highly desirable |
@vonovak Thanks for your feedback. I added a test case to check if |
8dfc262
to
4374497
Compare
https://github.com/ifsnow/react-native-infinite-flatlist-patch Use the patch library above to try it out before this PR merges. |
Thanks!, I'm starting a project with RN and was going to add infinite scrolling today. I didn't know they were so many problems with it since so long ago. Now I just hope the elevation bug gets fixed 🤞 |
@ifsnow I left some comments that can improve the tests, but please note I'm not a person who can merge the PR, I'm just trying to make it look good. |
@vonovak I agree on your comments. I'm sure it can improve the tests, so I modified the test as you said. It's ok even if you don't have merging role. Thank you for your interest in my PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate you trying to optimize this, and love how you beefed up the tests, but I don't think you're considering all possible use cases this needs to work for, especially cases with rows of unpredictable render heights and data changes (e.g. the same 3 items could be updated to include a piece of metadata that shrinks their height, which would no longer fill the screen and should trigger an onEndReached
).
Do you mind providing more context on the exact cases you're seeing where onEndReached
is called when it shouldn't be? As I commented inline, it sounds like you probably just need to tweak your configuration or adjust how you're thinking about optimal performance.
@sahrens Thank you for trying to explain the shortcomings of my implementation. I didn't think of a situation where the item layout would shrink dynamically. I've tried to improve the logic so that it works more clearly in the various cases you've mentioned. You can see how the improved logic works in the test app. The first goal is to come up with an easy way to use infinite scrolling in FlatList without worrying about the suitable value of Please let me know if there is a better approach or something I'm missing. |
This looks very cool! Does this PR also solve the issue where I can test these changes in my project to see if it helps with having to use different |
@kristerkari I think this patch will work the same on both Android and iOS. Please test it on your project and let me know if you have any problems. Thanks. |
We really need this merged, awesome work. |
@emilioheinz You can use this improvement feature without merged RN. Check it out here https://github.com/ifsnow/react-native-infinite-flatlist-patch |
Any updates on this? |
I did a quick test using patch-package on top of a 0.61.2 project. It does not seem to fix the issue with I'm currently using |
use the package provided by the author |
Bump, we really need this. |
Any updates on this? Would be nice to get this merged instead of using patch :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ifsnow for the contribution!
Indeed this is an issue we've seen in internal usage of FlatList as well. I've been hesitant about pulling this change in because of lack of testing in our list components and any potential side effects this may have in our view logging. We are actively investing in this area but still have a ways to go.
In the meantime, for this fix, could we add an opt-in option to the fix so we can run experimentation around it? That'd help de-risk this change for us as we continue to improve testing and clarify expectations in VirtualizedList's behavior.
any news here? |
I've been discussing this ticket on the road to 0.7.0 thread, I'd love to pick this up. I don't have much in the way of internal React / RN development but I reckon to resolve @lunaleaps request for an opt-in we would need a prop, right? (Sorry for necro'ing the PR, by the way) |
@dylmye Sounds great! Let me know if you need any help |
Any solution of this |
I didn't get round to this @vksgautam1 because I don't have write access to ifsnow's repo and (honestly) forgot about this. There's also conflicts that need to be fixed that I don't have the knowledge to fix. |
- Import improvements from PR facebook#26444 _maybeCallOnEndReached: https://github.com/facebook/react-native/pull/26444/files#diff-7481ec8ed5532798b075df637e805a8e439807aa2ce671208c24068c286361e8L1374-R1413 https://github.com/facebook/react-native/blob/2d3f6ca9801ef92b446458a2efc795db4ec17021/Libraries/Lists/VirtualizedList.js#L1372-L1414 - Additional check _hasDoneFirstScroll for maybeCallOnEndReached (added in onScroll callback) - Add improved logic start/endPositionReached and isScrollingForward - Add threeshold instead of 2 - Use default threeshold 30 for iOS - Add other improvements from method _maybeCallOnEndReached
moving onEndReached logic for inverted infinite list with TalkBack enabled to rn-tester example. To add in upcoming PR Notes of tasks done with this and previous commits: - Import improvements from PR facebook#26444 _maybeCallOnEndReached: https://github.com/facebook/react-native/pull/26444/files#diff-7481ec8ed5532798b075df637e805a8e439807aa2ce671208c24068c286361e8L1374-R1413 https://github.com/facebook/react-native/blob/2d3f6ca9801ef92b446458a2efc795db4ec17021/Libraries/Lists/VirtualizedList.js#L1372-L1414 - Additional check _hasDoneFirstScroll for maybeCallOnEndReached (added in onScroll callback) - Add improved logic start/endPositionReached and isScrollingForward - Add threeshold instead of 2 - Use default threeshold 30 for iOS - Add other improvements from method _maybeCallOnEndReached - Complete improvements required for iOS and Android: - Test iOS solution onEndReached correctly works with an infinite list - Test Android Solution onEndReached correctly works and list starts from the end - Try to remove setTimeout and test if bug is reintroduced - On Android re-introduce java logic to start the list from the bottom - On iOS use initialScrollIndex={0} with inverted flatlist and VoiceOver - Code review: - Test setEnabledTalkbackCompatibleInvertedList - Remove check on lastItem - Remove setTimeout Try to add more of the logic from _maybeCallOnEndReached as it may be the cause of the issue _maybeOnCallReached could be causing the flatlist to scroll in the opposite direction later .. check if the callback is called after the scrollTo - Review Diff
This PR is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days |
This PR was closed because the author hasn't provided the requested feedback after 7 days. |
https://github.com/ifsnow/react-native-infinite-flatlist-patch/tree/master/patches does not support rn versions > 0.68. |
anybody was able to reproduce this issue on 0.72 or 0.73? Thanks |
@dylmye @vksgautam1 @KingAmo @roshangm1 @tanoabeleyra @luancurti @nnnnnoel @ghasemikasra39 @vastamaki @dylmye @Smolyan91 anybody was able to reproduce this issue on 0.72 or 0.73? Thanks |
Summary
Related to : #18887 #16067 #25656 #14015 (There're more issues.)
I'm sure FlatList's
onEndReached
doesn't work as expected. It's one of the headaches that hasn't been solved for quite some time. We had to make it work by modifyingonEndReachedThreshold
several times, but eventually it doesn't work efficiently.Problems
In most cases,
onEndReached
is called one or more times after the initial rendering.If scrolling is fast, it will be called again after the
onEndReached
call.There're some logic implementations that are not needed.
Solutions
Changelog
[General] [Fixed] - Fix
onEndReached
bugs for FlatListTest Plan
Test App : https://github.com/ifsnow/FlatListImprovementTest
onEndReached
is called, 10 items are added.1. After the initial rendering
OnEndReached
is called twice in a short period and has 30 items.OnEndReached
is not called and has 10 items.2. After scrolling to the 11th item
OnEndReached
is called twice in a short period, having 50 items.OnEndReached
is called twice when required, having 30 items.