Skip to content

Commit

Permalink
LazyListBox: items are not loaded, if the last is invisible #3356
Browse files Browse the repository at this point in the history
  • Loading branch information
edloidas committed Nov 20, 2023
1 parent eee7815 commit d0602ec
Showing 1 changed file with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,40 @@ export class LazyListBox<T> extends ListBox<T> {
}

protected handleLazyLoad(): void {
//
// must be implemented by subclasses
}

setItems(items: T[], silent?: boolean): void {
super.setItems(items, silent);

if (items.length > 0) {
this.addLazyLoad();
}
this.addLazyLoad();
}

addItems(items: T[], silent: boolean = false): void {
super.addItems(items, silent);

if (items.length > 0) {
this.addLazyLoad();
}
this.addLazyLoad();
}

private addLazyLoad(): void {
if (this.getItemCount() === 0) {
const lastVisibleChild = this.getLastVisibleChild();
if (!lastVisibleChild) {
return;
}

if (!this.observer) {
this.initIntersectionObserver();
}

this.addLazyLoadWhenLastIsVisible(this.getLastChild());
this.addLazyLoadWhenLastIsVisible(lastVisibleChild);
}

protected getLastVisibleChild(): Element | undefined {
if (!this.isVisible() || this.getItemCount() === 0) {
return undefined;
}

return [...this.getChildren()].reverse().find((item: Element) => {
return item.isVisible();
});
}

protected addLazyLoadWhenLastIsVisible(itemView: Element): void {
Expand Down

0 comments on commit d0602ec

Please sign in to comment.