Skip to content

Commit

Permalink
feat(infinite-scroll): it can be enabled/disabled from a ng input
Browse files Browse the repository at this point in the history
references ionic-team#8380
  • Loading branch information
manucorporat committed Oct 1, 2016
1 parent 21eae2e commit 49f4dd3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion demos/src/infinite-scroll/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class ApiDemoApp {
infiniteScroll.complete();

if (this.items.length > 90) {
infiniteScroll.enable(false);
infiniteScroll.enabled = false;
}
});
}
Expand Down
34 changes: 20 additions & 14 deletions src/components/infinite-scroll/infinite-scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,26 @@ export class InfiniteScroll {
}
}

/**
* @input {boolean} Whether or not the infinite scroll should be
* enabled or not. Setting to `false` will remove scroll event listeners
* and hide the display.
*
* Call `enable = false` to disable the infinite scroll from actively
* trying to receive new data while scrolling. This method is useful
* when it is known that there is no more data that can be added, and
* the infinite scroll is no longer needed.
*/
@Input()
get enabled(): boolean {
return this.state !== STATE_DISABLED;
}

set enabled(shouldEnable: boolean) {
this.state = (shouldEnable ? STATE_ENABLED : STATE_DISABLED);
this._setListeners(shouldEnable);
}

/**
* @output {event} The expression to call when the scroll reaches
* the threshold distance. From within your infinite handler,
Expand Down Expand Up @@ -203,20 +223,6 @@ export class InfiniteScroll {
this.state = STATE_ENABLED;
}

/**
* Call `enable(false)` to disable the infinite scroll from actively
* trying to receive new data while scrolling. This method is useful
* when it is known that there is no more data that can be added, and
* the infinite scroll is no longer needed.
* @param {boolean} shouldEnable If the infinite scroll should be
* enabled or not. Setting to `false` will remove scroll event listeners
* and hide the display.
*/
enable(shouldEnable: boolean) {
this.state = (shouldEnable ? STATE_ENABLED : STATE_DISABLED);
this._setListeners(shouldEnable);
}

_setListeners(shouldListen: boolean) {
if (this._init) {
if (shouldListen) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/infinite-scroll/test/basic/app-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class E2EPage1 {

if (this.items.length > 90) {
this.enabled = false;
infiniteScroll.enable(this.enabled);
infiniteScroll.enabled = this.enabled;
}
});
}
Expand All @@ -40,7 +40,7 @@ export class E2EPage1 {

toggleInfiniteScroll() {
this.enabled = !this.enabled;
this.infiniteScroll.enable(this.enabled);
this.infiniteScroll.enabled = this.enabled;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class E2EPage {
infiniteScroll.complete();

if (this.items.length > 90) {
infiniteScroll.enable(false);
infiniteScroll.enabled = false;
}
});
}
Expand Down

0 comments on commit 49f4dd3

Please sign in to comment.