Skip to content

Commit 6ee9e26

Browse files
committed
fix(infiniteScroll): prevent checkbounds when infinitescroll completes when page is cached. Fixes #2694
1 parent c602cde commit 6ee9e26

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Diff for: js/angular/controller/infiniteScrollController.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ function($scope, $attrs, $element, $timeout) {
4444
});
4545
$timeout(function() {
4646
if (self.jsScrolling) self.scrollView.resize();
47-
self.checkBounds();
47+
// only check bounds again immediately if the page isn't cached (scroll el has height)
48+
if (self.scrollView.__container && self.scrollView.__container.offsetHeight > 0) {
49+
self.checkBounds();
50+
}
4851
}, 30, false);
4952
self.isLoading = false;
5053
}
@@ -116,4 +119,7 @@ function($scope, $attrs, $element, $timeout) {
116119
maximum - parseFloat(distance);
117120
}
118121

122+
//for testing
123+
self.__finishInfiniteScroll = finishInfiniteScroll;
124+
119125
}]);

Diff for: test/unit/angular/directive/infiniteScroll.unit.js

+17
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,23 @@ describe('ionicInfiniteScroll directive', function() {
316316
expect(el.controller('ionInfiniteScroll').checkBounds).not.toHaveBeenCalled();
317317
}));
318318

319+
it('should checkbounds on complete if the page is still active', inject(function($timeout) {
320+
var el = setupJS();
321+
322+
el.controller('ionInfiniteScroll').scrollView.__container = {offsetHeight:50};
323+
spyOn(el.controller('ionInfiniteScroll'),'checkBounds');
324+
el.controller('ionInfiniteScroll').__finishInfiniteScroll();
325+
$timeout.flush();
326+
expect(el.controller('ionInfiniteScroll').checkBounds).toHaveBeenCalled();
327+
expect(el.controller('ionInfiniteScroll').checkBounds.callCount).toBe(2);
328+
329+
el.controller('ionInfiniteScroll').scrollView.__container = {offsetHeight:0};
330+
el.controller('ionInfiniteScroll').__finishInfiniteScroll();
331+
$timeout.flush();
332+
expect(el.controller('ionInfiniteScroll').checkBounds.callCount).toBe(2);
333+
334+
}));
335+
319336
it('scroll.infiniteScrollComplete should work', inject(function($timeout) {
320337
var el = setupJS();
321338
ctrl.isLoading = true;

0 commit comments

Comments
 (0)