mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
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.
This commit is contained in:
5
js/angular/directive/collectionRepeat.js
vendored
5
js/angular/directive/collectionRepeat.js
vendored
@@ -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() {
|
||||
|
||||
1
js/angular/service/modal.js
vendored
1
js/angular/service/modal.js
vendored
@@ -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);
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user