forked from EddyVerbruggen/nativescript-feedback
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeedback.ios.ts
More file actions
87 lines (74 loc) · 2.53 KB
/
Copy pathfeedback.ios.ts
File metadata and controls
87 lines (74 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import {
FeedbackCommon,
FeedbackShowOptions,
FeedbackHideOptions,
FeedbackPosition,
FeedbackType
} from "./feedback.common";
declare const ISAlertTypeSuccess: any;
// Export the enums for devs not using TS
exports.FeedbackPosition = FeedbackPosition;
exports.FeedbackType = FeedbackType;
export class Feedback extends FeedbackCommon {
show(options: FeedbackShowOptions): Promise<any> {
return new Promise((resolve, reject) => {
let icon: UIImage = options.icon ? UIImage.imageNamed(options.icon) : null;
let hideOnSwipe: boolean = true;
let hideOnTap: boolean = true;
let message: ISMessages = ISMessages.cardAlertWithTitleMessageIconImageDurationHideOnSwipeHideOnTapAlertTypeAlertPosition(
options.title,
options.message,
icon,
options.duration ? options.duration / 1000 : 4.0,
hideOnSwipe,
hideOnTap,
Feedback.getType(options.type),
Feedback.getPosition(options.position));
if (options.backgroundColor) {
message.alertViewBackgroundColor = options.backgroundColor.ios;
}
if (options.titleColor) {
message.titleLabelTextColor = options.titleColor.ios;
}
message.titleLabelFont = UIFont.boldSystemFontOfSize(15.0);
if (options.messageColor) {
message.messageLabelTextColor = options.messageColor.ios;
}
message.messageLabelFont = UIFont.systemFontOfSize(13.0);
message.showDidHide(() => {
if (options.onTap) {
options.onTap();
}
}, (hidden: boolean) => {
// nothing to do on hide
});
resolve();
});
}
hide(options?: FeedbackHideOptions): Promise<any> {
return new Promise((resolve, reject) => {
ISMessages.hideAlertAnimated(true);
resolve();
});
}
private static getType(type?: FeedbackType) {
if (type === undefined || type === null || type as FeedbackType === FeedbackType.Custom) {
return ISAlertType.Custom;
} else if (type as FeedbackType === FeedbackType.Warning) {
return ISAlertType.Warning;
} else if (type as FeedbackType === FeedbackType.Error) {
return ISAlertType.Error;
} else if (type as FeedbackType === FeedbackType.Info) {
return ISAlertType.Info;
} else {
return ISAlertType.Success;
}
}
private static getPosition(position?: FeedbackPosition) {
if (!position || position as FeedbackPosition === FeedbackPosition.Top) {
return ISAlertPosition.Top;
} else {
return ISAlertPosition.Bottom;
}
}
}