Skip to content

Commit fe04c51

Browse files
committed
fix(infinitescroll): always check on scroll change
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.
1 parent f1348ad commit fe04c51

File tree

2 files changed

+3
-25
lines changed

2 files changed

+3
-25
lines changed

ionic/components/infinite-scroll/infinite-scroll.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,6 @@ export class InfiniteScroll {
168168

169169
let d = this._content.getContentDimensions();
170170

171-
if (d.scrollTop <= this._highestY) {
172-
// don't bother if scrollY is less than the highest Y seen
173-
return 4;
174-
}
175-
this._highestY = d.scrollTop;
176-
177171
let reloadY = d.contentHeight;
178172
if (this._thrPc) {
179173
reloadY += (reloadY * this._thrPc);
@@ -213,17 +207,15 @@ export class InfiniteScroll {
213207
* trying to receive new data while scrolling. This method is useful
214208
* when it is known that there is no more data that can be added, and
215209
* the infinite scroll is no longer needed.
216-
* @param {boolean} shouldEnable If the infinite scroll should be enabled or not. Setting to `false` will remove scroll event listeners and hide the display.
210+
* @param {boolean} shouldEnable If the infinite scroll should be
211+
* enabled or not. Setting to `false` will remove scroll event listeners
212+
* and hide the display.
217213
*/
218214
enable(shouldEnable: boolean) {
219215
this.state = (shouldEnable ? STATE_ENABLED : STATE_DISABLED);
220216
this._setListeners(shouldEnable);
221217
}
222218

223-
resetHighestY() {
224-
this._highestY = 0;
225-
}
226-
227219
private _setListeners(shouldListen: boolean) {
228220
if (this._init) {
229221
if (shouldListen) {

ionic/components/infinite-scroll/test/infinite-scroll.spec.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ describe('Infinite Scroll', () => {
1111
content.getContentDimensions = function() {
1212
return { scrollHeight: 1000, scrollTop: 350, contentHeight: 500 };
1313
};
14-
inf._highestY = 0;
1514
inf.threshold = '100px';
1615

1716
setInfiniteScrollTop(300);
@@ -25,7 +24,6 @@ describe('Infinite Scroll', () => {
2524
content.getContentDimensions = function() {
2625
return { scrollHeight: 1000, scrollTop: 500, contentHeight: 500 };
2726
};
28-
inf._highestY = 0;
2927
inf.threshold = '100px';
3028

3129
setInfiniteScrollTop(300);
@@ -34,18 +32,6 @@ describe('Infinite Scroll', () => {
3432
expect(result).toEqual(5);
3533
});
3634

37-
it('should not continue if the scrolltop is <= the highest Y', () => {
38-
inf._highestY = 100;
39-
setInfiniteScrollTop(50);
40-
setInfiniteScrollHeight(100);
41-
content.getContentDimensions = function() {
42-
return { scrollTop: 50 };
43-
};
44-
45-
var result = inf._onScroll(scrollEv());
46-
expect(result).toEqual(4);
47-
});
48-
4935
it('should not run if there is not infinite element height', () => {
5036
setInfiniteScrollTop(0);
5137
var result = inf._onScroll(scrollEv());

0 commit comments

Comments
 (0)