-
-
Notifications
You must be signed in to change notification settings - Fork 5k
/
types.tsx
229 lines (213 loc) · 6.47 KB
/
types.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
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
220
221
222
223
224
225
226
227
228
229
import type { StyleProp, ViewStyle, TextStyle } from 'react-native';
import type Animated from 'react-native-reanimated';
import type { PanGestureHandlerProperties } from 'react-native-gesture-handler';
import type {
Route,
ParamListBase,
NavigationProp,
Descriptor,
NavigationHelpers,
DrawerNavigationState,
DrawerActionHelpers,
RouteProp,
} from '@react-navigation/native';
export type Scene = {
route: Route<string>;
focused: boolean;
color?: string;
};
export type DrawerNavigationConfig<T = DrawerContentOptions> = {
/**
* Position of the drawer on the screen. Defaults to `left`.
*/
drawerPosition?: 'left' | 'right';
/**
* Type of the drawer. It determines how the drawer looks and animates.
* - `front`: Traditional drawer which covers the screen with a overlay behind it.
* - `back`: The drawer is revealed behind the screen on swipe.
* - `slide`: Both the screen and the drawer slide on swipe to reveal the drawer.
* - `permanent`: A permanent drawer is shown as a sidebar.
*/
drawerType?: 'front' | 'back' | 'slide' | 'permanent';
/**
* How far from the edge of the screen the swipe gesture should activate.
* Not supported on Web.
*/
edgeWidth?: number;
/**
* Whether the statusbar should be hidden when the drawer is pulled or opens,
*/
hideStatusBar?: boolean;
/**
* Whether the keyboard should be dismissed when the swipe gesture begins.
* Defaults to `'on-drag'`. Set to `'none'` to disable keyboard handling.
*/
keyboardDismissMode?: 'on-drag' | 'none';
/**
* Minimum swipe distance threshold that should activate opening the drawer.
*/
minSwipeDistance?: number;
/**
* Color of the overlay to be displayed on top of the content view when drawer gets open.
* The opacity is animated from `0` to `1` when the drawer opens.
*/
overlayColor?: string;
/**
* Animation of the statusbar when hiding it. use in combination with `hideStatusBar`.
*/
statusBarAnimation?: 'slide' | 'none' | 'fade';
/**
* Props to pass to the underlying pan gesture handler.
* Not supported on Web.
*/
gestureHandlerProps?: PanGestureHandlerProperties;
/**
* Whether the screens should render the first time they are accessed. Defaults to `true`.
* Set it to `false` if you want to render all screens on initial render.
*/
lazy?: boolean;
/**
* Function that returns React element to render as the content of the drawer, for example, navigation items.
* Defaults to `DrawerContent`.
*/
drawerContent?: (props: DrawerContentComponentProps<T>) => React.ReactNode;
/**
* Options for the content component which will be passed as props.
*/
drawerContentOptions?: T;
/**
* Style object for the component wrapping the screen content.
*/
sceneContainerStyle?: StyleProp<ViewStyle>;
/**
* Style object for the drawer component.
* You can pass a custom background color for a drawer or a custom width here.
*/
drawerStyle?: StyleProp<ViewStyle>;
};
export type DrawerNavigationOptions = {
/**
* Title text for the screen.
*/
title?: string;
/**
* Title string of a screen displayed in the drawer
* or a function that given { focused: boolean, color: string } returns a React.Node
* When undefined, scene title is used.
*/
drawerLabel?:
| string
| ((props: { color: string; focused: boolean }) => React.ReactNode);
/**
* A function that given { focused: boolean, color: string } returns a React.Node to display an icon the drawer.
*/
drawerIcon?: (props: {
color: string;
size: number;
focused: boolean;
}) => React.ReactNode;
/**
* Whether you can use gestures to open or close the drawer.
* Setting this to `false` disables swipe gestures as well as tap on overlay to close.
* See `swipeEnabled` to disable only the swipe gesture.
* Defaults to `true`.
* Not supported on Web.
*/
gestureEnabled?: boolean;
/**
* Whether you can use swipe gestures to open or close the drawer.
* Defaults to `true`.
* Not supported on Web.
*/
swipeEnabled?: boolean;
/**
* Whether this screen should be unmounted when navigating away from it.
* Defaults to `false`.
*/
unmountOnBlur?: boolean;
};
export type DrawerContentComponentProps<T = DrawerContentOptions> = T & {
state: DrawerNavigationState<ParamListBase>;
navigation: DrawerNavigationHelpers;
descriptors: DrawerDescriptorMap;
/**
* Animated node which represents the current progress of the drawer's open state.
* `0` is closed, `1` is open.
*/
progress: Animated.Node<number>;
};
export type DrawerContentOptions = {
/**
* Color for the icon and label in the active item in the drawer.
*/
activeTintColor?: string;
/**
* Background color for the active item in the drawer.
*/
activeBackgroundColor?: string;
/**
* Color for the icon and label in the inactive items in the drawer.
*/
inactiveTintColor?: string;
/**
* Background color for the inactive items in the drawer.
*/
inactiveBackgroundColor?: string;
/**
* Style object for the single item, which can contain an icon and/or a label.
*/
itemStyle?: StyleProp<ViewStyle>;
/**
* Style object to apply to the `Text` inside content section which renders a label.
*/
labelStyle?: StyleProp<TextStyle>;
/**
* Style object for the content section.
*/
contentContainerStyle?: StyleProp<ViewStyle>;
/**
* Style object for the wrapper view.
*/
style?: StyleProp<ViewStyle>;
};
export type DrawerNavigationEventMap = {
/**
* Event which fires when the drawer opens.
*/
drawerOpen: { data: undefined };
/**
* Event which fires when the drawer closes.
*/
drawerClose: { data: undefined };
};
export type DrawerNavigationHelpers = NavigationHelpers<
ParamListBase,
DrawerNavigationEventMap
>;
export type DrawerNavigationProp<
ParamList extends ParamListBase,
RouteName extends keyof ParamList = string
> = NavigationProp<
ParamList,
RouteName,
DrawerNavigationState<ParamList>,
DrawerNavigationOptions,
DrawerNavigationEventMap
> &
DrawerActionHelpers<ParamList>;
export type DrawerScreenProps<
ParamList extends ParamListBase,
RouteName extends keyof ParamList = string
> = {
navigation: DrawerNavigationProp<ParamList, RouteName>;
route: RouteProp<ParamList, RouteName>;
};
export type DrawerDescriptor = Descriptor<
ParamListBase,
string,
DrawerNavigationState<ParamListBase>,
DrawerNavigationOptions
>;
export type DrawerDescriptorMap = {
[key: string]: DrawerDescriptor;
};