Skip to content

Commit

Permalink
fix(virtual-scroll): fix viewportOffset calculation
Browse files Browse the repository at this point in the history
fixes #14963
  • Loading branch information
manucorporat committed Aug 11, 2018
1 parent 89e8256 commit b7e741a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions core/src/components/virtual-scroll/test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<ion-button onclick="addItems()">Add Items</ion-button>
</ion-buttons>
</ion-toolbar>
<ion-toolbar></ion-toolbar>
<ion-toolbar></ion-toolbar>
<ion-toolbar></ion-toolbar>
<ion-toolbar></ion-toolbar>
</ion-header>

<ion-content>
Expand Down
7 changes: 5 additions & 2 deletions core/src/components/virtual-scroll/virtual-scroll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Range, calcCells, calcHeightIndex, doRender, findCellIndex, getRange, g
})
export class VirtualScroll {

private contentEl?: HTMLElement;
private scrollEl?: HTMLElement;
private range: Range = { offset: 0, length: 0 };
private timerUpdate: any;
Expand Down Expand Up @@ -121,6 +122,7 @@ export class VirtualScroll {
}
await contentEl.componentOnReady();

this.contentEl = contentEl;
this.scrollEl = contentEl.getScrollElement();
this.calcCells();
this.updateState();
Expand Down Expand Up @@ -215,14 +217,15 @@ export class VirtualScroll {
}

private readVS() {
const { scrollEl, el } = this;
const { contentEl, scrollEl, el } = this;
let topOffset = 0;
let node: HTMLElement | null = el;
while (node && node !== scrollEl) {
while (node && node !== contentEl) {
topOffset += node.offsetTop;
node = node.parentElement;
}
this.viewportOffset = topOffset;
console.log(this.viewportOffset);
if (scrollEl) {
this.viewportHeight = scrollEl.offsetHeight;
this.currentScrollTop = scrollEl.scrollTop;
Expand Down

0 comments on commit b7e741a

Please sign in to comment.