Skip to content

Commit

Permalink
refactor(modal): trigger resize event on the window when modal opens
Browse files Browse the repository at this point in the history
A better approach to resolving an issue with collection-repeat sizing itself properly. This keeps directives independent of eachother.
  • Loading branch information
perrygovier committed Jul 24, 2014
1 parent 1fbd3c5 commit 4f6d02c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 23 deletions.
5 changes: 0 additions & 5 deletions js/angular/directive/collectionRepeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,6 @@ function($collectionRepeatManager, $collectionDataSource, $parse) {
rerender($scope.$eval(listExpr));
}

// for lists inside a modal, recalc when the modal is shown
$scope.$on('modal.shown',function(){
onWindowResize();
});

ionic.on('resize', onWindowResize, window);

$scope.$on('$destroy', function() {
Expand Down
1 change: 1 addition & 0 deletions js/angular/service/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTempla

$timeout(function(){
modalEl.addClass('ng-enter-active');
ionic.trigger('resize');
self.scope.$parent && self.scope.$parent.$broadcast('modal.shown', self);
self.el.classList.add('active');
}, 20);
Expand Down
18 changes: 0 additions & 18 deletions test/unit/angular/directive/collectionRepeat.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,6 @@ describe('collectionRepeat directive', function() {
expect(scrollView.resize.callCount).toBe(1);
});

it('should rerender on modal popup', function() {
inject(function($rootScope) {
var el = setup('collection-repeat="item in items" collection-item-height="50"');
var scrollView = el.controller('$ionicScroll').scrollView;
spyOn(scrollView, 'resize');
dataSource.setData.reset();
repeatManager.resize.reset();

el.scope().items = [1, 2, 3];

$rootScope.$broadcast('modal.shown');

expect(dataSource.setData).toHaveBeenCalledWith(el.scope().items);
expect(repeatManager.resize.callCount).toBe(1);
expect(scrollView.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
8 changes: 8 additions & 0 deletions test/unit/angular/service/modal.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ describe('Ionic Modal', function() {
expect(instance.isShown()).toBe(false);
});

it('should trigger a resize event', function() {
var instance = modal.fromTemplate('<div class="modal">hello</div>');
spyOn(ionic, 'trigger');
instance.show();
timeout.flush();
expect(ionic.trigger).toHaveBeenCalledWith('resize');
});

it('should set isShown on remove', function() {
var instance = modal.fromTemplate('<div class="modal">hello</div>');
expect(instance.isShown()).toBe(false);
Expand Down

0 comments on commit 4f6d02c

Please sign in to comment.