overlay view lifecycle events

This commit is contained in:
Adam Bradley
2015-07-30 13:19:27 -05:00
parent 1bcf110d0f
commit b38f9d17a8
2 changed files with 37 additions and 0 deletions

View File

@ -46,8 +46,30 @@ class MyAppCmp {
}) })
export class ContactModal { export class ContactModal {
constructor() { constructor() {
console.log('ContactModal constructor')
this.rootView = ModalFirstPage; this.rootView = ModalFirstPage;
} }
viewLoaded() {
console.log('ContactModal viewLoaded');
}
viewWillEnter() {
console.log('ContactModal viewWillEnter');
}
viewDidEnter() {
console.log('ContactModal viewDidEnter');
}
viewWillLeave() {
console.log('ContactModal viewWillLeave');
}
viewDidLeave() {
console.log('ContactModal viewDidLeave');
}
viewWillUnload() {
console.log('ContactModal viewWillUnload');
}
viewDidUnload() {
console.log('ContactModal viewDidUnload');
}
} }

View File

@ -74,6 +74,10 @@ export class OverlayRef {
let overlayInstance = (ref && ref.instance); let overlayInstance = (ref && ref.instance);
if (!overlayInstance) return; if (!overlayInstance) return;
this._instance = overlayInstance;
overlayInstance.viewLoaded && overlayInstance.viewLoaded();
this.zIndex = ROOT_Z_INDEX; this.zIndex = ROOT_Z_INDEX;
for (let i = 0; i < app.overlays.length; i++) { for (let i = 0; i < app.overlays.length; i++) {
if (app.overlays[i].zIndex >= this.zIndex) { if (app.overlays[i].zIndex >= this.zIndex) {
@ -92,6 +96,7 @@ export class OverlayRef {
this._handle = opts.handle || this.zIndex; this._handle = opts.handle || this.zIndex;
this._dispose = () => { this._dispose = () => {
this._instance = null;
ref.dispose && ref.dispose(); ref.dispose && ref.dispose();
util.array.remove(app.overlays, this); util.array.remove(app.overlays, this);
}; };
@ -105,6 +110,8 @@ export class OverlayRef {
_open(opts={}) { _open(opts={}) {
return new Promise(resolve => { return new Promise(resolve => {
this._instance.viewWillEnter && this._instance.viewWillEnter();
let animationName = (opts && opts.animation) || this._opts.enterAnimation; let animationName = (opts && opts.animation) || this._opts.enterAnimation;
let animation = Animation.create(this._elementRef.nativeElement, animationName); let animation = Animation.create(this._elementRef.nativeElement, animationName);
@ -115,6 +122,7 @@ export class OverlayRef {
animation.play().then(() => { animation.play().then(() => {
ClickBlock(false); ClickBlock(false);
animation.dispose(); animation.dispose();
this._instance.viewDidEnter && this._instance.viewDidEnter();
resolve(); resolve();
}); });
}).catch(err => { }).catch(err => {
@ -124,6 +132,9 @@ export class OverlayRef {
close(opts={}) { close(opts={}) {
return new Promise(resolve => { return new Promise(resolve => {
this._instance.viewWillLeave && this._instance.viewWillLeave();
this._instance.viewWillUnload && this._instance.viewWillUnload();
let animationName = (opts && opts.animation) || this._opts.leaveAnimation; let animationName = (opts && opts.animation) || this._opts.leaveAnimation;
let animation = Animation.create(this._elementRef.nativeElement, animationName); let animation = Animation.create(this._elementRef.nativeElement, animationName);
@ -131,10 +142,14 @@ export class OverlayRef {
ClickBlock(true, animation.duration() + 200); ClickBlock(true, animation.duration() + 200);
animation.play().then(() => { animation.play().then(() => {
this._instance.viewDidLeave && this._instance.viewDidLeave();
this._instance.viewDidUnload && this._instance.viewDidUnload();
this._dispose(); this._dispose();
ClickBlock(false); ClickBlock(false);
animation.dispose(); animation.dispose();
resolve(); resolve();
}) })
}).catch(err => { }).catch(err => {