Skip to content

Commit

Permalink
fix(collectionRepeat): rerender when $ionicScrollDelegate resizes
Browse files Browse the repository at this point in the history
Fixes #1777
  • Loading branch information
ajoslin committed Aug 11, 2014
1 parent 9a1f3d7 commit 5e025fb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion js/angular/controller/scrollController.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ function($scope, scrollViewOptions, $timeout, $window, $$scrollValueCache, $loca
};

this.resize = function() {
return $timeout(resize);
return $timeout(resize).then(function() {
$element.triggerHandler('scroll.resize');
});
};

this.scrollTop = function(shouldAnimate) {
Expand Down
8 changes: 5 additions & 3 deletions js/angular/directive/collectionRepeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ function($collectionRepeatManager, $collectionDataSource, $parse) {
var beforeSiblings = [];
var afterSiblings = [];
var before = true;

forEach(scrollViewContent.children, function(node, i) {
if ( ionic.DomUtil.elementIsDescendant($element[0], node, scrollViewContent) ) {
before = false;
Expand All @@ -248,16 +249,17 @@ function($collectionRepeatManager, $collectionDataSource, $parse) {
dataSource.setData(value, beforeSiblings, afterSiblings);
collectionRepeatManager.resize();
}
function onWindowResize() {
function rerenderOnResize() {
rerender($scope.$eval(listExpr));
}

ionic.on('resize', onWindowResize, window);
scrollCtrl.$element.on('scroll.resize', rerenderOnResize);
ionic.on('resize', rerenderOnResize, window);

$scope.$on('$destroy', function() {
collectionRepeatManager.destroy();
dataSource.destroy();
ionic.off('resize', onWindowResize, window);
ionic.off('resize', rerenderOnResize, window);
});
}
};
Expand Down
10 changes: 10 additions & 0 deletions test/unit/angular/directive/collectionRepeat.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ describe('collectionRepeat directive', function() {
expect(scrollView.resize.callCount).toBe(1);
});

it('should rerender on scrollCtrl resize', inject(function($timeout) {
var el = setup('collection-repeat="item in items" collection-item-height="50"');
var scrollCtrl = el.controller('$ionicScroll');
repeatManager.resize.reset();

scrollCtrl.resize();
$timeout.flush();
expect(repeatManager.resize.callCount).toBe(1);
}));

it('$destroy', function() {
var el = setup('collection-repeat="item in items" collection-item-height="50"');
dataSource.destroy = jasmine.createSpy('dataSourceDestroy');
Expand Down

0 comments on commit 5e025fb

Please sign in to comment.