@react-navigation/drawer 6.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/lib/commonjs/index.js +104 -0
  4. package/lib/commonjs/index.js.map +1 -0
  5. package/lib/commonjs/navigators/createDrawerNavigator.js +95 -0
  6. package/lib/commonjs/navigators/createDrawerNavigator.js.map +1 -0
  7. package/lib/commonjs/types.js +6 -0
  8. package/lib/commonjs/types.js.map +1 -0
  9. package/lib/commonjs/utils/DrawerGestureContext.js +17 -0
  10. package/lib/commonjs/utils/DrawerGestureContext.js.map +1 -0
  11. package/lib/commonjs/utils/DrawerPositionContext.js +17 -0
  12. package/lib/commonjs/utils/DrawerPositionContext.js.map +1 -0
  13. package/lib/commonjs/utils/DrawerProgressContext.js +17 -0
  14. package/lib/commonjs/utils/DrawerProgressContext.js.map +1 -0
  15. package/lib/commonjs/utils/DrawerStatusContext.js +17 -0
  16. package/lib/commonjs/utils/DrawerStatusContext.js.map +1 -0
  17. package/lib/commonjs/utils/getDrawerStatusFromState.js +18 -0
  18. package/lib/commonjs/utils/getDrawerStatusFromState.js.map +1 -0
  19. package/lib/commonjs/utils/useDrawerProgress.js +27 -0
  20. package/lib/commonjs/utils/useDrawerProgress.js.map +1 -0
  21. package/lib/commonjs/utils/useDrawerStatus.js +31 -0
  22. package/lib/commonjs/utils/useDrawerStatus.js.map +1 -0
  23. package/lib/commonjs/views/DrawerContent.js +42 -0
  24. package/lib/commonjs/views/DrawerContent.js.map +1 -0
  25. package/lib/commonjs/views/DrawerContentScrollView.js +53 -0
  26. package/lib/commonjs/views/DrawerContentScrollView.js.map +1 -0
  27. package/lib/commonjs/views/DrawerItem.js +152 -0
  28. package/lib/commonjs/views/DrawerItem.js.map +1 -0
  29. package/lib/commonjs/views/DrawerItemList.js +70 -0
  30. package/lib/commonjs/views/DrawerItemList.js.map +1 -0
  31. package/lib/commonjs/views/DrawerToggleButton.js +64 -0
  32. package/lib/commonjs/views/DrawerToggleButton.js.map +1 -0
  33. package/lib/commonjs/views/DrawerView.js +282 -0
  34. package/lib/commonjs/views/DrawerView.js.map +1 -0
  35. package/lib/commonjs/views/GestureHandler.android.js +19 -0
  36. package/lib/commonjs/views/GestureHandler.android.js.map +1 -0
  37. package/lib/commonjs/views/GestureHandler.ios.js +19 -0
  38. package/lib/commonjs/views/GestureHandler.ios.js.map +1 -0
  39. package/lib/commonjs/views/GestureHandler.js +35 -0
  40. package/lib/commonjs/views/GestureHandler.js.map +1 -0
  41. package/lib/commonjs/views/GestureHandlerNative.js +50 -0
  42. package/lib/commonjs/views/GestureHandlerNative.js.map +1 -0
  43. package/lib/commonjs/views/ScreenFallback.js +62 -0
  44. package/lib/commonjs/views/ScreenFallback.js.map +1 -0
  45. package/lib/commonjs/views/assets/toggle-drawer-icon.png +0 -0
  46. package/lib/commonjs/views/assets/toggle-drawer-icon@1.5x.android.png +0 -0
  47. package/lib/commonjs/views/assets/toggle-drawer-icon@1.5x.ios.png +0 -0
  48. package/lib/commonjs/views/assets/toggle-drawer-icon@1x.android.png +0 -0
  49. package/lib/commonjs/views/assets/toggle-drawer-icon@1x.ios.png +0 -0
  50. package/lib/commonjs/views/assets/toggle-drawer-icon@2x.android.png +0 -0
  51. package/lib/commonjs/views/assets/toggle-drawer-icon@2x.ios.png +0 -0
  52. package/lib/commonjs/views/assets/toggle-drawer-icon@3x.android.png +0 -0
  53. package/lib/commonjs/views/assets/toggle-drawer-icon@3x.ios.png +0 -0
  54. package/lib/commonjs/views/assets/toggle-drawer-icon@4x.android.png +0 -0
  55. package/lib/commonjs/views/assets/toggle-drawer-icon@4x.ios.png +0 -0
  56. package/lib/commonjs/views/legacy/Drawer.js +455 -0
  57. package/lib/commonjs/views/legacy/Drawer.js.map +1 -0
  58. package/lib/commonjs/views/legacy/Overlay.js +79 -0
  59. package/lib/commonjs/views/legacy/Overlay.js.map +1 -0
  60. package/lib/commonjs/views/modern/Drawer.js +293 -0
  61. package/lib/commonjs/views/modern/Drawer.js.map +1 -0
  62. package/lib/commonjs/views/modern/Overlay.js +65 -0
  63. package/lib/commonjs/views/modern/Overlay.js.map +1 -0
  64. package/lib/module/index.js +27 -0
  65. package/lib/module/index.js.map +1 -0
  66. package/lib/module/navigators/createDrawerNavigator.js +77 -0
  67. package/lib/module/navigators/createDrawerNavigator.js.map +1 -0
  68. package/lib/module/types.js +2 -0
  69. package/lib/module/types.js.map +1 -0
  70. package/lib/module/utils/DrawerGestureContext.js +3 -0
  71. package/lib/module/utils/DrawerGestureContext.js.map +1 -0
  72. package/lib/module/utils/DrawerPositionContext.js +3 -0
  73. package/lib/module/utils/DrawerPositionContext.js.map +1 -0
  74. package/lib/module/utils/DrawerProgressContext.js +3 -0
  75. package/lib/module/utils/DrawerProgressContext.js.map +1 -0
  76. package/lib/module/utils/DrawerStatusContext.js +4 -0
  77. package/lib/module/utils/DrawerStatusContext.js.map +1 -0
  78. package/lib/module/utils/getDrawerStatusFromState.js +11 -0
  79. package/lib/module/utils/getDrawerStatusFromState.js.map +1 -0
  80. package/lib/module/utils/useDrawerProgress.js +12 -0
  81. package/lib/module/utils/useDrawerProgress.js.map +1 -0
  82. package/lib/module/utils/useDrawerStatus.js +17 -0
  83. package/lib/module/utils/useDrawerStatus.js.map +1 -0
  84. package/lib/module/views/DrawerContent.js +26 -0
  85. package/lib/module/views/DrawerContent.js.map +1 -0
  86. package/lib/module/views/DrawerContentScrollView.js +34 -0
  87. package/lib/module/views/DrawerContentScrollView.js.map +1 -0
  88. package/lib/module/views/DrawerItem.js +132 -0
  89. package/lib/module/views/DrawerItem.js.map +1 -0
  90. package/lib/module/views/DrawerItemList.js +55 -0
  91. package/lib/module/views/DrawerItemList.js.map +1 -0
  92. package/lib/module/views/DrawerToggleButton.js +48 -0
  93. package/lib/module/views/DrawerToggleButton.js.map +1 -0
  94. package/lib/module/views/DrawerView.js +256 -0
  95. package/lib/module/views/DrawerView.js.map +1 -0
  96. package/lib/module/views/GestureHandler.android.js +2 -0
  97. package/lib/module/views/GestureHandler.android.js.map +1 -0
  98. package/lib/module/views/GestureHandler.ios.js +2 -0
  99. package/lib/module/views/GestureHandler.ios.js.map +1 -0
  100. package/lib/module/views/GestureHandler.js +19 -0
  101. package/lib/module/views/GestureHandler.js.map +1 -0
  102. package/lib/module/views/GestureHandlerNative.js +11 -0
  103. package/lib/module/views/GestureHandlerNative.js.map +1 -0
  104. package/lib/module/views/ScreenFallback.js +44 -0
  105. package/lib/module/views/ScreenFallback.js.map +1 -0
  106. package/lib/module/views/assets/toggle-drawer-icon.png +0 -0
  107. package/lib/module/views/assets/toggle-drawer-icon@1.5x.android.png +0 -0
  108. package/lib/module/views/assets/toggle-drawer-icon@1.5x.ios.png +0 -0
  109. package/lib/module/views/assets/toggle-drawer-icon@1x.android.png +0 -0
  110. package/lib/module/views/assets/toggle-drawer-icon@1x.ios.png +0 -0
  111. package/lib/module/views/assets/toggle-drawer-icon@2x.android.png +0 -0
  112. package/lib/module/views/assets/toggle-drawer-icon@2x.ios.png +0 -0
  113. package/lib/module/views/assets/toggle-drawer-icon@3x.android.png +0 -0
  114. package/lib/module/views/assets/toggle-drawer-icon@3x.ios.png +0 -0
  115. package/lib/module/views/assets/toggle-drawer-icon@4x.android.png +0 -0
  116. package/lib/module/views/assets/toggle-drawer-icon@4x.ios.png +0 -0
  117. package/lib/module/views/legacy/Drawer.js +430 -0
  118. package/lib/module/views/legacy/Drawer.js.map +1 -0
  119. package/lib/module/views/legacy/Overlay.js +59 -0
  120. package/lib/module/views/legacy/Overlay.js.map +1 -0
  121. package/lib/module/views/modern/Drawer.js +272 -0
  122. package/lib/module/views/modern/Drawer.js.map +1 -0
  123. package/lib/module/views/modern/Overlay.js +47 -0
  124. package/lib/module/views/modern/Overlay.js.map +1 -0
  125. package/lib/typescript/src/index.d.ts +25 -0
  126. package/lib/typescript/src/navigators/createDrawerNavigator.d.ts +7 -0
  127. package/lib/typescript/src/types.d.ts +235 -0
  128. package/lib/typescript/src/utils/DrawerGestureContext.d.ts +3 -0
  129. package/lib/typescript/src/utils/DrawerPositionContext.d.ts +3 -0
  130. package/lib/typescript/src/utils/DrawerProgressContext.d.ts +4 -0
  131. package/lib/typescript/src/utils/DrawerStatusContext.d.ts +3 -0
  132. package/lib/typescript/src/utils/getDrawerStatusFromState.d.ts +2 -0
  133. package/lib/typescript/src/utils/useDrawerProgress.d.ts +2 -0
  134. package/lib/typescript/src/utils/useDrawerStatus.d.ts +5 -0
  135. package/lib/typescript/src/views/DrawerContent.d.ts +3 -0
  136. package/lib/typescript/src/views/DrawerContentScrollView.d.ts +6 -0
  137. package/lib/typescript/src/views/DrawerItem.d.ts +74 -0
  138. package/lib/typescript/src/views/DrawerItemList.d.ts +13 -0
  139. package/lib/typescript/src/views/DrawerToggleButton.d.ts +9 -0
  140. package/lib/typescript/src/views/DrawerView.d.ts +10 -0
  141. package/lib/typescript/src/views/GestureHandler.android.d.ts +1 -0
  142. package/lib/typescript/src/views/GestureHandler.d.ts +14 -0
  143. package/lib/typescript/src/views/GestureHandler.ios.d.ts +1 -0
  144. package/lib/typescript/src/views/GestureHandlerNative.d.ts +4 -0
  145. package/lib/typescript/src/views/ScreenFallback.d.ts +14 -0
  146. package/lib/typescript/src/views/legacy/Drawer.d.ts +44 -0
  147. package/lib/typescript/src/views/legacy/Overlay.d.ts +68 -0
  148. package/lib/typescript/src/views/modern/Drawer.d.ts +3 -0
  149. package/lib/typescript/src/views/modern/Overlay.d.ts +68 -0
  150. package/package.json +87 -0
  151. package/src/index.tsx +34 -0
  152. package/src/navigators/createDrawerNavigator.tsx +134 -0
  153. package/src/types.tsx +300 -0
  154. package/src/utils/DrawerGestureContext.tsx +3 -0
  155. package/src/utils/DrawerPositionContext.tsx +3 -0
  156. package/src/utils/DrawerProgressContext.tsx +6 -0
  157. package/src/utils/DrawerStatusContext.tsx +6 -0
  158. package/src/utils/getDrawerStatusFromState.tsx +20 -0
  159. package/src/utils/useDrawerProgress.tsx +18 -0
  160. package/src/utils/useDrawerStatus.tsx +19 -0
  161. package/src/views/DrawerContent.tsx +27 -0
  162. package/src/views/DrawerContentScrollView.tsx +52 -0
  163. package/src/views/DrawerItem.tsx +227 -0
  164. package/src/views/DrawerItemList.tsx +80 -0
  165. package/src/views/DrawerToggleButton.tsx +54 -0
  166. package/src/views/DrawerView.tsx +313 -0
  167. package/src/views/GestureHandler.android.tsx +1 -0
  168. package/src/views/GestureHandler.ios.tsx +1 -0
  169. package/src/views/GestureHandler.tsx +29 -0
  170. package/src/views/GestureHandlerNative.tsx +24 -0
  171. package/src/views/ScreenFallback.tsx +48 -0
  172. package/src/views/assets/toggle-drawer-icon.png +0 -0
  173. package/src/views/assets/toggle-drawer-icon@1.5x.android.png +0 -0
  174. package/src/views/assets/toggle-drawer-icon@1.5x.ios.png +0 -0
  175. package/src/views/assets/toggle-drawer-icon@1x.android.png +0 -0
  176. package/src/views/assets/toggle-drawer-icon@1x.ios.png +0 -0
  177. package/src/views/assets/toggle-drawer-icon@2x.android.png +0 -0
  178. package/src/views/assets/toggle-drawer-icon@2x.ios.png +0 -0
  179. package/src/views/assets/toggle-drawer-icon@3x.android.png +0 -0
  180. package/src/views/assets/toggle-drawer-icon@3x.ios.png +0 -0
  181. package/src/views/assets/toggle-drawer-icon@4x.android.png +0 -0
  182. package/src/views/assets/toggle-drawer-icon@4x.ios.png +0 -0
  183. package/src/views/legacy/Drawer.tsx +659 -0
  184. package/src/views/legacy/Overlay.tsx +74 -0
  185. package/src/views/modern/Drawer.tsx +385 -0
  186. package/src/views/modern/Overlay.tsx +56 -0
package/package.json ADDED
@@ -0,0 +1,87 @@
1
+ {
2
+ "name": "@react-navigation/drawer",
3
+ "description": "Drawer navigator component with animated transitions and gesturess",
4
+ "version": "6.1.5",
5
+ "keywords": [
6
+ "react-native-component",
7
+ "react-component",
8
+ "react-native",
9
+ "react-navigation",
10
+ "ios",
11
+ "android",
12
+ "material",
13
+ "drawer"
14
+ ],
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/react-navigation/react-navigation.git",
19
+ "directory": "packages/drawer"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/react-navigation/react-navigation/issues"
23
+ },
24
+ "homepage": "https://reactnavigation.org/docs/drawer-navigator/",
25
+ "main": "lib/commonjs/index.js",
26
+ "react-native": "src/index.tsx",
27
+ "source": "src/index.tsx",
28
+ "module": "lib/module/index.js",
29
+ "types": "lib/typescript/src/index.d.ts",
30
+ "files": [
31
+ "src",
32
+ "lib",
33
+ "!**/__tests__"
34
+ ],
35
+ "sideEffects": false,
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "scripts": {
40
+ "prepare": "bob build",
41
+ "clean": "del lib"
42
+ },
43
+ "dependencies": {
44
+ "@react-navigation/elements": "^1.1.1",
45
+ "color": "^3.1.3",
46
+ "warn-once": "^0.1.0"
47
+ },
48
+ "devDependencies": {
49
+ "@react-navigation/native": "^6.0.3",
50
+ "@testing-library/react-native": "^7.2.0",
51
+ "@types/react": "^17.0.9",
52
+ "@types/react-native": "~0.64.9",
53
+ "del-cli": "^3.0.1",
54
+ "react": "~16.13.1",
55
+ "react-native": "~0.63.4",
56
+ "react-native-builder-bob": "^0.18.1",
57
+ "react-native-gesture-handler": "~1.10.2",
58
+ "react-native-reanimated": "~2.2.0",
59
+ "react-native-safe-area-context": "~3.2.0",
60
+ "react-native-screens": "~3.3.0",
61
+ "typescript": "^4.3.2"
62
+ },
63
+ "peerDependencies": {
64
+ "@react-navigation/native": "^6.0.0",
65
+ "react": "*",
66
+ "react-native": "*",
67
+ "react-native-gesture-handler": ">= 1.0.0",
68
+ "react-native-reanimated": ">= 1.0.0",
69
+ "react-native-safe-area-context": ">= 3.0.0",
70
+ "react-native-screens": ">= 3.0.0"
71
+ },
72
+ "react-native-builder-bob": {
73
+ "source": "src",
74
+ "output": "lib",
75
+ "targets": [
76
+ "commonjs",
77
+ "module",
78
+ [
79
+ "typescript",
80
+ {
81
+ "project": "tsconfig.build.json"
82
+ }
83
+ ]
84
+ ]
85
+ },
86
+ "gitHead": "38ac69f17ee314f96d3d4bcee02349fa4a02d422"
87
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Navigators
3
+ */
4
+ export { default as createDrawerNavigator } from './navigators/createDrawerNavigator';
5
+
6
+ /**
7
+ * Views
8
+ */
9
+ export { default as DrawerContent } from './views/DrawerContent';
10
+ export { default as DrawerContentScrollView } from './views/DrawerContentScrollView';
11
+ export { default as DrawerItem } from './views/DrawerItem';
12
+ export { default as DrawerItemList } from './views/DrawerItemList';
13
+ export { default as DrawerToggleButton } from './views/DrawerToggleButton';
14
+ export { default as DrawerView } from './views/DrawerView';
15
+
16
+ /**
17
+ * Utilities
18
+ */
19
+ export { default as DrawerGestureContext } from './utils/DrawerGestureContext';
20
+ export { default as DrawerProgressContext } from './utils/DrawerProgressContext';
21
+ export { default as getDrawerStatusFromState } from './utils/getDrawerStatusFromState';
22
+ export { default as useDrawerProgress } from './utils/useDrawerProgress';
23
+ export { default as useDrawerStatus } from './utils/useDrawerStatus';
24
+
25
+ /**
26
+ * Types
27
+ */
28
+ export type {
29
+ DrawerContentComponentProps,
30
+ DrawerHeaderProps,
31
+ DrawerNavigationOptions,
32
+ DrawerNavigationProp,
33
+ DrawerScreenProps,
34
+ } from './types';
@@ -0,0 +1,134 @@
1
+ import {
2
+ createNavigatorFactory,
3
+ DefaultNavigatorOptions,
4
+ DrawerActionHelpers,
5
+ DrawerNavigationState,
6
+ DrawerRouter,
7
+ DrawerRouterOptions,
8
+ ParamListBase,
9
+ useNavigationBuilder,
10
+ } from '@react-navigation/native';
11
+ import * as React from 'react';
12
+ import warnOnce from 'warn-once';
13
+
14
+ import type {
15
+ DrawerNavigationConfig,
16
+ DrawerNavigationEventMap,
17
+ DrawerNavigationOptions,
18
+ } from '../types';
19
+ import DrawerView from '../views/DrawerView';
20
+
21
+ type Props = DefaultNavigatorOptions<
22
+ ParamListBase,
23
+ DrawerNavigationState<ParamListBase>,
24
+ DrawerNavigationOptions,
25
+ DrawerNavigationEventMap
26
+ > &
27
+ DrawerRouterOptions &
28
+ DrawerNavigationConfig;
29
+
30
+ function DrawerNavigator({
31
+ initialRouteName,
32
+ defaultStatus,
33
+ backBehavior,
34
+ children,
35
+ screenListeners,
36
+ screenOptions,
37
+ // @ts-expect-error: openByDefault is deprecated
38
+ openByDefault,
39
+ // @ts-expect-error: lazy is deprecated
40
+ lazy,
41
+ // @ts-expect-error: drawerContentOptions is deprecated
42
+ drawerContentOptions,
43
+ ...rest
44
+ }: Props) {
45
+ let defaultScreenOptions: DrawerNavigationOptions = {};
46
+
47
+ if (drawerContentOptions) {
48
+ Object.assign(defaultScreenOptions, {
49
+ drawerPosition: drawerContentOptions.drawerPosition,
50
+ drawerType: drawerContentOptions.drawerType,
51
+ swipeEdgeWidth: drawerContentOptions.edgeWidth,
52
+ drawerHideStatusBarOnOpen: drawerContentOptions.hideStatusBar,
53
+ keyboardDismissMode: drawerContentOptions.keyboardDismissMode,
54
+ swipeMinDistance: drawerContentOptions.minSwipeDistance,
55
+ overlayColor: drawerContentOptions.overlayColor,
56
+ drawerStatusBarAnimation: drawerContentOptions.statusBarAnimation,
57
+ gestureHandlerProps: drawerContentOptions.gestureHandlerProps,
58
+ });
59
+
60
+ (
61
+ Object.keys(defaultScreenOptions) as (keyof DrawerNavigationOptions)[]
62
+ ).forEach((key) => {
63
+ if (defaultScreenOptions[key] === undefined) {
64
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
65
+ delete defaultScreenOptions[key];
66
+ }
67
+ });
68
+
69
+ warnOnce(
70
+ drawerContentOptions,
71
+ `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(
72
+ defaultScreenOptions,
73
+ null,
74
+ 2
75
+ )}\n\nSee https://reactnavigation.org/docs/drawer-navigator#options for more details.`
76
+ );
77
+ }
78
+
79
+ if (typeof lazy === 'boolean') {
80
+ defaultScreenOptions.lazy = lazy;
81
+
82
+ warnOnce(
83
+ true,
84
+ `Drawer Navigator: 'lazy' in props is deprecated. Move it to 'screenOptions' instead.\n\nSee https://reactnavigation.org/docs/drawer-navigator/#lazy for more details.`
85
+ );
86
+ }
87
+
88
+ if (typeof openByDefault === 'boolean') {
89
+ warnOnce(
90
+ true,
91
+ `Drawer Navigator: 'openByDefault' is deprecated. Use 'defaultStatus' and set it to 'open' or 'closed' instead.\n\nSee https://reactnavigation.org/docs/drawer-navigator/#defaultstatus for more details.`
92
+ );
93
+ }
94
+
95
+ const { state, descriptors, navigation, NavigationContent } =
96
+ useNavigationBuilder<
97
+ DrawerNavigationState<ParamListBase>,
98
+ DrawerRouterOptions,
99
+ DrawerActionHelpers<ParamListBase>,
100
+ DrawerNavigationOptions,
101
+ DrawerNavigationEventMap
102
+ >(DrawerRouter, {
103
+ initialRouteName,
104
+ defaultStatus:
105
+ defaultStatus !== undefined
106
+ ? defaultStatus
107
+ : openByDefault
108
+ ? 'open'
109
+ : 'closed',
110
+ backBehavior,
111
+ children,
112
+ screenListeners,
113
+ screenOptions,
114
+ defaultScreenOptions,
115
+ });
116
+
117
+ return (
118
+ <NavigationContent>
119
+ <DrawerView
120
+ {...rest}
121
+ state={state}
122
+ descriptors={descriptors}
123
+ navigation={navigation}
124
+ />
125
+ </NavigationContent>
126
+ );
127
+ }
128
+
129
+ export default createNavigatorFactory<
130
+ DrawerNavigationState<ParamListBase>,
131
+ DrawerNavigationOptions,
132
+ DrawerNavigationEventMap,
133
+ typeof DrawerNavigator
134
+ >(DrawerNavigator);
package/src/types.tsx ADDED
@@ -0,0 +1,300 @@
1
+ import type { HeaderOptions } from '@react-navigation/elements';
2
+ import type {
3
+ Descriptor,
4
+ DrawerActionHelpers,
5
+ DrawerNavigationState,
6
+ NavigationHelpers,
7
+ NavigationProp,
8
+ ParamListBase,
9
+ Route,
10
+ RouteProp,
11
+ } from '@react-navigation/native';
12
+ import type { StyleProp, TextStyle, ViewStyle } from 'react-native';
13
+ import type {
14
+ PanGestureHandler,
15
+ PanGestureHandlerProperties,
16
+ } from 'react-native-gesture-handler';
17
+
18
+ export type Scene = {
19
+ route: Route<string>;
20
+ focused: boolean;
21
+ color?: string;
22
+ };
23
+
24
+ export type Layout = { width: number; height: number };
25
+
26
+ export type DrawerNavigationConfig = {
27
+ /**
28
+ * Function that returns React element to render as the content of the drawer, for example, navigation items.
29
+ * Defaults to `DrawerContent`.
30
+ */
31
+ drawerContent?: (props: DrawerContentComponentProps) => React.ReactNode;
32
+ /**
33
+ * Whether inactive screens should be detached from the view hierarchy to save memory.
34
+ * Make sure to call `enableScreens` from `react-native-screens` to make it work.
35
+ * Defaults to `true`.
36
+ */
37
+ detachInactiveScreens?: boolean;
38
+ /**
39
+ * Whether to use the legacy implementation based on Reanimated 1.
40
+ * The new implementation based on Reanimated 2 will perform better,
41
+ * but you need additional configuration and need to use Hermes with Flipper to debug.
42
+ *
43
+ * This defaults to `true` in following cases:
44
+ * - Reanimated 2 is not configured
45
+ * - App is connected to Chrome debugger (Reanimated 2 cannot be used with Chrome debugger)
46
+ *
47
+ * Otherwise, it defaults to `false`
48
+ */
49
+ useLegacyImplementation?: boolean;
50
+ };
51
+
52
+ export type DrawerNavigationOptions = HeaderOptions & {
53
+ /**
54
+ * Title text for the screen.
55
+ */
56
+ title?: string;
57
+
58
+ /**
59
+ * Whether this screens should render the first time it's accessed. Defaults to `true`.
60
+ * Set it to `false` if you want to render the screen on initial render.
61
+ */
62
+ lazy?: boolean;
63
+
64
+ /**
65
+ * Function that returns a React Element to display as a header.
66
+ */
67
+ header?: (props: DrawerHeaderProps) => React.ReactNode;
68
+
69
+ /**
70
+ * Whether to show the header. Setting this to `false` hides the header.
71
+ * Defaults to `true`.
72
+ */
73
+ headerShown?: boolean;
74
+
75
+ /**
76
+ * Title string of a screen displayed in the drawer
77
+ * or a function that given { focused: boolean, color: string } returns a React.Node
78
+ * When undefined, scene title is used.
79
+ */
80
+ drawerLabel?:
81
+ | string
82
+ | ((props: { color: string; focused: boolean }) => React.ReactNode);
83
+
84
+ /**
85
+ * A function that given { focused: boolean, color: string } returns a React.Node to display an icon the drawer.
86
+ */
87
+ drawerIcon?: (props: {
88
+ color: string;
89
+ size: number;
90
+ focused: boolean;
91
+ }) => React.ReactNode;
92
+
93
+ /**
94
+ * Color for the icon and label in the active item in the drawer.
95
+ */
96
+ drawerActiveTintColor?: string;
97
+
98
+ /**
99
+ * Background color for the active item in the drawer.
100
+ */
101
+ drawerActiveBackgroundColor?: string;
102
+
103
+ /**
104
+ * Color for the icon and label in the inactive items in the drawer.
105
+ */
106
+ drawerInactiveTintColor?: string;
107
+
108
+ /**
109
+ * Background color for the inactive items in the drawer.
110
+ */
111
+ drawerInactiveBackgroundColor?: string;
112
+
113
+ /**
114
+ * Style object for the single item, which can contain an icon and/or a label.
115
+ */
116
+ drawerItemStyle?: StyleProp<ViewStyle>;
117
+
118
+ /**
119
+ * Style object to apply to the `Text` inside content section which renders a label.
120
+ */
121
+ drawerLabelStyle?: StyleProp<TextStyle>;
122
+
123
+ /**
124
+ * Style object for the content section.
125
+ */
126
+ drawerContentContainerStyle?: StyleProp<ViewStyle>;
127
+
128
+ /**
129
+ * Style object for the wrapper view.
130
+ */
131
+ drawerContentStyle?: StyleProp<ViewStyle>;
132
+
133
+ /**
134
+ * Style object for the drawer component.
135
+ * You can pass a custom background color for a drawer or a custom width here.
136
+ */
137
+ drawerStyle?: StyleProp<ViewStyle>;
138
+
139
+ /**
140
+ * Position of the drawer on the screen. Defaults to `left`.
141
+ */
142
+ drawerPosition?: 'left' | 'right';
143
+
144
+ /**
145
+ * Type of the drawer. It determines how the drawer looks and animates.
146
+ * - `front`: Traditional drawer which covers the screen with a overlay behind it.
147
+ * - `back`: The drawer is revealed behind the screen on swipe.
148
+ * - `slide`: Both the screen and the drawer slide on swipe to reveal the drawer.
149
+ * - `permanent`: A permanent drawer is shown as a sidebar.
150
+ */
151
+ drawerType?: 'front' | 'back' | 'slide' | 'permanent';
152
+
153
+ /**
154
+ * Whether the statusbar should be hidden when the drawer is pulled or opens,
155
+ */
156
+ drawerHideStatusBarOnOpen?: boolean;
157
+
158
+ /**
159
+ * Animation of the statusbar when hiding it. use in combination with `drawerHideStatusBarOnOpen`.
160
+ */
161
+ drawerStatusBarAnimation?: 'slide' | 'none' | 'fade';
162
+
163
+ /**
164
+ * Color of the overlay to be displayed on top of the content view when drawer gets open.
165
+ * The opacity is animated from `0` to `1` when the drawer opens.
166
+ */
167
+ overlayColor?: string;
168
+
169
+ /**
170
+ * Style object for the component wrapping the screen content.
171
+ */
172
+ sceneContainerStyle?: StyleProp<ViewStyle>;
173
+
174
+ /**
175
+ * Whether you can use gestures to open or close the drawer.
176
+ * Setting this to `false` disables swipe gestures as well as tap on overlay to close.
177
+ * See `swipeEnabled` to disable only the swipe gesture.
178
+ * Defaults to `true`.
179
+ * Not supported on Web.
180
+ */
181
+ gestureEnabled?: boolean;
182
+
183
+ /**
184
+ * Props to pass to the underlying pan gesture handler.
185
+ * Not supported on Web.
186
+ */
187
+ gestureHandlerProps?: PanGestureHandlerProperties;
188
+
189
+ /**
190
+ * Whether you can use swipe gestures to open or close the drawer.
191
+ * Defaults to `true`.
192
+ * Not supported on Web.
193
+ */
194
+ swipeEnabled?: boolean;
195
+
196
+ /**
197
+ * How far from the edge of the screen the swipe gesture should activate.
198
+ * Not supported on Web.
199
+ */
200
+ swipeEdgeWidth?: number;
201
+
202
+ /**
203
+ * Minimum swipe distance threshold that should activate opening the drawer.
204
+ */
205
+ swipeMinDistance?: number;
206
+
207
+ /**
208
+ * Whether the keyboard should be dismissed when the swipe gesture begins.
209
+ * Defaults to `'on-drag'`. Set to `'none'` to disable keyboard handling.
210
+ */
211
+ keyboardDismissMode?: 'on-drag' | 'none';
212
+
213
+ /**
214
+ * Whether this screen should be unmounted when navigating away from it.
215
+ * Defaults to `false`.
216
+ */
217
+ unmountOnBlur?: boolean;
218
+ };
219
+
220
+ export type DrawerContentComponentProps = {
221
+ state: DrawerNavigationState<ParamListBase>;
222
+ navigation: DrawerNavigationHelpers;
223
+ descriptors: DrawerDescriptorMap;
224
+ };
225
+
226
+ export type DrawerHeaderProps = {
227
+ /**
228
+ * Layout of the screen.
229
+ */
230
+ layout: Layout;
231
+ /**
232
+ * Options for the current screen.
233
+ */
234
+ options: DrawerNavigationOptions;
235
+ /**
236
+ * Route object for the current screen.
237
+ */
238
+ route: RouteProp<ParamListBase>;
239
+ /**
240
+ * Navigation prop for the header.
241
+ */
242
+ navigation: DrawerNavigationProp<ParamListBase>;
243
+ };
244
+
245
+ export type DrawerNavigationEventMap = {};
246
+
247
+ export type DrawerNavigationHelpers = NavigationHelpers<
248
+ ParamListBase,
249
+ DrawerNavigationEventMap
250
+ > &
251
+ DrawerActionHelpers<ParamListBase>;
252
+
253
+ export type DrawerNavigationProp<
254
+ ParamList extends ParamListBase,
255
+ RouteName extends keyof ParamList = keyof ParamList
256
+ > = NavigationProp<
257
+ ParamList,
258
+ RouteName,
259
+ DrawerNavigationState<ParamList>,
260
+ DrawerNavigationOptions,
261
+ DrawerNavigationEventMap
262
+ > &
263
+ DrawerActionHelpers<ParamList>;
264
+
265
+ export type DrawerScreenProps<
266
+ ParamList extends ParamListBase,
267
+ RouteName extends keyof ParamList = keyof ParamList
268
+ > = {
269
+ navigation: DrawerNavigationProp<ParamList, RouteName>;
270
+ route: RouteProp<ParamList, RouteName>;
271
+ };
272
+
273
+ export type DrawerDescriptor = Descriptor<
274
+ DrawerNavigationOptions,
275
+ DrawerNavigationProp<ParamListBase>,
276
+ RouteProp<ParamListBase>
277
+ >;
278
+
279
+ export type DrawerDescriptorMap = Record<string, DrawerDescriptor>;
280
+
281
+ export type DrawerProps = {
282
+ dimensions: { width: number; height: number };
283
+ drawerPosition: 'left' | 'right';
284
+ drawerStyle?: StyleProp<ViewStyle>;
285
+ drawerType: 'front' | 'back' | 'slide' | 'permanent';
286
+ gestureHandlerProps?: React.ComponentProps<typeof PanGestureHandler>;
287
+ hideStatusBarOnOpen: boolean;
288
+ keyboardDismissMode: 'none' | 'on-drag';
289
+ onClose: () => void;
290
+ onOpen: () => void;
291
+ open: boolean;
292
+ overlayStyle?: StyleProp<ViewStyle>;
293
+ renderDrawerContent: () => React.ReactNode;
294
+ renderSceneContent: () => React.ReactNode;
295
+ statusBarAnimation: 'slide' | 'none' | 'fade';
296
+ swipeDistanceThreshold: number;
297
+ swipeEdgeWidth: number;
298
+ swipeEnabled: boolean;
299
+ swipeVelocityThreshold: number;
300
+ };
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+
3
+ export default React.createContext<React.RefObject<any> | null>(null);
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+
3
+ export default React.createContext<'left' | 'right' | undefined>(undefined);
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+ import type Animated from 'react-native-reanimated';
3
+
4
+ export default React.createContext<
5
+ Readonly<Animated.SharedValue<number>> | Animated.Node<number> | undefined
6
+ >(undefined);
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+
3
+ const DrawerStatusContext =
4
+ React.createContext<'open' | 'closed' | undefined>(undefined);
5
+
6
+ export default DrawerStatusContext;
@@ -0,0 +1,20 @@
1
+ import type {
2
+ DrawerNavigationState,
3
+ ParamListBase,
4
+ } from '@react-navigation/native';
5
+
6
+ export default function getDrawerStatusFromState(
7
+ state: DrawerNavigationState<ParamListBase>
8
+ ) {
9
+ if (state.history == null) {
10
+ throw new Error(
11
+ "Couldn't find the drawer status in the state object. Is it a valid state object of drawer navigator?"
12
+ );
13
+ }
14
+
15
+ const entry = state.history.find((it) => it.type === 'drawer') as
16
+ | { type: 'drawer'; status: 'open' }
17
+ | undefined;
18
+
19
+ return entry?.status ?? 'closed';
20
+ }
@@ -0,0 +1,18 @@
1
+ import * as React from 'react';
2
+ import type Animated from 'react-native-reanimated';
3
+
4
+ import DrawerProgressContext from './DrawerProgressContext';
5
+
6
+ export default function useDrawerProgress():
7
+ | Readonly<Animated.SharedValue<number>>
8
+ | Animated.Node<number> {
9
+ const progress = React.useContext(DrawerProgressContext);
10
+
11
+ if (progress === undefined) {
12
+ throw new Error(
13
+ "Couldn't find a drawer. Is your component inside a drawer navigator?"
14
+ );
15
+ }
16
+
17
+ return progress;
18
+ }
@@ -0,0 +1,19 @@
1
+ import * as React from 'react';
2
+
3
+ import DrawerStatusContext from './DrawerStatusContext';
4
+
5
+ /**
6
+ * Hook to detect if the drawer's status in a parent navigator.
7
+ * Returns 'open' if the drawer is open, 'closed' if the drawer is closed.
8
+ */
9
+ export default function useDrawerStatus() {
10
+ const drawerStatus = React.useContext(DrawerStatusContext);
11
+
12
+ if (drawerStatus === undefined) {
13
+ throw new Error(
14
+ "Couldn't find a drawer. Is your component inside a drawer navigator?"
15
+ );
16
+ }
17
+
18
+ return drawerStatus;
19
+ }
@@ -0,0 +1,27 @@
1
+ import * as React from 'react';
2
+
3
+ import type { DrawerContentComponentProps } from '../types';
4
+ import DrawerContentScrollView from './DrawerContentScrollView';
5
+ import DrawerItemList from './DrawerItemList';
6
+
7
+ export default function DrawerContent({
8
+ descriptors,
9
+ state,
10
+ ...rest
11
+ }: DrawerContentComponentProps) {
12
+ const focusedRoute = state.routes[state.index];
13
+ const focusedDescriptor = descriptors[focusedRoute.key];
14
+ const focusedOptions = focusedDescriptor.options;
15
+
16
+ const { drawerContentStyle, drawerContentContainerStyle } = focusedOptions;
17
+
18
+ return (
19
+ <DrawerContentScrollView
20
+ {...rest}
21
+ contentContainerStyle={drawerContentContainerStyle}
22
+ style={drawerContentStyle}
23
+ >
24
+ <DrawerItemList descriptors={descriptors} state={state} {...rest} />
25
+ </DrawerContentScrollView>
26
+ );
27
+ }