Skip to content

Commit 6d859f4

Browse files
committed
fix(popup): fix alignment, backdrop not fading out
1 parent 488e97b commit 6d859f4

File tree

3 files changed

+49
-59
lines changed

3 files changed

+49
-59
lines changed

Diff for: js/angular/service/popup.js

+14-24
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11

22
var POPUP_TPL =
3-
'<div class="popup">' +
4-
'<div class="popup-head">' +
5-
'<h3 class="popup-title" ng-bind-html="title"></h3>' +
6-
'<h5 class="popup-sub-title" ng-bind-html="subTitle" ng-if="subTitle"></h5>' +
7-
'</div>' +
8-
'<div class="popup-body">' +
9-
'</div>' +
10-
'<div class="popup-buttons row">' +
11-
'<button ng-repeat="button in buttons" ng-click="$buttonTapped(button, $event)" class="button col" ng-class="button.type || \'button-default\'" ng-bind-html="button.text"></button>' +
3+
'<div class="popup-container">' +
4+
'<div class="popup">' +
5+
'<div class="popup-head">' +
6+
'<h3 class="popup-title" ng-bind-html="title"></h3>' +
7+
'<h5 class="popup-sub-title" ng-bind-html="subTitle" ng-if="subTitle"></h5>' +
8+
'</div>' +
9+
'<div class="popup-body">' +
10+
'</div>' +
11+
'<div class="popup-buttons">' +
12+
'<button ng-repeat="button in buttons" ng-click="$buttonTapped(button, $event)" class="button" ng-class="button.type || \'button-default\'" ng-bind-html="button.text"></button>' +
13+
'</div>' +
1214
'</div>' +
1315
'</div>';
1416

@@ -114,7 +116,7 @@ IonicModule
114116
function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $document, $compile, $ionicPlatform) {
115117
//TODO allow this to be configured
116118
var config = {
117-
stackPushDelay: 50
119+
stackPushDelay: 75
118120
};
119121
var popupStack = [];
120122
var $ionicPopup = {
@@ -322,20 +324,8 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $docume
322324
//if hidden while waiting for raf, don't show
323325
if (!self.isShown) return;
324326

325-
//if the popup is taller than the window, make the popup body scrollable
326-
if(self.element[0].offsetHeight > window.innerHeight - 20){
327-
self.element[0].style.height = window.innerHeight - 20+'px';
328-
popupBody = self.element[0].querySelectorAll('.popup-body');
329-
popupHead = self.element[0].querySelectorAll('.popup-head');
330-
popupButtons = self.element[0].querySelectorAll('.popup-buttons');
331-
self.element.addClass('popup-tall');
332-
newHeight = window.innerHeight - popupHead[0].offsetHeight - popupButtons[0].offsetHeight -20;
333-
popupBody[0].style.height = newHeight + 'px';
334-
}
335-
336327
self.element.removeClass('popup-hidden');
337328
self.element.addClass('popup-showing active');
338-
ionic.DomUtil.centerElementByMarginTwice(self.element[0]);
339329
focusInput(self.element);
340330
});
341331
};
@@ -382,6 +372,7 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $docume
382372
//Add popup-open & backdrop if this is first popup
383373
document.body.classList.add('popup-open');
384374
$ionicBackdrop.retain();
375+
//only show the backdrop on the first popup
385376
$ionicPopup._backButtonActionDone = $ionicPlatform.registerBackButtonAction(
386377
onHardwareBackButton,
387378
PLATFORM_BACK_BUTTON_PRIORITY_POPUP
@@ -408,10 +399,9 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $docume
408399
} else {
409400
//Remove popup-open & backdrop if this is last popup
410401
document.body.classList.remove('popup-open');
402+
$ionicBackdrop.release();
411403
($ionicPopup._backButtonActionDone || angular.noop)();
412404
}
413-
// always release the backdrop since it has an internal backdrop counter
414-
$ionicBackdrop.release();
415405
return result;
416406
});
417407
});

Diff for: scss/_popup.scss

+34-26
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,52 @@
44
* --------------------------------------------------
55
*/
66

7-
.popup {
8-
position: fixed;
9-
top: 50%;
10-
left: 50%;
7+
.popup-container {
8+
position: absolute;
9+
top: 0;
10+
left: 0;
11+
bottom: 0;
12+
right: 0;
13+
background: rgba(0,0,0,0);
14+
pointer-events: none;
15+
16+
@include display-flex();
17+
@include justify-content(center);
18+
@include align-items(center);
19+
1120
z-index: $z-index-popup;
1221

1322
// Start hidden
1423
visibility: hidden;
24+
&.popup-showing {
25+
visibility: visible;
26+
}
1527

16-
width: $popup-width;
17-
max-width: 100%;
18-
19-
border-radius: $popup-border-radius;
20-
background-color: $popup-background-color;
21-
22-
&.popup-hidden {
28+
&.popup-hidden .popup {
2329
@include animation-name(scaleOut);
2430
@include animation-duration($popup-leave-animation-duration);
2531
@include animation-timing-function(ease-in-out);
2632
@include animation-fill-mode(both);
2733
}
2834

29-
&.popup-showing {
30-
visibility: visible;
31-
}
32-
33-
&.active {
35+
&.active .popup {
3436
@include animation-name(superScaleIn);
3537
@include animation-duration($popup-enter-animation-duration);
3638
@include animation-timing-function(ease-in-out);
3739
@include animation-fill-mode(both);
3840
}
39-
&.popup-tall{
40-
overflow:hidden;
41-
.popup-body{
42-
overflow:auto;
43-
}
41+
42+
.popup {
43+
width: $popup-width;
44+
max-width: 100%;
45+
max-height: 90%;
46+
pointer-events: auto;
47+
48+
border-radius: $popup-border-radius;
49+
background-color: $popup-background-color;
50+
51+
@include display-flex();
52+
@include flex-direction(column);
4453
}
4554
}
4655

@@ -62,18 +71,17 @@
6271
}
6372
.popup-body {
6473
padding: 10px;
74+
overflow: scroll;
6575
}
6676

6777
.popup-buttons {
68-
&.row {
69-
padding: 10px 10px;
70-
}
71-
7278
@include display-flex();
7379
@include flex-direction(row);
80+
padding: 10px;
81+
min-height: $popup-button-min-height + 20;
7482

7583
.button {
76-
margin: 0px 5px;
84+
@include flex(1);
7785
min-height: $popup-button-min-height;
7886
border-radius: $popup-button-border-radius;
7987
line-height: $popup-button-line-height;

Diff for: test/unit/angular/service/popup.unit.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ describe('$ionicPopup service', function() {
252252
expect(previousPopup.show).toHaveBeenCalled();
253253
}));
254254

255-
it('should always release backdrop and remove popup-open and deregister back if no previous', inject(function($q, $timeout, $ionicBackdrop, $ionicPlatform) {
255+
it('should release backdrop and remove popup-open and deregister back if no previous', inject(function($q, $timeout, $ionicBackdrop, $ionicPlatform) {
256256
var fakePopup = {
257257
show: jasmine.createSpy('show'),
258258
remove: jasmine.createSpy('remove'),
@@ -269,14 +269,6 @@ describe('$ionicPopup service', function() {
269269
expect(backDoneSpy).toHaveBeenCalled();
270270
expect(document.body.classList.contains('popup-open')).toBe(false);
271271
}));
272-
it('backdrop release should be called even if there are multiple popups', inject(function($q, $timeout, $ionicBackdrop) {
273-
popup = $ionicPopup.show();
274-
popup2 = $ionicPopup.show();
275-
spyOn($ionicBackdrop, 'release');
276-
popup.close();
277-
$timeout.flush();
278-
expect($ionicBackdrop.release).toHaveBeenCalled();
279-
}));
280272
it('template should only overwrite prompt input if it includes html', inject(function($timeout) {
281273
spyOn($ionicPopup, '_createPopup');
282274
$ionicPopup.prompt({template: "Tacos!"});

0 commit comments

Comments
 (0)