forked from EddyVerbruggen/nativescript-feedback
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeedback.common.ts
119 lines (107 loc) · 2.86 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
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;
/**
* 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").
*/
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 [email protected] / [email protected])
* - 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?: Function;
/**
* 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);
}
}