-
Notifications
You must be signed in to change notification settings - Fork 34
/
AppMessages.tsx
91 lines (86 loc) · 1.93 KB
/
AppMessages.tsx
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
import { ToastConfig } from '@msantang78/react-native-styled-toast/dist/Toast';
import sp from '~/services/serviceProvider';
let toast: undefined | ((config: ToastConfig) => void);
export function registerToast(t) {
toast = t;
}
type MessageType = 'success' | 'info' | 'warning' | 'danger';
function getIcon(type: MessageType): any {
switch (type) {
case 'success':
return {
iconColor: '#59A05E',
iconFamily: 'Ionicons',
iconName: 'checkmark',
};
case 'warning':
return {
iconColor: '#D49538',
iconFamily: 'Ionicons',
iconName: 'warning',
};
case 'info':
return {
iconColor: '#5282A7',
iconFamily: 'EvilIcons',
iconName: 'exclamation',
};
case 'danger':
return {
iconColor: '#CA4A34',
iconFamily: 'MaterialCommunityIcons',
iconName: 'alert-octagon',
};
}
return {};
}
/**
* Show a notification message to the user
* @param message
* @param type
* @param duration
* @param subMessage
* @param shouldVibrate
*/
export const showNotification = (
message: string,
type: MessageType = 'info',
duration: number = 2800,
subMessage?: string,
shouldVibrate = false,
onPress?: () => void,
) => {
if (toast) {
toast({
closeIconColor: sp.styles.getColor('SecondaryText'),
message,
onPress,
hideAccent: true,
shouldVibrate,
allowFontScaling: false,
// hideCloseIcon: true,
duration,
subMessage,
...getIcon(type),
closeIconSize: 18,
messageProps: {
fontFamily: 'Roboto_500Medium',
fontSize: 15,
},
iconSize: 24,
toastStyles: {
borderRadius: 4,
},
shadow: {
shadowColor: '#000000',
shadowOffset: {
width: 0,
height: 1,
},
shadowOpacity: 0.5,
shadowRadius: 2,
elevation: 4,
},
});
}
};