mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
This fixes the issue with Dialogs and being dismissed by clicking elsewhere on the screen on Android. The dialog will now call the callback with a null value as the first parameter (and finish calling the unloaded and other code that is supposed to be ran when the dialog is closed). This also adds a closeDialog function that you can call from the dialog which will also call the callback for you.
This commit is contained in:

committed by
Rossen Hristov

parent
8bc2aedfae
commit
5d3d772462
@ -35,6 +35,7 @@ export class Page extends contentView.ContentView implements dts.Page {
|
||||
|
||||
private _navigationContext: any;
|
||||
|
||||
private _closeDialogCallback: Function;
|
||||
private _cssApplied: boolean;
|
||||
private _styleScope: styleScope.StyleScope = new styleScope.StyleScope();
|
||||
private _actionBar: actionBar.ActionBar;
|
||||
@ -189,6 +190,12 @@ export class Page extends contentView.ContentView implements dts.Page {
|
||||
(<Page>page)._showNativeModalView(this, context, closeCallback, fullscreen);
|
||||
}
|
||||
|
||||
public closeDialog() {
|
||||
if (this._closeDialogCallback) {
|
||||
this._closeDialogCallback.apply(undefined, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
public _addChildFromBuilder(name: string, value: any) {
|
||||
if (value instanceof actionBar.ActionBar) {
|
||||
this.actionBar = value;
|
||||
@ -199,7 +206,16 @@ export class Page extends contentView.ContentView implements dts.Page {
|
||||
}
|
||||
|
||||
protected _showNativeModalView(parent: Page, context: any, closeCallback: Function, fullscreen?: boolean) {
|
||||
//
|
||||
var that = this;
|
||||
this._closeDialogCallback = function () {
|
||||
if (that._closeDialogCallback) {
|
||||
that._closeDialogCallback = null;
|
||||
that._hideNativeModalView(parent);
|
||||
if (typeof closeCallback === "function") {
|
||||
closeCallback.apply(undefined, arguments);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected _hideNativeModalView(parent: Page) {
|
||||
@ -207,19 +223,11 @@ export class Page extends contentView.ContentView implements dts.Page {
|
||||
}
|
||||
|
||||
protected _raiseShownModallyEvent(parent: Page, context: any, closeCallback: Function) {
|
||||
var that = this;
|
||||
var closeProxy = function () {
|
||||
that._hideNativeModalView(parent);
|
||||
if (closeCallback){
|
||||
closeCallback.apply(undefined, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
this.notify({
|
||||
eventName: Page.shownModallyEvent,
|
||||
object: this,
|
||||
context: context,
|
||||
closeCallback: closeProxy
|
||||
closeCallback: this._closeDialogCallback
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -12,12 +12,14 @@ global.moduleMerge(pageCommon, exports);
|
||||
class DialogFragmentClass extends android.app.DialogFragment {
|
||||
private _owner: Page;
|
||||
private _fullscreen: boolean;
|
||||
private _dismissCallback: Function;
|
||||
|
||||
constructor(owner: Page, fullscreen?: boolean) {
|
||||
constructor(owner: Page, fullscreen?: boolean, dismissCallback?: Function) {
|
||||
super();
|
||||
|
||||
this._owner = owner;
|
||||
this._fullscreen = fullscreen;
|
||||
this._dismissCallback = dismissCallback;
|
||||
return global.__native(this);
|
||||
}
|
||||
|
||||
@ -29,11 +31,18 @@ class DialogFragmentClass extends android.app.DialogFragment {
|
||||
window.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(android.graphics.Color.TRANSPARENT));
|
||||
|
||||
if (this._fullscreen) {
|
||||
window.setLayout(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.FILL_PARENT);
|
||||
window.setLayout(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.FILL_PARENT);
|
||||
}
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public onDismiss() {
|
||||
if (typeof this._dismissCallback === "function") {
|
||||
this._dismissCallback();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export class Page extends pageCommon.Page {
|
||||
@ -96,6 +105,7 @@ export class Page extends pageCommon.Page {
|
||||
private _dialogFragment: DialogFragmentClass;
|
||||
/* tslint:enable */
|
||||
protected _showNativeModalView(parent: Page, context: any, closeCallback: Function, fullscreen?: boolean) {
|
||||
super._showNativeModalView(parent, context, closeCallback, fullscreen);
|
||||
if (!this.backgroundColor) {
|
||||
this.backgroundColor = new color.Color("White");
|
||||
}
|
||||
@ -104,7 +114,10 @@ export class Page extends pageCommon.Page {
|
||||
this._isAddedToNativeVisualTree = true;
|
||||
this.onLoaded();
|
||||
|
||||
this._dialogFragment = new DialogFragmentClass(this, fullscreen);
|
||||
var that = this;
|
||||
this._dialogFragment = new DialogFragmentClass(this, fullscreen, function() {
|
||||
that.closeDialog();
|
||||
});
|
||||
this._dialogFragment.show(parent.frame.android.activity.getFragmentManager(), "dialog");
|
||||
|
||||
super._raiseShownModallyEvent(parent, context, closeCallback);
|
||||
|
@ -130,6 +130,7 @@ export class Page extends pageCommon.Page {
|
||||
}
|
||||
|
||||
protected _showNativeModalView(parent: Page, context: any, closeCallback: Function, fullscreen?: boolean) {
|
||||
super._showNativeModalView(parent, context, closeCallback, fullscreen);
|
||||
this._isModal = true;
|
||||
|
||||
if (!parent.ios.view.window) {
|
||||
|
Reference in New Issue
Block a user