-
-
Notifications
You must be signed in to change notification settings - Fork 5k
/
createDrawerNavigator.tsx
115 lines (105 loc) · 3.01 KB
/
createDrawerNavigator.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
import {
createNavigatorFactory,
DefaultNavigatorOptions,
DrawerActionHelpers,
DrawerNavigationState,
DrawerRouter,
DrawerRouterOptions,
ParamListBase,
useNavigationBuilder,
} from '@react-navigation/native';
import * as React from 'react';
import warnOnce from 'warn-once';
import type {
DrawerNavigationConfig,
DrawerNavigationEventMap,
DrawerNavigationOptions,
} from '../types';
import DrawerView from '../views/DrawerView';
type Props = DefaultNavigatorOptions<
ParamListBase,
DrawerNavigationState<ParamListBase>,
DrawerNavigationOptions,
DrawerNavigationEventMap
> &
DrawerRouterOptions &
DrawerNavigationConfig;
function DrawerNavigator({
initialRouteName,
defaultStatus,
backBehavior,
children,
screenListeners,
screenOptions,
// @ts-expect-error: lazy is deprecated
lazy,
// @ts-expect-error: drawerContentOptions is deprecated
drawerContentOptions,
...rest
}: Props) {
let defaultScreenOptions: DrawerNavigationOptions = {};
if (drawerContentOptions) {
Object.assign(defaultScreenOptions, {
drawerPosition: drawerContentOptions.drawerPosition,
drawerType: drawerContentOptions.drawerType,
swipeEdgeWidth: drawerContentOptions.edgeWidth,
drawerHideStatusBarOnOpen: drawerContentOptions.hideStatusBar,
keyboardDismissMode: drawerContentOptions.keyboardDismissMode,
swipeMinDistance: drawerContentOptions.minSwipeDistance,
overlayColor: drawerContentOptions.overlayColor,
drawerStatusBarAnimation: drawerContentOptions.statusBarAnimation,
gestureHandlerProps: drawerContentOptions.gestureHandlerProps,
});
warnOnce(
drawerContentOptions,
`Drawer Navigator: 'drawerContentOptions' is deprecated. Migrate the options to 'screenOptions' instead.\n\nPlace the following in 'screenOptions' in your code to keep current behavior:\n\n${JSON.stringify(
defaultScreenOptions,
null,
2
)}\n\nSee https://reactnavigation.org/docs/6.x/drawer-navigator#options for more details.`
);
}
if (typeof lazy === 'boolean') {
defaultScreenOptions.lazy = lazy;
warnOnce(
true,
`Drawer Navigator: 'lazy' in props is deprecated. Move it to 'screenOptions' instead.`
);
}
const {
state,
descriptors,
navigation,
NavigationContent,
} = useNavigationBuilder<
DrawerNavigationState<ParamListBase>,
DrawerRouterOptions,
DrawerActionHelpers<ParamListBase>,
DrawerNavigationOptions,
DrawerNavigationEventMap
>(DrawerRouter, {
initialRouteName,
defaultStatus,
backBehavior,
children,
screenListeners,
screenOptions,
defaultScreenOptions,
});
return (
<NavigationContent>
<DrawerView
{...rest}
state={state}
descriptors={descriptors}
navigation={navigation}
/>
</NavigationContent>
);
}
export default createNavigatorFactory<
DrawerNavigationState<ParamListBase>,
DrawerNavigationOptions,
DrawerNavigationEventMap,
typeof DrawerNavigator
>(DrawerNavigator);