Skip to content

Commit 4f6d02c

Browse files
committed
refactor(modal): trigger resize event on the window when modal opens
A better approach to resolving an issue with collection-repeat sizing itself properly. This keeps directives independent of eachother.
1 parent 1fbd3c5 commit 4f6d02c

File tree

4 files changed

+9
-23
lines changed

4 files changed

+9
-23
lines changed

js/angular/directive/collectionRepeat.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,6 @@ function($collectionRepeatManager, $collectionDataSource, $parse) {
225225
rerender($scope.$eval(listExpr));
226226
}
227227

228-
// for lists inside a modal, recalc when the modal is shown
229-
$scope.$on('modal.shown',function(){
230-
onWindowResize();
231-
});
232-
233228
ionic.on('resize', onWindowResize, window);
234229

235230
$scope.$on('$destroy', function() {

js/angular/service/modal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTempla
148148

149149
$timeout(function(){
150150
modalEl.addClass('ng-enter-active');
151+
ionic.trigger('resize');
151152
self.scope.$parent && self.scope.$parent.$broadcast('modal.shown', self);
152153
self.el.classList.add('active');
153154
}, 20);

test/unit/angular/directive/collectionRepeat.unit.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -152,24 +152,6 @@ describe('collectionRepeat directive', function() {
152152
expect(scrollView.resize.callCount).toBe(1);
153153
});
154154

155-
it('should rerender on modal popup', function() {
156-
inject(function($rootScope) {
157-
var el = setup('collection-repeat="item in items" collection-item-height="50"');
158-
var scrollView = el.controller('$ionicScroll').scrollView;
159-
spyOn(scrollView, 'resize');
160-
dataSource.setData.reset();
161-
repeatManager.resize.reset();
162-
163-
el.scope().items = [1, 2, 3];
164-
165-
$rootScope.$broadcast('modal.shown');
166-
167-
expect(dataSource.setData).toHaveBeenCalledWith(el.scope().items);
168-
expect(repeatManager.resize.callCount).toBe(1);
169-
expect(scrollView.resize.callCount).toBe(1);
170-
});
171-
});
172-
173155
it('$destroy', function() {
174156
var el = setup('collection-repeat="item in items" collection-item-height="50"');
175157
dataSource.destroy = jasmine.createSpy('dataSourceDestroy');

test/unit/angular/service/modal.unit.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ describe('Ionic Modal', function() {
4848
expect(instance.isShown()).toBe(false);
4949
});
5050

51+
it('should trigger a resize event', function() {
52+
var instance = modal.fromTemplate('<div class="modal">hello</div>');
53+
spyOn(ionic, 'trigger');
54+
instance.show();
55+
timeout.flush();
56+
expect(ionic.trigger).toHaveBeenCalledWith('resize');
57+
});
58+
5159
it('should set isShown on remove', function() {
5260
var instance = modal.fromTemplate('<div class="modal">hello</div>');
5361
expect(instance.isShown()).toBe(false);

0 commit comments

Comments
 (0)