Skip to content

Commit e9abe7a

Browse files
MayaKirovaMKirovaChronosSFkdinev
authored
fix(virtualization): Use virtual scroll top which takes virtual heig… (#7316)
* fix(virtualization): Use virtual scroll top which takes virtual height to actual height ration when recalculating vertical offset. * chore(*): Recalc virtual height before use. * chore(*): Fix test timing as it has elements with different height, * chore(*): Rename method and use only if browser height is exeeded. * chore(*): Fix lint. Co-authored-by: MKirova <MKirova@DEV-MKIROVA> Co-authored-by: Stamen Stoychev <[email protected]> Co-authored-by: Konstantin Dinev <[email protected]>
1 parent dfbff16 commit e9abe7a

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

projects/igniteui-angular/src/lib/combo/combo.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,8 @@ describe('igxCombo', () => {
750750
scrollIndex += 10;
751751
if (scrollIndex < combo.data.length) {
752752
combo.virtualScrollContainer.scrollTo(scrollIndex);
753-
combo.virtualScrollContainer.onChunkLoad.pipe(take(1)).subscribe(() => {
753+
combo.virtualScrollContainer.onChunkLoad.pipe(take(1)).subscribe(async() => {
754+
await wait(30);
754755
checkGroupedItemsClass();
755756
});
756757
} else {

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -734,13 +734,8 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
734734
if (!parseInt(this.scrollComponent.nativeElement.style.height, 10)) {
735735
return;
736736
}
737-
738-
const containerSize = parseInt(this.igxForContainerSize, 10);
739-
const maxRealScrollTop = event.target.children[0].scrollHeight - containerSize;
740-
const realPercentScrolled = maxRealScrollTop !== 0 ? event.target.scrollTop / maxRealScrollTop : 0;
741737
if (!this._bScrollInternal) {
742-
const maxVirtScrollTop = this._virtHeight - containerSize;
743-
this._virtScrollTop = realPercentScrolled * maxVirtScrollTop;
738+
this._calcVirtualScrollTop(event.target.scrollTop);
744739
} else {
745740
this._bScrollInternal = false;
746741
}
@@ -1340,11 +1335,25 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
13401335
}
13411336
private _updateVScrollOffset() {
13421337
let scrollOffset = 0;
1338+
let currentScrollTop = this.scrollPosition;
1339+
if (this._virtHeightRatio !== 1) {
1340+
this._calcVirtualScrollTop(this.scrollPosition);
1341+
currentScrollTop = this._virtScrollTop;
1342+
}
13431343
const vScroll = this.scrollComponent.nativeElement;
13441344
scrollOffset = vScroll && this.scrollComponent.size ?
1345-
this.scrollPosition - this.sizesCache[this.state.startIndex] : 0;
1345+
currentScrollTop - this.sizesCache[this.state.startIndex] : 0;
13461346
this.dc.instance._viewContainer.element.nativeElement.style.top = -(scrollOffset) + 'px';
13471347
}
1348+
1349+
protected _calcVirtualScrollTop(scrollTop: number) {
1350+
const containerSize = parseInt(this.igxForContainerSize, 10);
1351+
const maxRealScrollTop = this.scrollComponent.size - containerSize;
1352+
const realPercentScrolled = maxRealScrollTop !== 0 ? scrollTop / maxRealScrollTop : 0;
1353+
const maxVirtScrollTop = this._virtHeight - containerSize;
1354+
this._virtScrollTop = realPercentScrolled * maxVirtScrollTop;
1355+
}
1356+
13481357
private _updateHScrollOffset() {
13491358
let scrollOffset = 0;
13501359
scrollOffset = this.scrollComponent.nativeElement &&
@@ -1615,13 +1624,8 @@ export class IgxGridForOfDirective<T> extends IgxForOfDirective<T> implements On
16151624
if (!parseInt(this.scrollComponent.nativeElement.style.height, 10)) {
16161625
return;
16171626
}
1618-
1619-
const containerSize = parseInt(this.igxForContainerSize, 10);
1620-
const maxRealScrollTop = event.target.children[0].scrollHeight - containerSize;
1621-
const realPercentScrolled = maxRealScrollTop !== 0 ? event.target.scrollTop / maxRealScrollTop : 0;
16221627
if (!this._bScrollInternal) {
1623-
const maxVirtScrollTop = this._virtHeight - containerSize;
1624-
this._virtScrollTop = realPercentScrolled * maxVirtScrollTop;
1628+
this._calcVirtualScrollTop(event.target.scrollTop);
16251629
} else {
16261630
this._bScrollInternal = false;
16271631
}

0 commit comments

Comments
 (0)