mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
ShownModally fired when the dialog is actually shown in Android
This commit is contained in:
@ -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 {
|
||||
|
@ -25,23 +25,23 @@ function ensureColor() {
|
||||
|
||||
export var DIALOG_FRAGMENT_TAG = "dialog";
|
||||
|
||||
var DialogFragmentClass;
|
||||
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) {
|
||||
|
2
ui/page/page.d.ts
vendored
2
ui/page/page.d.ts
vendored
@ -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.
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user