mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 12:29:55 +08:00
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.
This commit is contained in:
@ -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) {
|
||||
|
@ -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());
|
||||
|
Reference in New Issue
Block a user