alert fixed

This commit is contained in:
Vladimir Enchev
2015-11-27 14:56:11 +02:00
parent 2eec961f9e
commit c3d3326cb2
5 changed files with 41 additions and 4 deletions

View File

@ -12,6 +12,32 @@ export function alertWithOptionsTapped(args) {
}); });
} }
export function alertWithNullTapped(args) {
dialogs.alert(null);
}
export function alertWithUndefinedTapped(args) {
dialogs.alert(undefined);
}
export function alertWithNumberTapped(args) {
dialogs.alert(1);
}
export function alertWithBooleanTapped(args) {
dialogs.alert(false);
}
export function alertWithFunctionTapped(args) {
dialogs.alert(function () {
//
});
}
export function alertWithObjectTapped(args) {
dialogs.alert({});
}
export function confirmTapped(args) { export function confirmTapped(args) {
dialogs.confirm("Are you sure?").then(r=> console.log(`Confirm result: ${r}`)); dialogs.confirm("Are you sure?").then(r=> console.log(`Confirm result: ${r}`));
} }

View File

@ -4,6 +4,12 @@
<StackLayout> <StackLayout>
<Button text="alert" tap="alertTapped"/> <Button text="alert" tap="alertTapped"/>
<Button text="alert with options" tap="alertWithOptionsTapped"/> <Button text="alert with options" tap="alertWithOptionsTapped"/>
<Button text="alert with null" tap="alertWithNullTapped"/>
<Button text="alert with undefined" tap="alertWithUndefinedTapped"/>
<Button text="alert with number" tap="alertWithNumberTapped"/>
<Button text="alert with boolean" tap="alertWithBooleanTapped"/>
<Button text="alert with function" tap="alertWithFunctionTapped"/>
<Button text="alert with object" tap="alertWithObjectTapped"/>
<Button text="confirm" tap="confirmTapped"/> <Button text="confirm" tap="confirmTapped"/>
<Button text="confirm with options" tap="confirmWithOptionsTapped"/> <Button text="confirm with options" tap="confirmWithOptionsTapped"/>
<Button text="prompt" tap="promptTapped"/> <Button text="prompt" tap="promptTapped"/>

View File

@ -4,6 +4,7 @@ import page = require("ui/page");
import button = require("ui/button"); import button = require("ui/button");
import textField = require("ui/text-field"); import textField = require("ui/text-field");
import label = require("ui/label"); import label = require("ui/label");
import types = require("utils/types");
export var STRING = "string", export var STRING = "string",
PROMPT = "Prompt", PROMPT = "Prompt",
@ -79,3 +80,7 @@ export function getLabelColor(): color.Color {
return labelColor; return labelColor;
} }
export function isDialogOptions(arg): boolean {
return !types.isNullOrUndefined(arg) && (arg.message || arg.title);
}

View File

@ -85,7 +85,7 @@ function addButtonsToAlertDialog(alert: android.app.AlertDialog.Builder, options
export function alert(arg: any): Promise<void> { export function alert(arg: any): Promise<void> {
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
try { try {
var options = types.isString(arg) ? { title: dialogsCommon.ALERT, okButtonText: dialogsCommon.OK, message: arg } : arg; var options = !dialogsCommon.isDialogOptions(arg) ? { title: dialogsCommon.ALERT, okButtonText: dialogsCommon.OK, message: arg + "" } : arg;
var alert = createAlertDialog(options); var alert = createAlertDialog(options);
@ -112,7 +112,7 @@ export function alert(arg: any): Promise<void> {
export function confirm(arg: any): Promise<boolean> { export function confirm(arg: any): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => { return new Promise<boolean>((resolve, reject) => {
try { try {
var options = types.isString(arg) ? { title: dialogsCommon.CONFIRM, okButtonText: dialogsCommon.OK, cancelButtonText: dialogsCommon.CANCEL, message: arg } : arg; var options = !dialogsCommon.isDialogOptions(arg) ? { title: dialogsCommon.CONFIRM, okButtonText: dialogsCommon.OK, cancelButtonText: dialogsCommon.CANCEL, message: arg + "" } : arg;
var alert = createAlertDialog(options); var alert = createAlertDialog(options);
addButtonsToAlertDialog(alert, options, function (result) { resolve(result); }); addButtonsToAlertDialog(alert, options, function (result) { resolve(result); });

View File

@ -136,7 +136,7 @@ function raiseCallback(callback, result) {
export function alert(arg: any): Promise<void> { export function alert(arg: any): Promise<void> {
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
try { try {
var options = types.isString(arg) ? { title: dialogsCommon.ALERT, okButtonText: dialogsCommon.OK, message: arg } : arg; var options = !dialogsCommon.isDialogOptions(arg) ? { title: dialogsCommon.ALERT, okButtonText: dialogsCommon.OK, message: arg + "" } : arg;
if (utils.ios.MajorVersion < 8) { if (utils.ios.MajorVersion < 8) {
var alert = createUIAlertView(options); var alert = createUIAlertView(options);
@ -171,7 +171,7 @@ export function alert(arg: any): Promise<void> {
export function confirm(arg: any): Promise<boolean> { export function confirm(arg: any): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => { return new Promise<boolean>((resolve, reject) => {
try { try {
var options = types.isString(arg) ? { title: dialogsCommon.CONFIRM, okButtonText: dialogsCommon.OK, cancelButtonText: dialogsCommon.CANCEL, message: arg } : arg; var options = !dialogsCommon.isDialogOptions(arg) ? { title: dialogsCommon.CONFIRM, okButtonText: dialogsCommon.OK, cancelButtonText: dialogsCommon.CANCEL, message: arg + "" } : arg;
if (utils.ios.MajorVersion < 8) { if (utils.ios.MajorVersion < 8) {
var alert = createUIAlertView(options); var alert = createUIAlertView(options);