ShownModally fired when the dialog is actually shown in Android

This commit is contained in:
vakrilov
2016-03-24 14:40:55 +02:00
parent 8b07d02091
commit d129dc5904
4 changed files with 38 additions and 29 deletions

View File

@ -50,6 +50,7 @@ export class Page extends ContentView implements dts.Page {
public static showingModallyEvent = "showingModally"; public static showingModallyEvent = "showingModally";
protected _closeModalCallback: Function; protected _closeModalCallback: Function;
private _modalContext: any;
private _navigationContext: 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) { protected _showNativeModalView(parent: Page, context: any, closeCallback: Function, fullscreen?: boolean) {
parent._modal = this; parent._modal = this;
var that = this; var that = this;
this._modalContext = context;
this._closeModalCallback = function () { this._closeModalCallback = function () {
if (that._closeModalCallback) { if (that._closeModalCallback) {
that._closeModalCallback = null; that._closeModalCallback = null;
that._modalContext = null;
that._hideNativeModalView(parent); that._hideNativeModalView(parent);
if (typeof closeCallback === "function") { if (typeof closeCallback === "function") {
closeCallback.apply(undefined, arguments); closeCallback.apply(undefined, arguments);
@ -265,20 +268,24 @@ export class Page extends ContentView implements dts.Page {
// //
} }
protected _raiseShownModallyEvent(parent: Page, context: any, closeCallback: Function) { protected _raiseShownModallyEvent() {
this.notify({ let args: dts.ShownModallyData = {
eventName: Page.shownModallyEvent, eventName: Page.shownModallyEvent,
object: this, object: this,
context: context, context: this._modalContext,
closeCallback: this._closeModalCallback closeCallback: this._closeModalCallback
}); }
this.notify(args);
} }
protected _raiseShowingModallyEvent() { protected _raiseShowingModallyEvent() {
this.notify({ let args: dts.ShownModallyData = {
eventName: Page.showingModallyEvent, eventName: Page.showingModallyEvent,
object: this object: this,
}); context: this._modalContext,
closeCallback: this._closeModalCallback
}
this.notify(args);
} }
public _getStyleScope(): styleScope.StyleScope { public _getStyleScope(): styleScope.StyleScope {

View File

@ -25,23 +25,23 @@ function ensureColor() {
export var DIALOG_FRAGMENT_TAG = "dialog"; export var DIALOG_FRAGMENT_TAG = "dialog";
var DialogFragmentClass; interface DialogFragmentClass {
function ensureDialogFragmentClass() { new (owner: Page, fullscreen: boolean, shownCallback: () => void, dismissCallback: () => void): android.app.DialogFragment;
}
var DialogFragmentClass: DialogFragmentClass;
function ensureDialogFragmentClass() {
if (DialogFragmentClass) { if (DialogFragmentClass) {
return; return;
} }
class DialogFragmentClassInner extends android.app.DialogFragment { class DialogFragmentClassInner extends android.app.DialogFragment {
private _owner: Page; constructor(
private _fullscreen: boolean; private _owner: Page,
private _dismissCallback: Function; private _fullscreen: boolean,
private _shownCallback: () => void,
constructor(owner: Page, fullscreen?: boolean, dismissCallback?: Function) { private _dismissCallback: () => void) {
super(); super();
this._owner = owner;
this._fullscreen = fullscreen;
this._dismissCallback = dismissCallback;
return global.__native(this); return global.__native(this);
} }
@ -66,10 +66,14 @@ function ensureDialogFragmentClass() {
return dialog; return dialog;
} }
public onDismiss() { public onStart() {
if (typeof this._dismissCallback === "function") { super.onStart();
this._dismissCallback(); 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(); this.onLoaded();
ensureDialogFragmentClass(); ensureDialogFragmentClass();
var that = this;
this._dialogFragment = new DialogFragmentClass(this, fullscreen, function () { this._dialogFragment = new DialogFragmentClass(this, !!fullscreen, () => this._raiseShownModallyEvent, () => this.closeModal());
that.closeModal();
});
super._raiseShowingModallyEvent(); super._raiseShowingModallyEvent();
this._dialogFragment.show(parent.frame.android.activity.getFragmentManager(), DIALOG_FRAGMENT_TAG); this._dialogFragment.show(parent.frame.android.activity.getFragmentManager(), DIALOG_FRAGMENT_TAG);
super._raiseShownModallyEvent(parent, context, closeCallback);
} }
protected _hideNativeModalView(parent: Page) { protected _hideNativeModalView(parent: Page) {

2
ui/page/page.d.ts vendored
View File

@ -166,7 +166,7 @@ declare module "ui/page" {
/** /**
* Raised before the page is shown as a modal dialog. * 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. * Raised after the page is shown as a modal dialog.

View File

@ -340,7 +340,7 @@ export class Page extends pageCommon.Page {
var that = this; var that = this;
parent.ios.presentViewControllerAnimatedCompletion(this._ios, utils.ios.MajorVersion >= 8, null); parent.ios.presentViewControllerAnimatedCompletion(this._ios, utils.ios.MajorVersion >= 8, null);
UIViewControllerTransitionCoordinator.prototype.animateAlongsideTransitionCompletion.call(parent.ios.transitionCoordinator(), null, function () { UIViewControllerTransitionCoordinator.prototype.animateAlongsideTransitionCompletion.call(parent.ios.transitionCoordinator(), null, function () {
that._raiseShownModallyEvent(parent, context, closeCallback); that._raiseShownModallyEvent();
}); });
} }