diff --git a/core/src/components/infinite-scroll/infinite-scroll.tsx b/core/src/components/infinite-scroll/infinite-scroll.tsx index 6e9b07f541..e28fe6b597 100644 --- a/core/src/components/infinite-scroll/infinite-scroll.tsx +++ b/core/src/components/infinite-scroll/infinite-scroll.tsx @@ -29,7 +29,8 @@ export class InfiniteScroll implements ComponentInterface { @Prop() threshold = '15%'; @Watch('threshold') - protected thresholdChanged(val: string) { + protected thresholdChanged() { + const val = this.threshold; if (val.lastIndexOf('%') > -1) { this.thrPx = 0; this.thrPc = (parseFloat(val) / 100); @@ -53,10 +54,12 @@ export class InfiniteScroll implements ComponentInterface { @Watch('disabled') protected disabledChanged() { - if (this.disabled) { + const disabled = this.disabled; + if (disabled) { this.isLoading = false; this.isBusy = false; } + this.enableScrollEvents(!disabled); } /** @@ -79,7 +82,8 @@ export class InfiniteScroll implements ComponentInterface { await contentEl.componentOnReady(); this.scrollEl = await contentEl.getScrollElement(); } - this.thresholdChanged(this.threshold); + this.thresholdChanged(); + this.disabledChanged(); if (this.position === 'top') { writeTask(() => { if (this.scrollEl) { @@ -90,6 +94,7 @@ export class InfiniteScroll implements ComponentInterface { } componentDidUnload() { + this.enableScrollEvents(false); this.scrollEl = undefined; } @@ -199,16 +204,26 @@ export class InfiniteScroll implements ComponentInterface { ); } + private enableScrollEvents(shouldListen: boolean) { + if (this.scrollEl) { + if (shouldListen) { + this.scrollEl.addEventListener('scroll', this.onScroll); + } else { + this.scrollEl.removeEventListener('scroll', this.onScroll); + } + } + } + render() { const mode = getIonMode(this); + const disabled = this.disabled; return ( ); }