-
Notifications
You must be signed in to change notification settings - Fork 276
/
Copy pathindex.ts
219 lines (208 loc) · 5.56 KB
/
index.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import React from 'react';
import {
StyleProp,
TextProps,
TextStyle,
TouchableOpacityProps,
ViewProps,
ViewStyle
} from 'react-native';
export type ReactChildren = React.ReactNode;
export type ToastType = 'success' | 'error' | 'info' | (string & {});
export type ToastPosition = 'top' | 'bottom';
export type ToastOptions = {
/**
* Toast type.
* Default value: `success`
*/
type?: ToastType;
/**
* Style for the header text in the Toast (text1).
*/
text1Style?: StyleProp<TextStyle>;
/**
* Style for the inner message text in the Toast (text2).
*/
text2Style?: StyleProp<TextStyle>;
/**
* Toast position.
* Default value: `top`
*/
position?: ToastPosition;
/**
* When `true`, the visible Toast automatically hides after a certain number of milliseconds,
* specified by the `visibilityTime` prop.
* Default value: `true`
*/
autoHide?: boolean;
/**
* Number of milliseconds after which Toast automatically hides.
* Has effect only in conjunction with `autoHide` prop set to `true`.
* Default value: `4000`
*/
visibilityTime?: number;
/**
* When `true`, the Toast can be dismissed by a swipe gesture, specified by the `swipeable` prop.
* Default value: `true`
*/
swipeable?: boolean;
/**
* Offset from the top of the screen (in px).
* Has effect only when `position` is `top`
* Default value: `40`
*/
topOffset?: number;
/**
* Offset from the bottom of the screen (in px)
* Has effect only when `position` is `bottom`
* Default value: `40`
*/
bottomOffset?: number;
/**
* Offset from the Keyboard (in px)
* Has effect only when `position` is `bottom` and Keyboard is visible
* Default value: `10`
*/
keyboardOffset?: number;
/**
* When `true` offset calculation use KeyboardHeight in position calculation.
* If you put <Toast /> inside a keyboard aware component and position is 'bottom', you should set this to `false`.
* Default value: true
*/
avoidKeyboard?: boolean;
/**
* Called when Toast is shown
*/
onShow?: () => void;
/**
* Called when Toast hides
*/
onHide?: () => void;
/**
* Called on Toast press
*/
onPress?: () => void;
/**
* Any custom props passed to the specified Toast type.
* Has effect only when there is a custom Toast type (configured via the `config` prop
* on the Toast instance) that uses the `props` parameter
*/
props?: any;
};
export type ToastData = {
text1?: string;
text2?: string;
};
export type ToastShowParams = ToastData & ToastOptions;
export type ToastHideParams = void;
export type BaseToastProps = {
text1?: string;
text2?: string;
onPress?: () => void;
activeOpacity?: number;
style?: StyleProp<ViewStyle>;
touchableContainerProps?: TouchableOpacityProps;
contentContainerStyle?: StyleProp<ViewStyle>;
contentContainerProps?: ViewProps;
text1Style?: StyleProp<TextStyle>;
text1NumberOfLines?: number;
text1Props?: TextProps;
text2Style?: StyleProp<TextStyle>;
text2NumberOfLines?: number;
text2Props?: TextProps;
renderLeadingIcon?: () => React.ReactNode;
renderTrailingIcon?: () => React.ReactNode;
};
export type ToastConfigParams<Props> = {
position: ToastPosition;
type: ToastType;
isVisible: boolean;
text1?: string;
text2?: string;
text1Style?: StyleProp<TextStyle>;
text2Style?: StyleProp<TextStyle>;
show: (params: ToastShowParams) => void;
hide: (params: ToastHideParams) => void;
onPress: () => void;
props: Props;
};
export type ToastConfig = {
[key: string]: (params: ToastConfigParams<any>) => React.ReactNode;
};
export type ToastRef = {
show: (params: ToastShowParams) => void;
hide: (params: ToastHideParams) => void;
};
/**
* `props` that can be set on the Toast instance.
* They act as defaults for all Toasts that are shown.
*/
export type ToastProps = {
/**
* Layout configuration for custom Toast types
*/
config?: ToastConfig;
/**
* Toast type.
* Default value: `success`
*/
type?: ToastType;
/**
* Toast position.
* Default value: `top`
*/
position?: ToastPosition;
/**
* Number of milliseconds after which Toast automatically hides.
* Has effect only in conjunction with `autoHide` prop set to `true`.
* Default value: `4000`
*/
visibilityTime?: number;
/**
* When `true`, the Toast can be dismissed by a swipe gesture, specified by the `swipeable` prop.
* Default value: `true`
*/
swipeable?: boolean;
/**
* When `true`, the visible Toast automatically hides after a certain number of milliseconds,
* specified by the `visibilityTime` prop.
* Default value: `true`
*/
autoHide?: boolean;
/**
* Offset from the top of the screen (in px).
* Has effect only when `position` is `top`
* Default value: `40`
*/
topOffset?: number;
/**
* Offset from the bottom of the screen (in px)
* Has effect only when `position` is `bottom`
* Default value: `40`
*/
bottomOffset?: number;
/**
* Offset from the Keyboard (in px)
* Has effect only when `position` is `bottom` and Keyboard is visible (iOS only)
* Default value: `10`
*/
keyboardOffset?: number;
/**
* When `true` offset calculation use KeyboardHeight in position calculation.
* If you put <Toast /> inside a keyboard aware component and position is 'bottom', you should set this to `false`.
* Default value: true
*/
avoidKeyboard?: boolean;
/**
* Called when any Toast is shown
*/
onShow?: () => void;
/**
* Called when any Toast hides
*/
onHide?: () => void;
/**
* Called on any Toast press
*/
onPress?: () => void;
};