Skip to content

Commit 82c86ad

Browse files
author
Vladimir Enchev
committed
Merge pull request NativeScript#1174 from NativeScript/alert-fixes
alert fixed
2 parents b89abbf + c3d3326 commit 82c86ad

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

apps/gallery-app/views/dialogs.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,32 @@ export function alertWithOptionsTapped(args) {
1212
});
1313
}
1414

15+
export function alertWithNullTapped(args) {
16+
dialogs.alert(null);
17+
}
18+
19+
export function alertWithUndefinedTapped(args) {
20+
dialogs.alert(undefined);
21+
}
22+
23+
export function alertWithNumberTapped(args) {
24+
dialogs.alert(1);
25+
}
26+
27+
export function alertWithBooleanTapped(args) {
28+
dialogs.alert(false);
29+
}
30+
31+
export function alertWithFunctionTapped(args) {
32+
dialogs.alert(function () {
33+
//
34+
});
35+
}
36+
37+
export function alertWithObjectTapped(args) {
38+
dialogs.alert({});
39+
}
40+
1541
export function confirmTapped(args) {
1642
dialogs.confirm("Are you sure?").then(r=> console.log(`Confirm result: ${r}`));
1743
}

apps/gallery-app/views/dialogs.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
<StackLayout>
55
<Button text="alert" tap="alertTapped"/>
66
<Button text="alert with options" tap="alertWithOptionsTapped"/>
7+
<Button text="alert with null" tap="alertWithNullTapped"/>
8+
<Button text="alert with undefined" tap="alertWithUndefinedTapped"/>
9+
<Button text="alert with number" tap="alertWithNumberTapped"/>
10+
<Button text="alert with boolean" tap="alertWithBooleanTapped"/>
11+
<Button text="alert with function" tap="alertWithFunctionTapped"/>
12+
<Button text="alert with object" tap="alertWithObjectTapped"/>
713
<Button text="confirm" tap="confirmTapped"/>
814
<Button text="confirm with options" tap="confirmWithOptionsTapped"/>
915
<Button text="prompt" tap="promptTapped"/>

ui/dialogs/dialogs-common.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import page = require("ui/page");
44
import button = require("ui/button");
55
import textField = require("ui/text-field");
66
import label = require("ui/label");
7+
import types = require("utils/types");
78

89
export var STRING = "string",
910
PROMPT = "Prompt",
@@ -78,4 +79,8 @@ export function getLabelColor(): color.Color {
7879
}
7980

8081
return labelColor;
82+
}
83+
84+
export function isDialogOptions(arg): boolean {
85+
return !types.isNullOrUndefined(arg) && (arg.message || arg.title);
8186
}

ui/dialogs/dialogs.android.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function addButtonsToAlertDialog(alert: android.app.AlertDialog.Builder, options
8484
export function alert(arg: any): Promise<void> {
8585
return new Promise<void>((resolve, reject) => {
8686
try {
87-
var options = types.isString(arg) ? { title: dialogsCommon.ALERT, okButtonText: dialogsCommon.OK, message: arg } : arg;
87+
var options = !dialogsCommon.isDialogOptions(arg) ? { title: dialogsCommon.ALERT, okButtonText: dialogsCommon.OK, message: arg + "" } : arg;
8888

8989
var alert = createAlertDialog(options);
9090

@@ -111,7 +111,7 @@ export function alert(arg: any): Promise<void> {
111111
export function confirm(arg: any): Promise<boolean> {
112112
return new Promise<boolean>((resolve, reject) => {
113113
try {
114-
var options = types.isString(arg) ? { title: dialogsCommon.CONFIRM, okButtonText: dialogsCommon.OK, cancelButtonText: dialogsCommon.CANCEL, message: arg } : arg;
114+
var options = !dialogsCommon.isDialogOptions(arg) ? { title: dialogsCommon.CONFIRM, okButtonText: dialogsCommon.OK, cancelButtonText: dialogsCommon.CANCEL, message: arg + "" } : arg;
115115
var alert = createAlertDialog(options);
116116

117117
addButtonsToAlertDialog(alert, options, function (result) { resolve(result); });

ui/dialogs/dialogs.ios.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ function raiseCallback(callback, result) {
135135
export function alert(arg: any): Promise<void> {
136136
return new Promise<void>((resolve, reject) => {
137137
try {
138-
var options = types.isString(arg) ? { title: dialogsCommon.ALERT, okButtonText: dialogsCommon.OK, message: arg } : arg;
138+
var options = !dialogsCommon.isDialogOptions(arg) ? { title: dialogsCommon.ALERT, okButtonText: dialogsCommon.OK, message: arg + "" } : arg;
139139

140140
if (utils.ios.MajorVersion < 8) {
141141
var alert = createUIAlertView(options);
@@ -170,7 +170,7 @@ export function alert(arg: any): Promise<void> {
170170
export function confirm(arg: any): Promise<boolean> {
171171
return new Promise<boolean>((resolve, reject) => {
172172
try {
173-
var options = types.isString(arg) ? { title: dialogsCommon.CONFIRM, okButtonText: dialogsCommon.OK, cancelButtonText: dialogsCommon.CANCEL, message: arg } : arg;
173+
var options = !dialogsCommon.isDialogOptions(arg) ? { title: dialogsCommon.CONFIRM, okButtonText: dialogsCommon.OK, cancelButtonText: dialogsCommon.CANCEL, message: arg + "" } : arg;
174174

175175
if (utils.ios.MajorVersion < 8) {
176176
var alert = createUIAlertView(options);

0 commit comments

Comments
 (0)