-
Notifications
You must be signed in to change notification settings - Fork 28
/
feedback.common.ts
163 lines (138 loc) · 3.6 KB
/
feedback.common.ts
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import { Color } from "tns-core-modules/color";
export enum FeedbackPosition {
Top,
Bottom
}
export enum FeedbackType {
Success,
Error,
Warning,
Info,
Custom
}
export interface FeedbackShowOptions {
/**
* The 'bold' title at the top.
* Default undefined.
*/
title?: string;
/**
* Default 15.
*/
titleSize?: number;
/**
* The title's color.
* Default new Color("white").
*/
titleColor?: Color;
/**
* The message below the title.
* Default undefined.
*/
message?: string;
/**
* The message's color.
* Default new Color("white").
*/
/**
* Default 13.
*/
messageSize?: number;
messageColor?: Color;
/**
* The duration to show the feedback (milliseconds).
* Default 4000.
*/
duration?: number;
/**
* The type determines the base layout of the feedback message.
* You can still override all other properties according to your liking.
* Default FeedbackType.Custom.
*/
type?: FeedbackType;
/**
* Either FeedbackPosition.Top or FeedbackPosition.Bottom (iOS only).
* Default FeedbackPosition.Top
*/
position?: FeedbackPosition;
/**
* The background's color.
* Default depends on the 'type' property.
*/
backgroundColor?: Color;
/**
* A resource like 'customimage' which refers to:
* - iOS: App_Resources/customimage.png (and customimage@2x.png / customimage@3x.png)
* - Android: App_Resources/drawable-hdpi/customimage.png (and other folders)
* Default depends on the 'type' property.
*/
icon?: string;
/**
* A callback function that gets invoked when the user tapped your feedback.
* Default undefined.
*/
onTap?: () => void;
/**
* A callback for when the feedback is hidden.
* Default undefined.
*/
onHide?: () => void;
/**
* A callback for when the feedback is shown.
* iOS note: is called twice: once when animating and once when done.
* Default undefined.
*/
onShow?: (animating?: boolean) => void;
/**
* The font name for the title.
* Be aware iOS needs the font name and android the file name.
* Default bold system font.
*/
titleFont?: string;
/**
* The font name for the message.
* Be aware iOS needs the font name and android the file name.
* Default system font.
*/
messageFont?: string;
/**
* Android-specific options
*/
android?: {
/**
* The icon's color. Android only as iOS uses the icon's color, but Android is otherwise always white.
*/
iconColor?: Color;
};
}
export interface FeedbackHideOptions {
}
export interface FeedbackApi {
show(options: FeedbackShowOptions): Promise<any>;
hide(options?: FeedbackHideOptions): Promise<any>;
// convenience funtions
success(options: FeedbackShowOptions): Promise<any>;
warning(options: FeedbackShowOptions): Promise<any>;
error(options: FeedbackShowOptions): Promise<any>;
info(options: FeedbackShowOptions): Promise<any>;
}
export abstract class FeedbackCommon implements FeedbackApi {
abstract show(options: FeedbackShowOptions): Promise<any>;
abstract hide(options?: FeedbackHideOptions): Promise<any>;
success(options: FeedbackShowOptions): Promise<any> {
options.type = FeedbackType.Success;
return this.show(options);
}
warning(options: FeedbackShowOptions): Promise<any> {
options.type = FeedbackType.Warning;
return this.show(options);
}
error(options: FeedbackShowOptions): Promise<any> {
options.type = FeedbackType.Error;
return this.show(options);
}
info(options: FeedbackShowOptions): Promise<any> {
options.type = FeedbackType.Info;
return this.show(options);
}
}