Merge pull request #1086 from NathanaelA/DialogBox_Fixes

This will now allow the dialog to call the resolve function when cancelled by clicking outside.
This commit is contained in:
Vladimir Enchev
2015-11-17 10:28:20 +02:00
2 changed files with 40 additions and 2 deletions

View File

@@ -13,6 +13,9 @@ function createAlertDialog(options?: dialogs.DialogOptions): android.app.AlertDi
var alert = new android.app.AlertDialog.Builder(appmodule.android.foregroundActivity); var alert = new android.app.AlertDialog.Builder(appmodule.android.foregroundActivity);
alert.setTitle(options && types.isString(options.title) ? options.title : ""); alert.setTitle(options && types.isString(options.title) ? options.title : "");
alert.setMessage(options && types.isString(options.message) ? options.message : ""); alert.setMessage(options && types.isString(options.message) ? options.message : "");
if (options && options.cancelable === false) {
alert.setCancelable(false);
}
return alert; return alert;
} }
@@ -72,6 +75,11 @@ function addButtonsToAlertDialog(alert: android.app.AlertDialog.Builder, options
} }
})); }));
} }
alert.setOnDismissListener(new android.content.DialogInterface.OnDismissListener({
onDismiss: function() {
callback(false);
}
}));
} }
export function alert(arg: any): Promise<void> { export function alert(arg: any): Promise<void> {
@@ -87,6 +95,11 @@ export function alert(arg: any): Promise<void> {
resolve(); resolve();
} }
})); }));
alert.setOnDismissListener(new android.content.DialogInterface.OnDismissListener({
onDismiss: function() {
resolve();
}
}));
showDialog(alert); showDialog(alert);
@@ -262,6 +275,9 @@ export function action(arg: any): Promise<string> {
var alert = new android.app.AlertDialog.Builder(activity); var alert = new android.app.AlertDialog.Builder(activity);
var message = options && types.isString(options.message) ? options.message : ""; var message = options && types.isString(options.message) ? options.message : "";
var title = options && types.isString(options.title) ? options.title : ""; var title = options && types.isString(options.title) ? options.title : "";
if (options && options.cancelable === false) {
alert.setCancelable(false);
}
if (title) { if (title) {
alert.setTitle(title); alert.setTitle(title);
@@ -289,6 +305,17 @@ export function action(arg: any): Promise<string> {
} }
})); }));
} }
alert.setOnDismissListener(new android.content.DialogInterface.OnDismissListener({
onDismiss: function() {
if (types.isString(options.cancelButtonText)) {
resolve(options.cancelButtonText);
} else {
resolve("");
}
}
}));
showDialog(alert); showDialog(alert);
} catch (ex) { } catch (ex) {

View File

@@ -81,11 +81,21 @@ declare module "ui/dialogs" {
* @param options The options for the dialog box. * @param options The options for the dialog box.
*/ */
export function action(options: ActionOptions): Promise<string>; export function action(options: ActionOptions): Promise<string>;
/**
* Provides options for the dialog.
*/
export interface CancelableOptions {
/**
* [Android only] Gets or sets if the dialog can be canceled by taping outside of the dialog.
*/
cancelable?: boolean;
}
/** /**
* Provides options for the dialog. * Provides options for the dialog.
*/ */
export interface ActionOptions { export interface ActionOptions extends CancelableOptions {
/** /**
* Gets or sets the dialog title. * Gets or sets the dialog title.
*/ */
@@ -110,7 +120,7 @@ declare module "ui/dialogs" {
/** /**
* Provides options for the dialog. * Provides options for the dialog.
*/ */
export interface DialogOptions { export interface DialogOptions extends CancelableOptions {
/** /**
* Gets or sets the dialog title. * Gets or sets the dialog title.
*/ */
@@ -120,6 +130,7 @@ declare module "ui/dialogs" {
* Gets or sets the dialog message. * Gets or sets the dialog message.
*/ */
message?: string; message?: string;
} }
/** /**