Skip to content

Commit a658524

Browse files
danbucholtzadamdbradley
authored andcommitted
feat(modal): add inset modal feature
* feat(inset-modal): add dynamic component loading functionality for inset modal * style(modal): moved border-radius to a variable, added an additional data binding activity in moved border-radius to a variable, added an additional data binding activity in an e2e test * refactor(modal): refactor sass and remove some unnecessary stuff * refactor(modal): migrate to Angular RC import syntax Closes #5423
1 parent ece1eba commit a658524

File tree

6 files changed

+153
-30
lines changed

6 files changed

+153
-30
lines changed

ionic/components/modal/modal.ios.scss

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@
44
// --------------------------------------------------
55

66
$modal-ios-background-color: $background-ios-color !default;
7+
$modal-ios-border-radius: 5px !default;
78

8-
9-
ion-page.modal {
9+
.modal ion-page {
1010
background-color: $modal-ios-background-color;
1111
}
12+
13+
.modal-wrapper {
14+
@media only screen and (min-width: 768px) and (min-height: 600px) {
15+
overflow: hidden;
16+
17+
border-radius: $modal-ios-border-radius;
18+
}
19+
}

ionic/components/modal/modal.md.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
$modal-md-background-color: $background-md-color !default;
77

88

9-
ion-page.modal {
9+
.modal ion-page {
1010
background-color: $modal-md-background-color;
1111
}

ionic/components/modal/modal.scss

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,54 @@
33
// Modals
44
// --------------------------------------------------
55

6-
ion-page.modal {
7-
z-index: $z-index-overlay;
6+
$modal-inset-min-width: 768px !default;
7+
$modal-inset-min-height-small: 600px !default;
8+
$modal-inset-min-height-large: 768px !default;
9+
$modal-inset-width: 600px !default;
10+
$modal-inset-height-small: 500px !default;
11+
$modal-inset-height-large: 600px !default;
812

9-
// hidden by default to prevent flickers, the animation will show it
10-
transform: translate3d(0, 100%, 0);
13+
.modal {
14+
position: absolute;
15+
top: 0;
16+
left: 0;
1117

12-
@media only screen and (min-width: 768px) and (min-height: 600px){
18+
display: block;
19+
20+
width: 100%;
21+
height: 100%;
22+
23+
.backdrop {
24+
@media not all and (min-width: $modal-inset-min-width) and (min-height: $modal-inset-min-height-small) {
25+
display: none;
26+
}
27+
}
28+
}
29+
30+
.modal-wrapper {
31+
z-index: 10;
32+
33+
height: 100%;
34+
35+
@media only screen and (min-width: $modal-inset-min-width) and (min-height: $modal-inset-min-height-small) {
1336
position: absolute;
14-
top: calc(50% - 250px);
15-
left: calc(50% - 300px);
37+
top: calc(50% - (#{$modal-inset-height-small}/2));
38+
left: calc(50% - (#{$modal-inset-width}/2));
1639

17-
width: 600px;
18-
height: 500px;
40+
width: $modal-inset-width;
41+
height: $modal-inset-height-small;
1942
}
2043

21-
@media only screen and (min-width: 768px) and (min-height: 768px){
44+
@media only screen and (min-width: $modal-inset-min-width) and (min-height: $modal-inset-min-height-large) {
2245
position: absolute;
23-
top: calc(50% - 300px);
24-
left: calc(50% - 300px);
46+
top: calc(50% - (#{$modal-inset-height-large}/2));
47+
left: calc(50% - (#{$modal-inset-width}/2));
2548

26-
width: 600px;
27-
height: 600px;
49+
width: $modal-inset-width;
50+
height: $modal-inset-height-large;
2851
}
2952
}
53+
54+
.show-page ion-page {
55+
display: flex;
56+
}

ionic/components/modal/modal.ts

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import {Component, DynamicComponentLoader, ViewChild, ViewContainerRef} from '@angular/core';
2+
3+
import {NavParams} from '../nav/nav-params';
14
import {ViewController} from '../nav/view-controller';
25
import {Animation} from '../../animations/animation';
36
import {Transition, TransitionOptions} from '../../transitions/transition';
@@ -103,8 +106,9 @@ import {Transition, TransitionOptions} from '../../transitions/transition';
103106
*/
104107
export class Modal extends ViewController {
105108

106-
constructor(componentType, data = {}) {
107-
super(componentType, data);
109+
constructor(componentType, data: any = {}) {
110+
data.componentToPresent = componentType;
111+
super(ModalComponent, data);
108112
this.viewType = 'modal';
109113
this.isOverlay = true;
110114
}
@@ -127,19 +131,50 @@ export class Modal extends ViewController {
127131

128132
}
129133

134+
@Component({
135+
selector: 'ion-modal',
136+
template: `
137+
<div class="backdrop"></div>
138+
<div class="modal-wrapper">
139+
<div #wrapper></div>
140+
</div>
141+
`
142+
})
143+
class ModalComponent {
144+
145+
@ViewChild('wrapper', {read: ViewContainerRef}) wrapper: ViewContainerRef;
146+
147+
constructor(private _loader: DynamicComponentLoader, private _navParams: NavParams, private _viewCtrl: ViewController) {
148+
}
149+
150+
ngAfterViewInit() {
151+
let component = this._navParams.data.componentToPresent;
152+
this._loader.loadNextToLocation(component, this.wrapper).then(componentInstance => {
153+
this._viewCtrl.setInstance(componentInstance.instance);
154+
// TODO - validate what life cycle events aren't call and possibly call them here if needed
155+
});
156+
}
157+
}
130158

131159
/**
132160
* Animations for modals
133161
*/
134162
class ModalSlideIn extends Transition {
135163
constructor(enteringView: ViewController, leavingView: ViewController, opts: TransitionOptions) {
136164
super(opts);
165+
166+
let ele = enteringView.pageRef().nativeElement;
167+
let backdrop = new Animation(ele.querySelector('.backdrop'));
168+
backdrop.fromTo('opacity', 0.01, 0.4);
169+
let wrapper = new Animation(ele.querySelector('.modal-wrapper'));
170+
wrapper.fromTo('translateY', '100%', '0%');
137171
this
138172
.element(enteringView.pageRef())
139173
.easing('cubic-bezier(0.36,0.66,0.04,1)')
140174
.duration(400)
141-
.fromTo('translateY', '100%', '0%')
142-
.before.addClass('show-page');
175+
.before.addClass('show-page')
176+
.add(backdrop)
177+
.add(wrapper);
143178

144179
if (enteringView.hasNavbar()) {
145180
// entering page has a navbar
@@ -155,11 +190,19 @@ Transition.register('modal-slide-in', ModalSlideIn);
155190
class ModalSlideOut extends Transition {
156191
constructor(enteringView: ViewController, leavingView: ViewController, opts: TransitionOptions) {
157192
super(opts);
193+
194+
let ele = leavingView.pageRef().nativeElement;
195+
let backdrop = new Animation(ele.querySelector('.backdrop'));
196+
backdrop.fromTo('opacity', 0.4, 0.0);
197+
let wrapper = new Animation(ele.querySelector('.modal-wrapper'));
198+
wrapper.fromTo('translateY', '0%', '100%');
199+
158200
this
159201
.element(leavingView.pageRef())
160202
.easing('ease-out')
161203
.duration(250)
162-
.fromTo('translateY', '0%', '100%');
204+
.add(backdrop)
205+
.add(wrapper);
163206
}
164207
}
165208
Transition.register('modal-slide-out', ModalSlideOut);
@@ -168,13 +211,21 @@ Transition.register('modal-slide-out', ModalSlideOut);
168211
class ModalMDSlideIn extends Transition {
169212
constructor(enteringView: ViewController, leavingView: ViewController, opts: TransitionOptions) {
170213
super(opts);
214+
215+
let ele = enteringView.pageRef().nativeElement;
216+
let backdrop = new Animation(ele.querySelector('.backdrop'));
217+
backdrop.fromTo('opacity', 0.01, 0.4);
218+
let wrapper = new Animation(ele.querySelector('.modal-wrapper'));
219+
wrapper.fromTo('translateY', '40px', '0px');
220+
171221
this
172222
.element(enteringView.pageRef())
173223
.easing('cubic-bezier(0.36,0.66,0.04,1)')
174224
.duration(280)
175-
.fromTo('translateY', '40px', '0px')
176225
.fadeIn()
177-
.before.addClass('show-page');
226+
.before.addClass('show-page')
227+
.add(backdrop)
228+
.add(wrapper);
178229

179230
if (enteringView.hasNavbar()) {
180231
// entering page has a navbar
@@ -190,12 +241,20 @@ Transition.register('modal-md-slide-in', ModalMDSlideIn);
190241
class ModalMDSlideOut extends Transition {
191242
constructor(enteringView: ViewController, leavingView: ViewController, opts: TransitionOptions) {
192243
super(opts);
244+
245+
let ele = leavingView.pageRef().nativeElement;
246+
let backdrop = new Animation(ele.querySelector('.backdrop'));
247+
backdrop.fromTo('opacity', 0.4, 0.0);
248+
let wrapper = new Animation(ele.querySelector('.modal-wrapper'));
249+
wrapper.fromTo('translateY', '0px', '40px');
250+
193251
this
194252
.element(leavingView.pageRef())
195253
.duration(200)
196254
.easing('cubic-bezier(0.47,0,0.745,0.715)')
197-
.fromTo('translateY', '0px', '40px')
198-
.fadeOut();
255+
.fadeOut()
256+
.add(wrapper)
257+
.add(backdrop);
199258
}
200259
}
201260
Transition.register('modal-md-slide-out', ModalMDSlideOut);

ionic/components/modal/modal.wp.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
$modal-wp-background-color: $background-wp-color !default;
77

88

9-
ion-page.modal {
9+
.modal ion-page {
1010
background-color: $modal-wp-background-color;
1111
}

ionic/components/modal/test/basic/index.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {App, Page, Config, Platform} from '../../../../../ionic';
2-
import {Modal, ActionSheet, NavController, NavParams, Transition, TransitionOptions, ViewController} from '../../../../../ionic';;
3-
2+
import {Modal, ActionSheet, NavController, NavParams, Transition, TransitionOptions, ViewController} from '../../../../../ionic';
43

54
@Page({
65
templateUrl: 'main.html'
@@ -105,6 +104,22 @@ class ModalPassData {
105104
submit() {
106105
this.viewCtrl.dismiss(this.data);
107106
}
107+
108+
onPageWillEnter(){
109+
console.log("ModalPassData onPagewillEnter fired");
110+
}
111+
112+
onPageDidEnter(){
113+
console.log("ModalPassData onPageDidEnter fired");
114+
}
115+
116+
onPageWillLeave(){
117+
console.log("ModalPassData onPageWillLeave fired");
118+
}
119+
120+
onPageDidLeave(){
121+
console.log("ModalPassData onPageDidLeave fired");
122+
}
108123
}
109124

110125

@@ -242,11 +257,25 @@ class ContactUs {
242257
</p>
243258
<f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f>
244259
<f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f>
260+
<ion-list>
261+
<ion-item *ngFor="#item of items">
262+
Item Number: {{item.value}}
263+
</ion-item>
264+
</ion-list>
245265
</ion-content>
246266
`
247267
})
248268
class ModalFirstPage {
249-
constructor(private nav: NavController) {}
269+
270+
private items:any[];
271+
constructor(private nav: NavController) {
272+
this.items = [];
273+
for ( let i = 0; i < 50; i++ ){
274+
this.items.push({
275+
value: (i + 1)
276+
});
277+
}
278+
}
250279

251280
push() {
252281
let page = ModalSecondPage;

0 commit comments

Comments
 (0)