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

fix viewCache for gridList (resolves issue #32) #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/components/virtual-scroll/virtual-scroll.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,13 @@ export class VirtualScroll<T> implements VirtualScrollState<T> {
const bufferLengthPx = (scrollContainer.clientHeight) * bufferLength;

// Calculate the number of rendered items per row
const itemsPerRow = gridList ? Math.floor(scrollContainer.clientWidth / itemWidth!) : 1;
let itemsPerRow = gridList ? Math.floor(scrollContainer.clientWidth / itemWidth!) : 1;

// Don't reset items per row to 0 on view change as it invalidates the viewCache
if (itemsPerRow === 0 && this._itemsPerRow > 0) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to safely skip running all of the logic in this subscription when the list element has a width or height of 0. Instead of checking for itemsPerRow being 0 here, we could update the filter condition on line 304 to additionally check that the clientWidth and clientHeight of scrollContainer are both greater than 0.

This should hopefully result in the same fixed behavior and also avoid updating other state variables unnecessarily.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll test it out and see if the behaviour is the same, will update the PR accordingly, thanks

itemsPerRow = this._itemsPerRow;
}

const virtualScrollHeight = items.length * itemHeight! / itemsPerRow;

// Adjust the bounds by the buffer length and clamp to the edges of the container
Expand Down