@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.
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/lib/commonjs/index.js +104 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/navigators/createDrawerNavigator.js +95 -0
- package/lib/commonjs/navigators/createDrawerNavigator.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils/DrawerGestureContext.js +17 -0
- package/lib/commonjs/utils/DrawerGestureContext.js.map +1 -0
- package/lib/commonjs/utils/DrawerPositionContext.js +17 -0
- package/lib/commonjs/utils/DrawerPositionContext.js.map +1 -0
- package/lib/commonjs/utils/DrawerProgressContext.js +17 -0
- package/lib/commonjs/utils/DrawerProgressContext.js.map +1 -0
- package/lib/commonjs/utils/DrawerStatusContext.js +17 -0
- package/lib/commonjs/utils/DrawerStatusContext.js.map +1 -0
- package/lib/commonjs/utils/getDrawerStatusFromState.js +18 -0
- package/lib/commonjs/utils/getDrawerStatusFromState.js.map +1 -0
- package/lib/commonjs/utils/useDrawerProgress.js +27 -0
- package/lib/commonjs/utils/useDrawerProgress.js.map +1 -0
- package/lib/commonjs/utils/useDrawerStatus.js +31 -0
- package/lib/commonjs/utils/useDrawerStatus.js.map +1 -0
- package/lib/commonjs/views/DrawerContent.js +42 -0
- package/lib/commonjs/views/DrawerContent.js.map +1 -0
- package/lib/commonjs/views/DrawerContentScrollView.js +53 -0
- package/lib/commonjs/views/DrawerContentScrollView.js.map +1 -0
- package/lib/commonjs/views/DrawerItem.js +152 -0
- package/lib/commonjs/views/DrawerItem.js.map +1 -0
- package/lib/commonjs/views/DrawerItemList.js +70 -0
- package/lib/commonjs/views/DrawerItemList.js.map +1 -0
- package/lib/commonjs/views/DrawerToggleButton.js +64 -0
- package/lib/commonjs/views/DrawerToggleButton.js.map +1 -0
- package/lib/commonjs/views/DrawerView.js +282 -0
- package/lib/commonjs/views/DrawerView.js.map +1 -0
- package/lib/commonjs/views/GestureHandler.android.js +19 -0
- package/lib/commonjs/views/GestureHandler.android.js.map +1 -0
- package/lib/commonjs/views/GestureHandler.ios.js +19 -0
- package/lib/commonjs/views/GestureHandler.ios.js.map +1 -0
- package/lib/commonjs/views/GestureHandler.js +35 -0
- package/lib/commonjs/views/GestureHandler.js.map +1 -0
- package/lib/commonjs/views/GestureHandlerNative.js +50 -0
- package/lib/commonjs/views/GestureHandlerNative.js.map +1 -0
- package/lib/commonjs/views/ScreenFallback.js +62 -0
- package/lib/commonjs/views/ScreenFallback.js.map +1 -0
- package/lib/commonjs/views/assets/toggle-drawer-icon.png +0 -0
- package/lib/commonjs/views/assets/toggle-drawer-icon@1.5x.android.png +0 -0
- package/lib/commonjs/views/assets/toggle-drawer-icon@1.5x.ios.png +0 -0
- package/lib/commonjs/views/assets/toggle-drawer-icon@1x.android.png +0 -0
- package/lib/commonjs/views/assets/toggle-drawer-icon@1x.ios.png +0 -0
- package/lib/commonjs/views/assets/toggle-drawer-icon@2x.android.png +0 -0
- package/lib/commonjs/views/assets/toggle-drawer-icon@2x.ios.png +0 -0
- package/lib/commonjs/views/assets/toggle-drawer-icon@3x.android.png +0 -0
- package/lib/commonjs/views/assets/toggle-drawer-icon@3x.ios.png +0 -0
- package/lib/commonjs/views/assets/toggle-drawer-icon@4x.android.png +0 -0
- package/lib/commonjs/views/assets/toggle-drawer-icon@4x.ios.png +0 -0
- package/lib/commonjs/views/legacy/Drawer.js +455 -0
- package/lib/commonjs/views/legacy/Drawer.js.map +1 -0
- package/lib/commonjs/views/legacy/Overlay.js +79 -0
- package/lib/commonjs/views/legacy/Overlay.js.map +1 -0
- package/lib/commonjs/views/modern/Drawer.js +293 -0
- package/lib/commonjs/views/modern/Drawer.js.map +1 -0
- package/lib/commonjs/views/modern/Overlay.js +65 -0
- package/lib/commonjs/views/modern/Overlay.js.map +1 -0
- package/lib/module/index.js +27 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/navigators/createDrawerNavigator.js +77 -0
- package/lib/module/navigators/createDrawerNavigator.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/DrawerGestureContext.js +3 -0
- package/lib/module/utils/DrawerGestureContext.js.map +1 -0
- package/lib/module/utils/DrawerPositionContext.js +3 -0
- package/lib/module/utils/DrawerPositionContext.js.map +1 -0
- package/lib/module/utils/DrawerProgressContext.js +3 -0
- package/lib/module/utils/DrawerProgressContext.js.map +1 -0
- package/lib/module/utils/DrawerStatusContext.js +4 -0
- package/lib/module/utils/DrawerStatusContext.js.map +1 -0
- package/lib/module/utils/getDrawerStatusFromState.js +11 -0
- package/lib/module/utils/getDrawerStatusFromState.js.map +1 -0
- package/lib/module/utils/useDrawerProgress.js +12 -0
- package/lib/module/utils/useDrawerProgress.js.map +1 -0
- package/lib/module/utils/useDrawerStatus.js +17 -0
- package/lib/module/utils/useDrawerStatus.js.map +1 -0
- package/lib/module/views/DrawerContent.js +26 -0
- package/lib/module/views/DrawerContent.js.map +1 -0
- package/lib/module/views/DrawerContentScrollView.js +34 -0
- package/lib/module/views/DrawerContentScrollView.js.map +1 -0
- package/lib/module/views/DrawerItem.js +132 -0
- package/lib/module/views/DrawerItem.js.map +1 -0
- package/lib/module/views/DrawerItemList.js +55 -0
- package/lib/module/views/DrawerItemList.js.map +1 -0
- package/lib/module/views/DrawerToggleButton.js +48 -0
- package/lib/module/views/DrawerToggleButton.js.map +1 -0
- package/lib/module/views/DrawerView.js +256 -0
- package/lib/module/views/DrawerView.js.map +1 -0
- package/lib/module/views/GestureHandler.android.js +2 -0
- package/lib/module/views/GestureHandler.android.js.map +1 -0
- package/lib/module/views/GestureHandler.ios.js +2 -0
- package/lib/module/views/GestureHandler.ios.js.map +1 -0
- package/lib/module/views/GestureHandler.js +19 -0
- package/lib/module/views/GestureHandler.js.map +1 -0
- package/lib/module/views/GestureHandlerNative.js +11 -0
- package/lib/module/views/GestureHandlerNative.js.map +1 -0
- package/lib/module/views/ScreenFallback.js +44 -0
- package/lib/module/views/ScreenFallback.js.map +1 -0
- package/lib/module/views/assets/toggle-drawer-icon.png +0 -0
- package/lib/module/views/assets/toggle-drawer-icon@1.5x.android.png +0 -0
- package/lib/module/views/assets/toggle-drawer-icon@1.5x.ios.png +0 -0
- package/lib/module/views/assets/toggle-drawer-icon@1x.android.png +0 -0
- package/lib/module/views/assets/toggle-drawer-icon@1x.ios.png +0 -0
- package/lib/module/views/assets/toggle-drawer-icon@2x.android.png +0 -0
- package/lib/module/views/assets/toggle-drawer-icon@2x.ios.png +0 -0
- package/lib/module/views/assets/toggle-drawer-icon@3x.android.png +0 -0
- package/lib/module/views/assets/toggle-drawer-icon@3x.ios.png +0 -0
- package/lib/module/views/assets/toggle-drawer-icon@4x.android.png +0 -0
- package/lib/module/views/assets/toggle-drawer-icon@4x.ios.png +0 -0
- package/lib/module/views/legacy/Drawer.js +430 -0
- package/lib/module/views/legacy/Drawer.js.map +1 -0
- package/lib/module/views/legacy/Overlay.js +59 -0
- package/lib/module/views/legacy/Overlay.js.map +1 -0
- package/lib/module/views/modern/Drawer.js +272 -0
- package/lib/module/views/modern/Drawer.js.map +1 -0
- package/lib/module/views/modern/Overlay.js +47 -0
- package/lib/module/views/modern/Overlay.js.map +1 -0
- package/lib/typescript/src/index.d.ts +25 -0
- package/lib/typescript/src/navigators/createDrawerNavigator.d.ts +7 -0
- package/lib/typescript/src/types.d.ts +235 -0
- package/lib/typescript/src/utils/DrawerGestureContext.d.ts +3 -0
- package/lib/typescript/src/utils/DrawerPositionContext.d.ts +3 -0
- package/lib/typescript/src/utils/DrawerProgressContext.d.ts +4 -0
- package/lib/typescript/src/utils/DrawerStatusContext.d.ts +3 -0
- package/lib/typescript/src/utils/getDrawerStatusFromState.d.ts +2 -0
- package/lib/typescript/src/utils/useDrawerProgress.d.ts +2 -0
- package/lib/typescript/src/utils/useDrawerStatus.d.ts +5 -0
- package/lib/typescript/src/views/DrawerContent.d.ts +3 -0
- package/lib/typescript/src/views/DrawerContentScrollView.d.ts +6 -0
- package/lib/typescript/src/views/DrawerItem.d.ts +74 -0
- package/lib/typescript/src/views/DrawerItemList.d.ts +13 -0
- package/lib/typescript/src/views/DrawerToggleButton.d.ts +9 -0
- package/lib/typescript/src/views/DrawerView.d.ts +10 -0
- package/lib/typescript/src/views/GestureHandler.android.d.ts +1 -0
- package/lib/typescript/src/views/GestureHandler.d.ts +14 -0
- package/lib/typescript/src/views/GestureHandler.ios.d.ts +1 -0
- package/lib/typescript/src/views/GestureHandlerNative.d.ts +4 -0
- package/lib/typescript/src/views/ScreenFallback.d.ts +14 -0
- package/lib/typescript/src/views/legacy/Drawer.d.ts +44 -0
- package/lib/typescript/src/views/legacy/Overlay.d.ts +68 -0
- package/lib/typescript/src/views/modern/Drawer.d.ts +3 -0
- package/lib/typescript/src/views/modern/Overlay.d.ts +68 -0
- package/package.json +87 -0
- package/src/index.tsx +34 -0
- package/src/navigators/createDrawerNavigator.tsx +134 -0
- package/src/types.tsx +300 -0
- package/src/utils/DrawerGestureContext.tsx +3 -0
- package/src/utils/DrawerPositionContext.tsx +3 -0
- package/src/utils/DrawerProgressContext.tsx +6 -0
- package/src/utils/DrawerStatusContext.tsx +6 -0
- package/src/utils/getDrawerStatusFromState.tsx +20 -0
- package/src/utils/useDrawerProgress.tsx +18 -0
- package/src/utils/useDrawerStatus.tsx +19 -0
- package/src/views/DrawerContent.tsx +27 -0
- package/src/views/DrawerContentScrollView.tsx +52 -0
- package/src/views/DrawerItem.tsx +227 -0
- package/src/views/DrawerItemList.tsx +80 -0
- package/src/views/DrawerToggleButton.tsx +54 -0
- package/src/views/DrawerView.tsx +313 -0
- package/src/views/GestureHandler.android.tsx +1 -0
- package/src/views/GestureHandler.ios.tsx +1 -0
- package/src/views/GestureHandler.tsx +29 -0
- package/src/views/GestureHandlerNative.tsx +24 -0
- package/src/views/ScreenFallback.tsx +48 -0
- package/src/views/assets/toggle-drawer-icon.png +0 -0
- package/src/views/assets/toggle-drawer-icon@1.5x.android.png +0 -0
- package/src/views/assets/toggle-drawer-icon@1.5x.ios.png +0 -0
- package/src/views/assets/toggle-drawer-icon@1x.android.png +0 -0
- package/src/views/assets/toggle-drawer-icon@1x.ios.png +0 -0
- package/src/views/assets/toggle-drawer-icon@2x.android.png +0 -0
- package/src/views/assets/toggle-drawer-icon@2x.ios.png +0 -0
- package/src/views/assets/toggle-drawer-icon@3x.android.png +0 -0
- package/src/views/assets/toggle-drawer-icon@3x.ios.png +0 -0
- package/src/views/assets/toggle-drawer-icon@4x.android.png +0 -0
- package/src/views/assets/toggle-drawer-icon@4x.ios.png +0 -0
- package/src/views/legacy/Drawer.tsx +659 -0
- package/src/views/legacy/Overlay.tsx +74 -0
- package/src/views/modern/Drawer.tsx +385 -0
- package/src/views/modern/Overlay.tsx +56 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
I18nManager,
|
|
4
|
+
ScrollView,
|
|
5
|
+
ScrollViewProps,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
9
|
+
|
|
10
|
+
import DrawerPositionContext from '../utils/DrawerPositionContext';
|
|
11
|
+
|
|
12
|
+
type Props = ScrollViewProps & {
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function DrawerContentScrollView(
|
|
17
|
+
{ contentContainerStyle, style, children, ...rest }: Props,
|
|
18
|
+
ref?: React.Ref<ScrollView>
|
|
19
|
+
) {
|
|
20
|
+
const drawerPosition = React.useContext(DrawerPositionContext);
|
|
21
|
+
const insets = useSafeAreaInsets();
|
|
22
|
+
|
|
23
|
+
const isRight = I18nManager.isRTL
|
|
24
|
+
? drawerPosition === 'left'
|
|
25
|
+
: drawerPosition === 'right';
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<ScrollView
|
|
29
|
+
{...rest}
|
|
30
|
+
ref={ref}
|
|
31
|
+
contentContainerStyle={[
|
|
32
|
+
{
|
|
33
|
+
paddingTop: insets.top + 4,
|
|
34
|
+
paddingStart: !isRight ? insets.left : 0,
|
|
35
|
+
paddingEnd: isRight ? insets.right : 0,
|
|
36
|
+
},
|
|
37
|
+
contentContainerStyle,
|
|
38
|
+
]}
|
|
39
|
+
style={[styles.container, style]}
|
|
40
|
+
>
|
|
41
|
+
{children}
|
|
42
|
+
</ScrollView>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default React.forwardRef(DrawerContentScrollView);
|
|
47
|
+
|
|
48
|
+
const styles = StyleSheet.create({
|
|
49
|
+
container: {
|
|
50
|
+
flex: 1,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { PlatformPressable } from '@react-navigation/elements';
|
|
2
|
+
import { Link, useTheme } from '@react-navigation/native';
|
|
3
|
+
import Color from 'color';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import {
|
|
6
|
+
Platform,
|
|
7
|
+
StyleProp,
|
|
8
|
+
StyleSheet,
|
|
9
|
+
Text,
|
|
10
|
+
TextStyle,
|
|
11
|
+
View,
|
|
12
|
+
ViewStyle,
|
|
13
|
+
} from 'react-native';
|
|
14
|
+
|
|
15
|
+
type Props = {
|
|
16
|
+
/**
|
|
17
|
+
* The label text of the item.
|
|
18
|
+
*/
|
|
19
|
+
label:
|
|
20
|
+
| string
|
|
21
|
+
| ((props: { focused: boolean; color: string }) => React.ReactNode);
|
|
22
|
+
/**
|
|
23
|
+
* Icon to display for the `DrawerItem`.
|
|
24
|
+
*/
|
|
25
|
+
icon?: (props: {
|
|
26
|
+
focused: boolean;
|
|
27
|
+
size: number;
|
|
28
|
+
color: string;
|
|
29
|
+
}) => React.ReactNode;
|
|
30
|
+
/**
|
|
31
|
+
* URL to use for the link to the tab.
|
|
32
|
+
*/
|
|
33
|
+
to?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Whether to highlight the drawer item as active.
|
|
36
|
+
*/
|
|
37
|
+
focused?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Function to execute on press.
|
|
40
|
+
*/
|
|
41
|
+
onPress: () => void;
|
|
42
|
+
/**
|
|
43
|
+
* Color for the icon and label when the item is active.
|
|
44
|
+
*/
|
|
45
|
+
activeTintColor?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Color for the icon and label when the item is inactive.
|
|
48
|
+
*/
|
|
49
|
+
inactiveTintColor?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Background color for item when its active.
|
|
52
|
+
*/
|
|
53
|
+
activeBackgroundColor?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Background color for item when its inactive.
|
|
56
|
+
*/
|
|
57
|
+
inactiveBackgroundColor?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Color of the touchable effect on press.
|
|
60
|
+
* Only supported on Android.
|
|
61
|
+
*
|
|
62
|
+
* @platform android
|
|
63
|
+
*/
|
|
64
|
+
pressColor?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Opacity of the touchable effect on press.
|
|
67
|
+
* Only supported on iOS.
|
|
68
|
+
*
|
|
69
|
+
* @platform ios
|
|
70
|
+
*/
|
|
71
|
+
pressOpacity?: number;
|
|
72
|
+
/**
|
|
73
|
+
* Style object for the label element.
|
|
74
|
+
*/
|
|
75
|
+
labelStyle?: StyleProp<TextStyle>;
|
|
76
|
+
/**
|
|
77
|
+
* Style object for the wrapper element.
|
|
78
|
+
*/
|
|
79
|
+
style?: StyleProp<ViewStyle>;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const LinkPressable = ({
|
|
83
|
+
children,
|
|
84
|
+
style,
|
|
85
|
+
onPress,
|
|
86
|
+
onLongPress,
|
|
87
|
+
to,
|
|
88
|
+
accessibilityRole,
|
|
89
|
+
...rest
|
|
90
|
+
}: Omit<React.ComponentProps<typeof PlatformPressable>, 'style'> & {
|
|
91
|
+
style: StyleProp<ViewStyle>;
|
|
92
|
+
} & {
|
|
93
|
+
to?: string;
|
|
94
|
+
children: React.ReactNode;
|
|
95
|
+
onPress?: () => void;
|
|
96
|
+
}) => {
|
|
97
|
+
if (Platform.OS === 'web' && to) {
|
|
98
|
+
// React Native Web doesn't forward `onClick` if we use `TouchableWithoutFeedback`.
|
|
99
|
+
// We need to use `onClick` to be able to prevent default browser handling of links.
|
|
100
|
+
return (
|
|
101
|
+
<Link
|
|
102
|
+
{...rest}
|
|
103
|
+
to={to}
|
|
104
|
+
style={[styles.button, style]}
|
|
105
|
+
onPress={(e: any) => {
|
|
106
|
+
if (
|
|
107
|
+
!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) && // ignore clicks with modifier keys
|
|
108
|
+
(e.button == null || e.button === 0) // ignore everything but left clicks
|
|
109
|
+
) {
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
onPress?.(e);
|
|
112
|
+
}
|
|
113
|
+
}}
|
|
114
|
+
onLongPress={onLongPress ?? undefined}
|
|
115
|
+
>
|
|
116
|
+
{children}
|
|
117
|
+
</Link>
|
|
118
|
+
);
|
|
119
|
+
} else {
|
|
120
|
+
return (
|
|
121
|
+
<PlatformPressable
|
|
122
|
+
{...rest}
|
|
123
|
+
accessibilityRole={accessibilityRole}
|
|
124
|
+
onPress={onPress}
|
|
125
|
+
>
|
|
126
|
+
<View style={style}>{children}</View>
|
|
127
|
+
</PlatformPressable>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* A component used to show an action item with an icon and a label in a navigation drawer.
|
|
134
|
+
*/
|
|
135
|
+
export default function DrawerItem(props: Props) {
|
|
136
|
+
const { colors } = useTheme();
|
|
137
|
+
|
|
138
|
+
const {
|
|
139
|
+
icon,
|
|
140
|
+
label,
|
|
141
|
+
labelStyle,
|
|
142
|
+
to,
|
|
143
|
+
focused = false,
|
|
144
|
+
activeTintColor = colors.primary,
|
|
145
|
+
inactiveTintColor = Color(colors.text).alpha(0.68).rgb().string(),
|
|
146
|
+
activeBackgroundColor = Color(activeTintColor).alpha(0.12).rgb().string(),
|
|
147
|
+
inactiveBackgroundColor = 'transparent',
|
|
148
|
+
style,
|
|
149
|
+
onPress,
|
|
150
|
+
pressColor,
|
|
151
|
+
pressOpacity,
|
|
152
|
+
...rest
|
|
153
|
+
} = props;
|
|
154
|
+
|
|
155
|
+
const { borderRadius = 4 } = StyleSheet.flatten(style || {});
|
|
156
|
+
const color = focused ? activeTintColor : inactiveTintColor;
|
|
157
|
+
const backgroundColor = focused
|
|
158
|
+
? activeBackgroundColor
|
|
159
|
+
: inactiveBackgroundColor;
|
|
160
|
+
|
|
161
|
+
const iconNode = icon ? icon({ size: 24, focused, color }) : null;
|
|
162
|
+
|
|
163
|
+
return (
|
|
164
|
+
<View
|
|
165
|
+
collapsable={false}
|
|
166
|
+
{...rest}
|
|
167
|
+
style={[styles.container, { borderRadius, backgroundColor }, style]}
|
|
168
|
+
>
|
|
169
|
+
<LinkPressable
|
|
170
|
+
onPress={onPress}
|
|
171
|
+
style={[styles.wrapper, { borderRadius }]}
|
|
172
|
+
accessibilityRole="button"
|
|
173
|
+
accessibilityState={{ selected: focused }}
|
|
174
|
+
pressColor={pressColor}
|
|
175
|
+
pressOpacity={pressOpacity}
|
|
176
|
+
to={to}
|
|
177
|
+
>
|
|
178
|
+
<React.Fragment>
|
|
179
|
+
{iconNode}
|
|
180
|
+
<View
|
|
181
|
+
style={[
|
|
182
|
+
styles.label,
|
|
183
|
+
{ marginLeft: iconNode ? 32 : 0, marginVertical: 5 },
|
|
184
|
+
]}
|
|
185
|
+
>
|
|
186
|
+
{typeof label === 'string' ? (
|
|
187
|
+
<Text
|
|
188
|
+
numberOfLines={1}
|
|
189
|
+
style={[
|
|
190
|
+
{
|
|
191
|
+
color,
|
|
192
|
+
fontWeight: '500',
|
|
193
|
+
},
|
|
194
|
+
labelStyle,
|
|
195
|
+
]}
|
|
196
|
+
>
|
|
197
|
+
{label}
|
|
198
|
+
</Text>
|
|
199
|
+
) : (
|
|
200
|
+
label({ color, focused })
|
|
201
|
+
)}
|
|
202
|
+
</View>
|
|
203
|
+
</React.Fragment>
|
|
204
|
+
</LinkPressable>
|
|
205
|
+
</View>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const styles = StyleSheet.create({
|
|
210
|
+
container: {
|
|
211
|
+
marginHorizontal: 10,
|
|
212
|
+
marginVertical: 4,
|
|
213
|
+
overflow: 'hidden',
|
|
214
|
+
},
|
|
215
|
+
wrapper: {
|
|
216
|
+
flexDirection: 'row',
|
|
217
|
+
alignItems: 'center',
|
|
218
|
+
padding: 8,
|
|
219
|
+
},
|
|
220
|
+
label: {
|
|
221
|
+
marginRight: 32,
|
|
222
|
+
flex: 1,
|
|
223
|
+
},
|
|
224
|
+
button: {
|
|
225
|
+
display: 'flex',
|
|
226
|
+
},
|
|
227
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CommonActions,
|
|
3
|
+
DrawerActions,
|
|
4
|
+
DrawerNavigationState,
|
|
5
|
+
ParamListBase,
|
|
6
|
+
useLinkBuilder,
|
|
7
|
+
} from '@react-navigation/native';
|
|
8
|
+
import * as React from 'react';
|
|
9
|
+
|
|
10
|
+
import type { DrawerDescriptorMap, DrawerNavigationHelpers } from '../types';
|
|
11
|
+
import DrawerItem from './DrawerItem';
|
|
12
|
+
|
|
13
|
+
type Props = {
|
|
14
|
+
state: DrawerNavigationState<ParamListBase>;
|
|
15
|
+
navigation: DrawerNavigationHelpers;
|
|
16
|
+
descriptors: DrawerDescriptorMap;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Component that renders the navigation list in the drawer.
|
|
21
|
+
*/
|
|
22
|
+
export default function DrawerItemList({
|
|
23
|
+
state,
|
|
24
|
+
navigation,
|
|
25
|
+
descriptors,
|
|
26
|
+
}: Props) {
|
|
27
|
+
const buildLink = useLinkBuilder();
|
|
28
|
+
|
|
29
|
+
const focusedRoute = state.routes[state.index];
|
|
30
|
+
const focusedDescriptor = descriptors[focusedRoute.key];
|
|
31
|
+
const focusedOptions = focusedDescriptor.options;
|
|
32
|
+
|
|
33
|
+
const {
|
|
34
|
+
drawerActiveTintColor,
|
|
35
|
+
drawerInactiveTintColor,
|
|
36
|
+
drawerActiveBackgroundColor,
|
|
37
|
+
drawerInactiveBackgroundColor,
|
|
38
|
+
} = focusedOptions;
|
|
39
|
+
|
|
40
|
+
return state.routes.map((route, i) => {
|
|
41
|
+
const focused = i === state.index;
|
|
42
|
+
const {
|
|
43
|
+
title,
|
|
44
|
+
drawerLabel,
|
|
45
|
+
drawerIcon,
|
|
46
|
+
drawerLabelStyle,
|
|
47
|
+
drawerItemStyle,
|
|
48
|
+
} = descriptors[route.key].options;
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<DrawerItem
|
|
52
|
+
key={route.key}
|
|
53
|
+
label={
|
|
54
|
+
drawerLabel !== undefined
|
|
55
|
+
? drawerLabel
|
|
56
|
+
: title !== undefined
|
|
57
|
+
? title
|
|
58
|
+
: route.name
|
|
59
|
+
}
|
|
60
|
+
icon={drawerIcon}
|
|
61
|
+
focused={focused}
|
|
62
|
+
activeTintColor={drawerActiveTintColor}
|
|
63
|
+
inactiveTintColor={drawerInactiveTintColor}
|
|
64
|
+
activeBackgroundColor={drawerActiveBackgroundColor}
|
|
65
|
+
inactiveBackgroundColor={drawerInactiveBackgroundColor}
|
|
66
|
+
labelStyle={drawerLabelStyle}
|
|
67
|
+
style={drawerItemStyle}
|
|
68
|
+
to={buildLink(route.name, route.params)}
|
|
69
|
+
onPress={() => {
|
|
70
|
+
navigation.dispatch({
|
|
71
|
+
...(focused
|
|
72
|
+
? DrawerActions.closeDrawer()
|
|
73
|
+
: CommonActions.navigate({ name: route.name, merge: true })),
|
|
74
|
+
target: state.key,
|
|
75
|
+
});
|
|
76
|
+
}}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
}) as React.ReactNode as React.ReactElement;
|
|
80
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { PlatformPressable } from '@react-navigation/elements';
|
|
2
|
+
import {
|
|
3
|
+
DrawerActions,
|
|
4
|
+
ParamListBase,
|
|
5
|
+
useNavigation,
|
|
6
|
+
} from '@react-navigation/native';
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
import { Image, Platform, StyleSheet } from 'react-native';
|
|
9
|
+
|
|
10
|
+
import type { DrawerNavigationProp } from '../types';
|
|
11
|
+
|
|
12
|
+
type Props = {
|
|
13
|
+
accessibilityLabel?: string;
|
|
14
|
+
pressColor?: string;
|
|
15
|
+
pressOpacity?: number;
|
|
16
|
+
tintColor?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default function DrawerToggleButton({ tintColor, ...rest }: Props) {
|
|
20
|
+
const navigation = useNavigation<DrawerNavigationProp<ParamListBase>>();
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<PlatformPressable
|
|
24
|
+
{...rest}
|
|
25
|
+
accessible
|
|
26
|
+
accessibilityRole="button"
|
|
27
|
+
android_ripple={{ borderless: true }}
|
|
28
|
+
onPress={() => navigation.dispatch(DrawerActions.toggleDrawer())}
|
|
29
|
+
style={styles.touchable}
|
|
30
|
+
hitSlop={Platform.select({
|
|
31
|
+
ios: undefined,
|
|
32
|
+
default: { top: 16, right: 16, bottom: 16, left: 16 },
|
|
33
|
+
})}
|
|
34
|
+
>
|
|
35
|
+
<Image
|
|
36
|
+
style={[styles.icon, tintColor ? { tintColor } : null]}
|
|
37
|
+
source={require('./assets/toggle-drawer-icon.png')}
|
|
38
|
+
fadeDuration={0}
|
|
39
|
+
/>
|
|
40
|
+
</PlatformPressable>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const styles = StyleSheet.create({
|
|
45
|
+
icon: {
|
|
46
|
+
height: 24,
|
|
47
|
+
width: 24,
|
|
48
|
+
margin: 3,
|
|
49
|
+
resizeMode: 'contain',
|
|
50
|
+
},
|
|
51
|
+
touchable: {
|
|
52
|
+
marginHorizontal: 11,
|
|
53
|
+
},
|
|
54
|
+
});
|