Skip to content

Commit

Permalink
fix(infinitescroll): always check on scroll change
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adamdbradley committed Mar 12, 2016
1 parent f1348ad commit fe04c51
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 25 deletions.
14 changes: 3 additions & 11 deletions ionic/components/infinite-scroll/infinite-scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 0 additions & 14 deletions ionic/components/infinite-scroll/test/infinite-scroll.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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());
Expand Down

0 comments on commit fe04c51

Please sign in to comment.