Skip to content

Commit

Permalink
fix(infiniteScroll): prevent checkbounds when infinitescroll complete…
Browse files Browse the repository at this point in the history
…s when page is cached. Fixes #2694
  • Loading branch information
perrygovier committed Apr 16, 2015
1 parent c602cde commit 6ee9e26
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion js/angular/controller/infiniteScrollController.js
Expand Up @@ -44,7 +44,10 @@ function($scope, $attrs, $element, $timeout) {
});
$timeout(function() {
if (self.jsScrolling) self.scrollView.resize();
self.checkBounds();
// only check bounds again immediately if the page isn't cached (scroll el has height)
if (self.scrollView.__container && self.scrollView.__container.offsetHeight > 0) {
self.checkBounds();
}
}, 30, false);
self.isLoading = false;
}
Expand Down Expand Up @@ -116,4 +119,7 @@ function($scope, $attrs, $element, $timeout) {
maximum - parseFloat(distance);
}

//for testing
self.__finishInfiniteScroll = finishInfiniteScroll;

}]);
17 changes: 17 additions & 0 deletions test/unit/angular/directive/infiniteScroll.unit.js
Expand Up @@ -316,6 +316,23 @@ describe('ionicInfiniteScroll directive', function() {
expect(el.controller('ionInfiniteScroll').checkBounds).not.toHaveBeenCalled();
}));

it('should checkbounds on complete if the page is still active', inject(function($timeout) {
var el = setupJS();

el.controller('ionInfiniteScroll').scrollView.__container = {offsetHeight:50};
spyOn(el.controller('ionInfiniteScroll'),'checkBounds');
el.controller('ionInfiniteScroll').__finishInfiniteScroll();
$timeout.flush();
expect(el.controller('ionInfiniteScroll').checkBounds).toHaveBeenCalled();
expect(el.controller('ionInfiniteScroll').checkBounds.callCount).toBe(2);

el.controller('ionInfiniteScroll').scrollView.__container = {offsetHeight:0};
el.controller('ionInfiniteScroll').__finishInfiniteScroll();
$timeout.flush();
expect(el.controller('ionInfiniteScroll').checkBounds.callCount).toBe(2);

}));

it('scroll.infiniteScrollComplete should work', inject(function($timeout) {
var el = setupJS();
ctrl.isLoading = true;
Expand Down

0 comments on commit 6ee9e26

Please sign in to comment.