fix(virtual-scroll): read viewport size for every scroll event

This commit is contained in:
Manu Mtz.-Almeida
2018-07-11 20:17:01 +02:00
parent 2127fa2cec
commit 1d3eb3fabf

View File

@ -125,7 +125,6 @@ export class VirtualScroll {
} }
contentEl.componentOnReady().then(() => { contentEl.componentOnReady().then(() => {
this.scrollEl = contentEl.getScrollElement(); this.scrollEl = contentEl.getScrollElement();
this.calcDimensions();
this.calcCells(); this.calcCells();
this.updateState(); this.updateState();
}); });
@ -147,7 +146,6 @@ export class VirtualScroll {
@Listen('window:resize') @Listen('window:resize')
onResize() { onResize() {
this.indexDirty = 0; this.indexDirty = 0;
this.calcDimensions();
this.calcCells(); this.calcCells();
this.updateVirtualScroll(); this.updateVirtualScroll();
} }
@ -232,6 +230,7 @@ export class VirtualScroll {
} }
this.viewportOffset = topOffset; this.viewportOffset = topOffset;
if (scrollEl) { if (scrollEl) {
this.viewportHeight = scrollEl.offsetHeight;
this.currentScrollTop = scrollEl.scrollTop; this.currentScrollTop = scrollEl.scrollTop;
} }
} }
@ -313,8 +312,7 @@ export class VirtualScroll {
private updateState() { private updateState() {
const shouldEnable = !!( const shouldEnable = !!(
this.scrollEl && this.scrollEl &&
this.cells && this.cells
this.viewportHeight > 1
); );
if (shouldEnable !== this.isEnabled) { if (shouldEnable !== this.isEnabled) {
this.enableScrollEvents(shouldEnable); this.enableScrollEvents(shouldEnable);
@ -360,12 +358,6 @@ export class VirtualScroll {
this.indexDirty = Infinity; this.indexDirty = Infinity;
} }
private calcDimensions() {
if (this.scrollEl) {
this.viewportHeight = this.scrollEl.offsetHeight;
}
}
private enableScrollEvents(shouldListen: boolean) { private enableScrollEvents(shouldListen: boolean) {
if (this.scrollEl) { if (this.scrollEl) {
this.isEnabled = shouldListen; this.isEnabled = shouldListen;