-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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 VirtualizedList with initialScrollIndex not rendering all elements when data is updated #33558
Conversation
|
Base commit: a129595 |
@yungsters has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Thanks for making this change. I think it makes sense to me. One thing to mention here -- I tried to reproduce this with your example, but got error at VirtualizedList.js where the Could you check if that's the case for you? I wonder why that is happening on my side. That might indicate an issue by itself (separate from this one). |
@ryancat Sure, I'll check if that's also the case for me and I'll try to give you an update soon. |
@ryancat You were right, I get the same error using the example in the issue. There is no error when adding the The correct code example is the following:
I think there is no issue with this warning: react-native/Libraries/Lists/VirtualizedList.js Lines 1864 to 1869 in a223874
|
@yungsters has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
dcd60dc
to
6c3407f
Compare
I rebased onto master to resolve conflicts. |
Base commit: a129595 |
This test case is based on this issue: facebook#33529
…endering all items when da… Use this._hasDoneInitialScroll instead of this._scrollMetrics.offset to determine if the initial scroll is done. The offset can sometimes be 0 even after the scrollToIndex method is called to scroll to the initialScrollIndex: for example when the content does not fill the list.
This test case is unrelevant because we do not need to simulate a scroll to check that the render area has been adjusted, and this behavior is already tested by "adjusts render area with non-zero initialScrollIndex".
6c3407f
to
5eb2a0a
Compare
(Rebased again after commit was reverted) |
@yungsters has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
This pull request was successfully merged by @AntoineDoubovetzky in c5c1798. When will my fix make it into a release? | Upcoming Releases |
Is this still a problem or something? I have a horizontal FlatList, each item has the width of the screen (carousel style) and with active pagination. When I declare a value for initialScrollIndex all next items are only rendered when scrolling/paging is done |
…s when data is updated (facebook#33558) Summary: Fixes facebook#33529 (note that I reproduced the bug on iOS too). The bug comes from the fact that we were using `this._scrollMetrics.offset` to determine if the initial scroll was done. But sometimes it equals 0 even after the initial scroll is done, for example when the content does not fill the list. So I replaced it with `this._hasDoneInitialScroll`. I believe that `this._hasDoneInitialScroll` was not used in the first place because it was introduced later (3 years ago vs 5 years ago for the original code). The replacement correctly fixes the broken test case and the example given in the issue. Then I had to update two test cases (rename the first and remove the second), that shows explicitly the broken behavior: we have to simulate the initial scroll for the content to be adjusted, so when the content does not fill the view and the scroll cannot be executed, the content is not adjusted. ## Changelog [General] [Fix] - Fix VirtualizedList with initialScrollIndex not rendering all elements when data is updated Pull Request resolved: facebook#33558 Test Plan: - I added a broken test case based on the issue - I tested with the RNTesterApp using the code example given in the issue Reviewed By: ryancat Differential Revision: D35503114 Pulled By: yungsters fbshipit-source-id: 67bb75d7cf1ebac0d59127d0d45afbaa3167dcf3
Summary
Fixes #33529 (note that I reproduced the bug on iOS too).
The bug comes from the fact that we were using
this._scrollMetrics.offset
to determine if the initial scroll was done. But sometimes it equals 0 even after the initial scroll is done, for example when the content does not fill the list. So I replaced it withthis._hasDoneInitialScroll
.I believe that
this._hasDoneInitialScroll
was not used in the first place because it was introduced later (3 years ago vs 5 years ago for the original code).The replacement correctly fixes the broken test case and the example given in the issue.
Then I had to update two test cases (rename the first and remove the second), that shows explicitly the broken behavior:
we have to simulate the initial scroll for the content to be adjusted, so when the content does not fill the view and the scroll cannot be executed, the content is not adjusted.
Changelog
[General] [Fix] - Fix VirtualizedList with initialScrollIndex not rendering all elements when data is updated
Test Plan