diff --git a/ui/page/page-common.ts b/ui/page/page-common.ts index 95d9961d7..84103d613 100644 --- a/ui/page/page-common.ts +++ b/ui/page/page-common.ts @@ -50,6 +50,7 @@ export class Page extends ContentView implements dts.Page { public static showingModallyEvent = "showingModally"; protected _closeModalCallback: Function; + private _modalContext: any; private _navigationContext: any; @@ -250,9 +251,11 @@ export class Page extends ContentView implements dts.Page { protected _showNativeModalView(parent: Page, context: any, closeCallback: Function, fullscreen?: boolean) { parent._modal = this; var that = this; + this._modalContext = context; this._closeModalCallback = function () { if (that._closeModalCallback) { that._closeModalCallback = null; + that._modalContext = null; that._hideNativeModalView(parent); if (typeof closeCallback === "function") { closeCallback.apply(undefined, arguments); @@ -265,20 +268,24 @@ export class Page extends ContentView implements dts.Page { // } - protected _raiseShownModallyEvent(parent: Page, context: any, closeCallback: Function) { - this.notify({ + protected _raiseShownModallyEvent() { + let args: dts.ShownModallyData = { eventName: Page.shownModallyEvent, object: this, - context: context, + context: this._modalContext, closeCallback: this._closeModalCallback - }); + } + this.notify(args); } protected _raiseShowingModallyEvent() { - this.notify({ + let args: dts.ShownModallyData = { eventName: Page.showingModallyEvent, - object: this - }); + object: this, + context: this._modalContext, + closeCallback: this._closeModalCallback + } + this.notify(args); } public _getStyleScope(): styleScope.StyleScope { diff --git a/ui/page/page.android.ts b/ui/page/page.android.ts index f3d185a74..896714288 100644 --- a/ui/page/page.android.ts +++ b/ui/page/page.android.ts @@ -25,23 +25,23 @@ function ensureColor() { export var DIALOG_FRAGMENT_TAG = "dialog"; -var DialogFragmentClass; -function ensureDialogFragmentClass() { +interface DialogFragmentClass { + new (owner: Page, fullscreen: boolean, shownCallback: () => void, dismissCallback: () => void): android.app.DialogFragment; +} +var DialogFragmentClass: DialogFragmentClass; + +function ensureDialogFragmentClass() { if (DialogFragmentClass) { return; } class DialogFragmentClassInner extends android.app.DialogFragment { - private _owner: Page; - private _fullscreen: boolean; - private _dismissCallback: Function; - - constructor(owner: Page, fullscreen?: boolean, dismissCallback?: Function) { + constructor( + private _owner: Page, + private _fullscreen: boolean, + private _shownCallback: () => void, + private _dismissCallback: () => void) { super(); - - this._owner = owner; - this._fullscreen = fullscreen; - this._dismissCallback = dismissCallback; return global.__native(this); } @@ -66,10 +66,14 @@ function ensureDialogFragmentClass() { return dialog; } - public onDismiss() { - if (typeof this._dismissCallback === "function") { - this._dismissCallback(); - } + public onStart() { + super.onStart(); + this._shownCallback(); + } + + public onDismiss(dialog: android.content.IDialogInterface) { + super.onDismiss(dialog); + this._dismissCallback(); } }; @@ -149,14 +153,12 @@ export class Page extends pageCommon.Page { this.onLoaded(); ensureDialogFragmentClass(); - var that = this; - this._dialogFragment = new DialogFragmentClass(this, fullscreen, function () { - that.closeModal(); - }); + + this._dialogFragment = new DialogFragmentClass(this, !!fullscreen, () => this._raiseShownModallyEvent, () => this.closeModal()); super._raiseShowingModallyEvent(); + this._dialogFragment.show(parent.frame.android.activity.getFragmentManager(), DIALOG_FRAGMENT_TAG); - super._raiseShownModallyEvent(parent, context, closeCallback); } protected _hideNativeModalView(parent: Page) { diff --git a/ui/page/page.d.ts b/ui/page/page.d.ts index f2d6c0eb9..f22b4d179 100644 --- a/ui/page/page.d.ts +++ b/ui/page/page.d.ts @@ -166,7 +166,7 @@ declare module "ui/page" { /** * Raised before the page is shown as a modal dialog. */ - on(event: "showingModally", callback: (args: observable.EventData) => void, thisArg?: any): void; + on(event: "showingModally", callback: (args: ShownModallyData) => void, thisArg?: any): void; /** * Raised after the page is shown as a modal dialog. diff --git a/ui/page/page.ios.ts b/ui/page/page.ios.ts index 63a79f164..ec5c151a2 100644 --- a/ui/page/page.ios.ts +++ b/ui/page/page.ios.ts @@ -340,7 +340,7 @@ export class Page extends pageCommon.Page { var that = this; parent.ios.presentViewControllerAnimatedCompletion(this._ios, utils.ios.MajorVersion >= 8, null); UIViewControllerTransitionCoordinator.prototype.animateAlongsideTransitionCompletion.call(parent.ios.transitionCoordinator(), null, function () { - that._raiseShownModallyEvent(parent, context, closeCallback); + that._raiseShownModallyEvent(); }); }