mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-23 22:17:40 +08:00
refactor(infinite-scroll): use stencil listeners
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import { Component, Element, Event, EventEmitter, HostElement, Method, Prop, PropDidChange, State } from '@stencil/core';
|
import { Component, Element, Event, EventEmitter, HostElement, Listen, Method, Prop, PropDidChange, State } from '@stencil/core';
|
||||||
import { ScrollDetail } from '../../index';
|
import { ScrollDetail } from '../../index';
|
||||||
|
|
||||||
const enum Position {
|
const enum Position {
|
||||||
@ -146,7 +146,6 @@ const enum Position {
|
|||||||
})
|
})
|
||||||
export class InfiniteScroll {
|
export class InfiniteScroll {
|
||||||
|
|
||||||
private rmListener: Function;
|
|
||||||
private thrPx: number = 0;
|
private thrPx: number = 0;
|
||||||
private thrPc: number = 0.15;
|
private thrPc: number = 0.15;
|
||||||
private init: boolean = false;
|
private init: boolean = false;
|
||||||
@ -233,8 +232,8 @@ export class InfiniteScroll {
|
|||||||
this.scrollEl = null;
|
this.scrollEl = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ******** DOM READ ****************
|
@Listen('ionScroll', {enabled: false})
|
||||||
private onScroll(ev: CustomEvent) {
|
protected onScroll(ev: CustomEvent) {
|
||||||
const detail = ev.detail as ScrollDetail;
|
const detail = ev.detail as ScrollDetail;
|
||||||
if (!this.canStart()) {
|
if (!this.canStart()) {
|
||||||
return 1;
|
return 1;
|
||||||
@ -355,18 +354,7 @@ export class InfiniteScroll {
|
|||||||
if (!this.init) {
|
if (!this.init) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (shouldListen) {
|
Context.enableListener(this, 'ionScroll', shouldListen, this.scrollEl);
|
||||||
if (!this.rmListener) {
|
|
||||||
const onScroll = this.onScroll.bind(this);
|
|
||||||
this.scrollEl.addEventListener('ionScroll', onScroll);
|
|
||||||
this.rmListener = () => {
|
|
||||||
this.scrollEl.removeEventListener('ionScroll', onScroll);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.rmListener && this.rmListener();
|
|
||||||
this.rmListener = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hostData() {
|
hostData() {
|
||||||
|
Reference in New Issue
Block a user