From fe04c51866860c9e033c960550f16126305ac58f Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Sat, 12 Mar 2016 02:45:12 -0600 Subject: [PATCH] fix(infinitescroll): always check on scroll change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously infinite scroll would only do checks when it got to scrollTop it’s never seen before. However, this then requires a reset() function if the underlying data changes, which would become an API gotcha that would be a common source of problems for developers. Always checking on scroll change should have little performance impact since it was always checking while scrolling down anyway, it just wasn’t checking when scrolling up. Now it always checks. --- .../components/infinite-scroll/infinite-scroll.ts | 14 +++----------- .../infinite-scroll/test/infinite-scroll.spec.ts | 14 -------------- 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/ionic/components/infinite-scroll/infinite-scroll.ts b/ionic/components/infinite-scroll/infinite-scroll.ts index 8f598245e12..46e2fed0862 100644 --- a/ionic/components/infinite-scroll/infinite-scroll.ts +++ b/ionic/components/infinite-scroll/infinite-scroll.ts @@ -168,12 +168,6 @@ export class InfiniteScroll { let d = this._content.getContentDimensions(); - if (d.scrollTop <= this._highestY) { - // don't bother if scrollY is less than the highest Y seen - return 4; - } - this._highestY = d.scrollTop; - let reloadY = d.contentHeight; if (this._thrPc) { reloadY += (reloadY * this._thrPc); @@ -213,17 +207,15 @@ export class InfiniteScroll { * 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. + * @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); } - resetHighestY() { - this._highestY = 0; - } - private _setListeners(shouldListen: boolean) { if (this._init) { if (shouldListen) { diff --git a/ionic/components/infinite-scroll/test/infinite-scroll.spec.ts b/ionic/components/infinite-scroll/test/infinite-scroll.spec.ts index fdfd049b205..8766577e697 100644 --- a/ionic/components/infinite-scroll/test/infinite-scroll.spec.ts +++ b/ionic/components/infinite-scroll/test/infinite-scroll.spec.ts @@ -11,7 +11,6 @@ describe('Infinite Scroll', () => { content.getContentDimensions = function() { return { scrollHeight: 1000, scrollTop: 350, contentHeight: 500 }; }; - inf._highestY = 0; inf.threshold = '100px'; setInfiniteScrollTop(300); @@ -25,7 +24,6 @@ describe('Infinite Scroll', () => { content.getContentDimensions = function() { return { scrollHeight: 1000, scrollTop: 500, contentHeight: 500 }; }; - inf._highestY = 0; inf.threshold = '100px'; setInfiniteScrollTop(300); @@ -34,18 +32,6 @@ describe('Infinite Scroll', () => { expect(result).toEqual(5); }); - it('should not continue if the scrolltop is <= the highest Y', () => { - inf._highestY = 100; - setInfiniteScrollTop(50); - setInfiniteScrollHeight(100); - content.getContentDimensions = function() { - return { scrollTop: 50 }; - }; - - var result = inf._onScroll(scrollEv()); - expect(result).toEqual(4); - }); - it('should not run if there is not infinite element height', () => { setInfiniteScrollTop(0); var result = inf._onScroll(scrollEv());