1
+ import { Component , DynamicComponentLoader , ViewChild , ViewContainerRef } from '@angular/core' ;
2
+
3
+ import { NavParams } from '../nav/nav-params' ;
1
4
import { ViewController } from '../nav/view-controller' ;
2
5
import { Animation } from '../../animations/animation' ;
3
6
import { Transition , TransitionOptions } from '../../transitions/transition' ;
@@ -103,8 +106,9 @@ import {Transition, TransitionOptions} from '../../transitions/transition';
103
106
*/
104
107
export class Modal extends ViewController {
105
108
106
- constructor ( componentType , data = { } ) {
107
- super ( componentType , data ) ;
109
+ constructor ( componentType , data : any = { } ) {
110
+ data . componentToPresent = componentType ;
111
+ super ( ModalComponent , data ) ;
108
112
this . viewType = 'modal' ;
109
113
this . isOverlay = true ;
110
114
}
@@ -127,19 +131,50 @@ export class Modal extends ViewController {
127
131
128
132
}
129
133
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
+ }
130
158
131
159
/**
132
160
* Animations for modals
133
161
*/
134
162
class ModalSlideIn extends Transition {
135
163
constructor ( enteringView : ViewController , leavingView : ViewController , opts : TransitionOptions ) {
136
164
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%' ) ;
137
171
this
138
172
. element ( enteringView . pageRef ( ) )
139
173
. easing ( 'cubic-bezier(0.36,0.66,0.04,1)' )
140
174
. duration ( 400 )
141
- . fromTo ( 'translateY' , '100%' , '0%' )
142
- . before . addClass ( 'show-page' ) ;
175
+ . before . addClass ( 'show-page' )
176
+ . add ( backdrop )
177
+ . add ( wrapper ) ;
143
178
144
179
if ( enteringView . hasNavbar ( ) ) {
145
180
// entering page has a navbar
@@ -155,11 +190,19 @@ Transition.register('modal-slide-in', ModalSlideIn);
155
190
class ModalSlideOut extends Transition {
156
191
constructor ( enteringView : ViewController , leavingView : ViewController , opts : TransitionOptions ) {
157
192
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
+
158
200
this
159
201
. element ( leavingView . pageRef ( ) )
160
202
. easing ( 'ease-out' )
161
203
. duration ( 250 )
162
- . fromTo ( 'translateY' , '0%' , '100%' ) ;
204
+ . add ( backdrop )
205
+ . add ( wrapper ) ;
163
206
}
164
207
}
165
208
Transition . register ( 'modal-slide-out' , ModalSlideOut ) ;
@@ -168,13 +211,21 @@ Transition.register('modal-slide-out', ModalSlideOut);
168
211
class ModalMDSlideIn extends Transition {
169
212
constructor ( enteringView : ViewController , leavingView : ViewController , opts : TransitionOptions ) {
170
213
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
+
171
221
this
172
222
. element ( enteringView . pageRef ( ) )
173
223
. easing ( 'cubic-bezier(0.36,0.66,0.04,1)' )
174
224
. duration ( 280 )
175
- . fromTo ( 'translateY' , '40px' , '0px' )
176
225
. fadeIn ( )
177
- . before . addClass ( 'show-page' ) ;
226
+ . before . addClass ( 'show-page' )
227
+ . add ( backdrop )
228
+ . add ( wrapper ) ;
178
229
179
230
if ( enteringView . hasNavbar ( ) ) {
180
231
// entering page has a navbar
@@ -190,12 +241,20 @@ Transition.register('modal-md-slide-in', ModalMDSlideIn);
190
241
class ModalMDSlideOut extends Transition {
191
242
constructor ( enteringView : ViewController , leavingView : ViewController , opts : TransitionOptions ) {
192
243
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
+
193
251
this
194
252
. element ( leavingView . pageRef ( ) )
195
253
. duration ( 200 )
196
254
. 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 ) ;
199
258
}
200
259
}
201
260
Transition . register ( 'modal-md-slide-out' , ModalMDSlideOut ) ;
0 commit comments