-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Improve collection items scrolling #16738
Improve collection items scrolling #16738
Conversation
e0f245c
to
179eca8
Compare
179eca8
to
958039d
Compare
Since we know the expected total number of elements we can let the virtual scroller know it by creating the expected number of items beforehand and then update them as we fetch the details.
Remove unnecessary defaults and keep it to minimum.
- Make `expandDataset` optional with default to false. - Reorder props to put required ones first.
be295dc
to
739193a
Compare
This is finally ready for review. |
* This is used to determine the offset to fetch the element from when | ||
* scrolling through the collection. | ||
*/ | ||
element_index?: number; |
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.
Very minor: Don't you always know the element_index ? Similarly, could you require fetching to be a boolean and init it with true ?
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.
Good point, making element_index
optional here was just to be able to make it work with Array.fill
but now that I look at it we still need to map the index to each placeholder so making it required and using simple for loop would be even better. I'll go and do that 👍
About making the fetching
boolean default to true... I'm not so sure, maybe default them to false
, I think not even setting it by default will save a tiny bit of memory if you have a huge number of elements that you would never navigate to 😅
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.
Clever, I like it!
That works super smooth! |
Thanks @davelopez |
Requires #16725
We know the total number of items in a collection since they are immutable. We can then initialize the virtual scroller array with all the items as placeholders and then just fetch those that are missing real data. The direct benefit is that we can scroll and navigate to the end of the collection (or any point in the middle) much more smoothly.
This approach might be a bit naive though as with potentially huge collections we are creating a lot of items that will probably never be navigated to... but it is probably worth it.
We can observe the differences in scrolling behavior in the examples below with a modest collection containing 25k items.
Note: expanding a placeholder has been disabled.
Before
CollectionScrollingBefore.mp4
After
CollectionScrollingWithPlaceholders.mp4
How to test the changes?
License