@react-navigation/drawer 8.0.0-alpha.4 → 8.0.0-alpha.40

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 (62) hide show
  1. package/lib/module/index.js.map +1 -1
  2. package/lib/module/navigators/createDrawerNavigator.js +3 -7
  3. package/lib/module/navigators/createDrawerNavigator.js.map +1 -1
  4. package/lib/module/utils/useDrawerStatus.js +1 -1
  5. package/lib/module/utils/useDrawerStatus.js.map +1 -1
  6. package/lib/module/views/DrawerContent.js +4 -2
  7. package/lib/module/views/DrawerContent.js.map +1 -1
  8. package/lib/module/views/DrawerContentScrollView.js +30 -13
  9. package/lib/module/views/DrawerContentScrollView.js.map +1 -1
  10. package/lib/module/views/DrawerItem.js +52 -9
  11. package/lib/module/views/DrawerItem.js.map +1 -1
  12. package/lib/module/views/DrawerItemList.js +13 -5
  13. package/lib/module/views/DrawerItemList.js.map +1 -1
  14. package/lib/module/views/DrawerToggleButton.js +37 -7
  15. package/lib/module/views/DrawerToggleButton.js.map +1 -1
  16. package/lib/module/views/DrawerView.js +24 -17
  17. package/lib/module/views/DrawerView.js.map +1 -1
  18. package/lib/typescript/src/index.d.ts +11 -11
  19. package/lib/typescript/src/index.d.ts.map +1 -1
  20. package/lib/typescript/src/navigators/createDrawerNavigator.d.ts +9 -15
  21. package/lib/typescript/src/navigators/createDrawerNavigator.d.ts.map +1 -1
  22. package/lib/typescript/src/types.d.ts +24 -25
  23. package/lib/typescript/src/types.d.ts.map +1 -1
  24. package/lib/typescript/src/views/DrawerContent.d.ts +2 -2
  25. package/lib/typescript/src/views/DrawerContent.d.ts.map +1 -1
  26. package/lib/typescript/src/views/DrawerContentScrollView.d.ts +5 -2
  27. package/lib/typescript/src/views/DrawerContentScrollView.d.ts.map +1 -1
  28. package/lib/typescript/src/views/DrawerItem.d.ts +19 -18
  29. package/lib/typescript/src/views/DrawerItem.d.ts.map +1 -1
  30. package/lib/typescript/src/views/DrawerItemList.d.ts +1 -1
  31. package/lib/typescript/src/views/DrawerItemList.d.ts.map +1 -1
  32. package/lib/typescript/src/views/DrawerToggleButton.d.ts +12 -7
  33. package/lib/typescript/src/views/DrawerToggleButton.d.ts.map +1 -1
  34. package/lib/typescript/src/views/DrawerView.d.ts +3 -2
  35. package/lib/typescript/src/views/DrawerView.d.ts.map +1 -1
  36. package/package.json +26 -26
  37. package/src/index.tsx +1 -0
  38. package/src/navigators/createDrawerNavigator.tsx +9 -40
  39. package/src/types.tsx +30 -25
  40. package/src/utils/useDrawerStatus.tsx +1 -1
  41. package/src/views/DrawerContent.tsx +6 -2
  42. package/src/views/DrawerContentScrollView.tsx +31 -15
  43. package/src/views/DrawerItem.tsx +88 -24
  44. package/src/views/DrawerItemList.tsx +16 -4
  45. package/src/views/DrawerToggleButton.tsx +66 -22
  46. package/src/views/DrawerView.tsx +37 -20
  47. package/lib/module/views/assets/toggle-drawer-icon@1x.android.png +0 -0
  48. package/lib/module/views/assets/toggle-drawer-icon@1x.ios.png +0 -0
  49. package/lib/module/views/assets/toggle-drawer-icon@2x.android.png +0 -0
  50. package/lib/module/views/assets/toggle-drawer-icon@2x.ios.png +0 -0
  51. package/lib/module/views/assets/toggle-drawer-icon@3x.android.png +0 -0
  52. package/lib/module/views/assets/toggle-drawer-icon@3x.ios.png +0 -0
  53. package/lib/module/views/assets/toggle-drawer-icon@4x.android.png +0 -0
  54. package/lib/module/views/assets/toggle-drawer-icon@4x.ios.png +0 -0
  55. package/src/views/assets/toggle-drawer-icon@1x.android.png +0 -0
  56. package/src/views/assets/toggle-drawer-icon@1x.ios.png +0 -0
  57. package/src/views/assets/toggle-drawer-icon@2x.android.png +0 -0
  58. package/src/views/assets/toggle-drawer-icon@2x.ios.png +0 -0
  59. package/src/views/assets/toggle-drawer-icon@3x.android.png +0 -0
  60. package/src/views/assets/toggle-drawer-icon@3x.ios.png +0 -0
  61. package/src/views/assets/toggle-drawer-icon@4x.android.png +0 -0
  62. package/src/views/assets/toggle-drawer-icon@4x.ios.png +0 -0
package/src/types.tsx CHANGED
@@ -1,4 +1,5 @@
1
- import type { HeaderOptions } from '@react-navigation/elements';
1
+ import type { HeaderOptions, Icon } from '@react-navigation/elements';
2
+ import type { Screen } from '@react-navigation/elements/internal';
2
3
  import type {
3
4
  DefaultNavigatorOptions,
4
5
  Descriptor,
@@ -13,7 +14,7 @@ import type {
13
14
  Theme,
14
15
  } from '@react-navigation/native';
15
16
  import type { ColorValue, StyleProp, TextStyle, ViewStyle } from 'react-native';
16
- import type { PanGesture } from 'react-native-gesture-handler';
17
+ import type { PanGestureConfig } from 'react-native-gesture-handler';
17
18
 
18
19
  export type Scene = {
19
20
  route: Route<string>;
@@ -29,12 +30,6 @@ export type DrawerNavigationConfig = {
29
30
  * Defaults to `DrawerContent`.
30
31
  */
31
32
  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
33
  };
39
34
 
40
35
  export type DrawerNavigationOptions = HeaderOptions & {
@@ -70,13 +65,15 @@ export type DrawerNavigationOptions = HeaderOptions & {
70
65
  | ((props: { color: ColorValue; focused: boolean }) => React.ReactNode);
71
66
 
72
67
  /**
73
- * A function that given { focused: boolean, color: ColorValue } returns a React.Node to display an icon the drawer.
68
+ * Icon to display for the drawer item.
74
69
  */
75
- drawerIcon?: (props: {
76
- color: ColorValue;
77
- size: number;
78
- focused: boolean;
79
- }) => React.ReactNode;
70
+ drawerIcon?:
71
+ | Icon
72
+ | ((props: {
73
+ color: ColorValue;
74
+ size: number;
75
+ focused: boolean;
76
+ }) => Icon | React.ReactNode);
80
77
 
81
78
  /**
82
79
  * Color for the icon and label in the active item in the drawer.
@@ -108,6 +105,11 @@ export type DrawerNavigationOptions = HeaderOptions & {
108
105
  */
109
106
  drawerItemStyle?: StyleProp<ViewStyle>;
110
107
 
108
+ /**
109
+ * ID to locate this drawer item in tests.
110
+ */
111
+ drawerItemTestID?: string;
112
+
111
113
  /**
112
114
  * Style object to apply to the `Text` inside content section which renders a label.
113
115
  */
@@ -143,7 +145,7 @@ export type DrawerNavigationOptions = HeaderOptions & {
143
145
  *
144
146
  * Defaults to `slide` on iOS and `front` on other platforms.
145
147
  */
146
- drawerType?: 'front' | 'back' | 'slide' | 'permanent';
148
+ drawerType?: 'front' | 'back' | 'slide' | 'permanent' | undefined;
147
149
 
148
150
  /**
149
151
  * Whether the statusbar should be hidden when the drawer is pulled or opens,
@@ -170,12 +172,12 @@ export type DrawerNavigationOptions = HeaderOptions & {
170
172
  /**
171
173
  * Style object for the component wrapping the screen content.
172
174
  */
173
- sceneStyle?: StyleProp<ViewStyle>;
175
+ sceneStyle?: React.ComponentProps<typeof Screen>['style'];
174
176
 
175
177
  /**
176
- * Function to modify the pan gesture handler via RNGH properties API.
178
+ * Function to modify the pan gesture config.
177
179
  */
178
- configureGestureHandler?: (gesture: PanGesture) => PanGesture;
180
+ configureGestureHandler?: (gesture: PanGestureConfig) => PanGestureConfig;
179
181
 
180
182
  /**
181
183
  * Whether you can use swipe gestures to open or close the drawer.
@@ -208,13 +210,17 @@ export type DrawerNavigationOptions = HeaderOptions & {
208
210
  popToTopOnBlur?: boolean;
209
211
 
210
212
  /**
211
- * Whether inactive screens should be suspended from re-rendering. Defaults to `false`.
212
- * Defaults to `true` when `enableFreeze()` is run at the top of the application.
213
- * Requires `react-native-screens` version >=3.16.0.
213
+ * What should happen when screens become inactive.
214
+ * - `pause`: Effects are cleaned up.
215
+ * - `none`: Screen renders normally
216
+ *
217
+ * Defaults to `pause`.
214
218
  *
215
- * Only supported on iOS and Android.
219
+ * If you set `lazy: false` or preload a screen,
220
+ * It won't be paused until after the first time it becomes focused.
221
+ * This makes sure that effects are run to initialize the screen.
216
222
  */
217
- freezeOnBlur?: boolean;
223
+ inactiveBehavior?: 'pause' | 'none';
218
224
  };
219
225
 
220
226
  export type DrawerContentComponentProps = {
@@ -307,11 +313,10 @@ export type DrawerDescriptor = Descriptor<
307
313
  export type DrawerDescriptorMap = Record<string, DrawerDescriptor>;
308
314
 
309
315
  export type DrawerProps = {
310
- dimensions: { width: number; height: number };
311
316
  drawerPosition: 'left' | 'right';
312
317
  drawerStyle?: StyleProp<ViewStyle>;
313
318
  drawerType: 'front' | 'back' | 'slide' | 'permanent';
314
- configureGestureHandler?: (gesture: PanGesture) => PanGesture;
319
+ configureGestureHandler?: (gesture: PanGestureConfig) => PanGestureConfig;
315
320
  hideStatusBarOnOpen: boolean;
316
321
  keyboardDismissMode: 'none' | 'on-drag';
317
322
  onClose: () => void;
@@ -8,7 +8,7 @@ import { DrawerStatusContext } from './DrawerStatusContext';
8
8
  * Returns 'open' if the drawer is open, 'closed' if the drawer is closed.
9
9
  */
10
10
  export function useDrawerStatus(): DrawerStatus {
11
- const drawerStatus = React.useContext(DrawerStatusContext);
11
+ const drawerStatus = React.use(DrawerStatusContext);
12
12
 
13
13
  if (drawerStatus === undefined) {
14
14
  throw new Error(
@@ -8,8 +8,12 @@ export function DrawerContent({
8
8
  ...rest
9
9
  }: DrawerContentComponentProps) {
10
10
  const focusedRoute = state.routes[state.index];
11
- const focusedDescriptor = descriptors[focusedRoute.key];
12
- const focusedOptions = focusedDescriptor.options;
11
+
12
+ if (focusedRoute == null) {
13
+ throw new Error(`Couldn't find a route at index ${state.index}.`);
14
+ }
15
+
16
+ const focusedOptions = descriptors[focusedRoute.key]?.options ?? {};
13
17
 
14
18
  const { drawerContentStyle, drawerContentContainerStyle } = focusedOptions;
15
19
 
@@ -1,21 +1,31 @@
1
- import { useLocale } from '@react-navigation/native';
1
+ import { UNSTABLE_CornerInset, useLocale } from '@react-navigation/native';
2
2
  import * as React from 'react';
3
- import { ScrollView, type ScrollViewProps, StyleSheet } from 'react-native';
3
+ import {
4
+ Platform,
5
+ ScrollView,
6
+ type ScrollViewProps,
7
+ StyleSheet,
8
+ } from 'react-native';
4
9
  import { useSafeAreaInsets } from 'react-native-safe-area-context';
5
10
 
6
11
  import { DrawerPositionContext } from '../utils/DrawerPositionContext';
7
12
 
8
13
  type Props = ScrollViewProps & {
9
14
  children: React.ReactNode;
15
+ ref?: React.Ref<ScrollView>;
10
16
  };
11
17
 
12
18
  const SPACING = 12;
13
19
 
14
- function DrawerContentScrollViewInner(
15
- { contentContainerStyle, style, children, ...rest }: Props,
16
- ref?: React.Ref<ScrollView>
17
- ) {
18
- const drawerPosition = React.useContext(DrawerPositionContext);
20
+ export function DrawerContentScrollView({
21
+ contentInsetAdjustmentBehavior = 'automatic',
22
+ contentContainerStyle,
23
+ style,
24
+ children,
25
+ ref,
26
+ ...rest
27
+ }: Props) {
28
+ const drawerPosition = React.use(DrawerPositionContext);
19
29
  const insets = useSafeAreaInsets();
20
30
  const { direction } = useLocale();
21
31
 
@@ -28,26 +38,32 @@ function DrawerContentScrollViewInner(
28
38
  <ScrollView
29
39
  {...rest}
30
40
  ref={ref}
41
+ contentInsetAdjustmentBehavior={contentInsetAdjustmentBehavior}
31
42
  contentContainerStyle={[
32
43
  {
33
- paddingTop: SPACING + insets.top,
34
- paddingBottom: SPACING + insets.bottom,
35
- paddingStart: SPACING + (!isRight ? insets.left : 0),
36
- paddingEnd: SPACING + (isRight ? insets.right : 0),
44
+ paddingTop:
45
+ SPACING + Platform.select({ ios: 0, default: insets.top }),
46
+ paddingBottom:
47
+ SPACING + Platform.select({ ios: 0, default: insets.bottom }),
48
+ paddingStart:
49
+ SPACING +
50
+ (!isRight ? Platform.select({ ios: 0, default: insets.left }) : 0),
51
+ paddingEnd:
52
+ SPACING +
53
+ (isRight ? Platform.select({ ios: 0, default: insets.right }) : 0),
37
54
  },
38
55
  contentContainerStyle,
39
56
  ]}
40
57
  style={[styles.container, style]}
41
58
  >
59
+ {Platform.OS === 'ios' && contentInsetAdjustmentBehavior !== 'never' && (
60
+ <UNSTABLE_CornerInset direction="vertical" edge="top" />
61
+ )}
42
62
  {children}
43
63
  </ScrollView>
44
64
  );
45
65
  }
46
66
 
47
- export const DrawerContentScrollView = React.forwardRef(
48
- DrawerContentScrollViewInner
49
- );
50
-
51
67
  const styles = StyleSheet.create({
52
68
  container: {
53
69
  flex: 1,
@@ -1,9 +1,15 @@
1
- import { PlatformPressable, Text } from '@react-navigation/elements';
1
+ import { type Icon, PlatformPressable, Text } from '@react-navigation/elements';
2
2
  import { Color } from '@react-navigation/elements/internal';
3
- import { type Route, useTheme } from '@react-navigation/native';
4
- import * as React from 'react';
3
+ import {
4
+ MaterialSymbol,
5
+ type Route,
6
+ SFSymbol,
7
+ useTheme,
8
+ } from '@react-navigation/native';
9
+ import React from 'react';
5
10
  import {
6
11
  type ColorValue,
12
+ Image,
7
13
  Platform,
8
14
  type StyleProp,
9
15
  StyleSheet,
@@ -16,11 +22,11 @@ type Props = {
16
22
  /**
17
23
  * The route object which should be specified by the drawer item.
18
24
  */
19
- route?: Route<string>;
25
+ route?: Route<string> | undefined;
20
26
  /**
21
27
  * The `href` to use for the anchor tag on web
22
28
  */
23
- href?: string;
29
+ href?: string | undefined;
24
30
  /**
25
31
  * The label text of the item.
26
32
  */
@@ -30,15 +36,18 @@ type Props = {
30
36
  /**
31
37
  * Icon to display for the `DrawerItem`.
32
38
  */
33
- icon?: (props: {
34
- focused: boolean;
35
- size: number;
36
- color: ColorValue;
37
- }) => React.ReactNode;
39
+ icon?:
40
+ | Icon
41
+ | ((props: {
42
+ focused: boolean;
43
+ size: number;
44
+ color: ColorValue;
45
+ }) => Icon | React.ReactNode)
46
+ | undefined;
38
47
  /**
39
48
  * Whether to highlight the drawer item as active.
40
49
  */
41
- focused?: boolean;
50
+ focused?: boolean | undefined;
42
51
  /**
43
52
  * Function to execute on press.
44
53
  */
@@ -46,54 +55,54 @@ type Props = {
46
55
  /**
47
56
  * Color for the icon and label when the item is active.
48
57
  */
49
- activeTintColor?: ColorValue;
58
+ activeTintColor?: ColorValue | undefined;
50
59
  /**
51
60
  * Color for the icon and label when the item is inactive.
52
61
  */
53
- inactiveTintColor?: ColorValue;
62
+ inactiveTintColor?: ColorValue | undefined;
54
63
  /**
55
64
  * Background color for item when its active.
56
65
  */
57
- activeBackgroundColor?: ColorValue;
66
+ activeBackgroundColor?: ColorValue | undefined;
58
67
  /**
59
68
  * Background color for item when its inactive.
60
69
  */
61
- inactiveBackgroundColor?: ColorValue;
70
+ inactiveBackgroundColor?: ColorValue | undefined;
62
71
  /**
63
72
  * Color of the touchable effect on press.
64
73
  * Only supported on Android.
65
74
  *
66
75
  * @platform android
67
76
  */
68
- pressColor?: ColorValue;
77
+ pressColor?: ColorValue | undefined;
69
78
  /**
70
79
  * Opacity of the touchable effect on press.
71
80
  * Only supported on iOS.
72
81
  *
73
82
  * @platform ios
74
83
  */
75
- pressOpacity?: number;
84
+ pressOpacity?: number | undefined;
76
85
  /**
77
86
  * Style object for the label element.
78
87
  */
79
- labelStyle?: StyleProp<TextStyle>;
88
+ labelStyle?: StyleProp<TextStyle> | undefined;
80
89
  /**
81
90
  * Style object for the wrapper element.
82
91
  */
83
- style?: StyleProp<ViewStyle>;
92
+ style?: StyleProp<ViewStyle> | undefined;
84
93
  /**
85
94
  * Whether label font should scale to respect Text Size accessibility settings.
86
95
  */
87
- allowFontScaling?: boolean;
96
+ allowFontScaling?: boolean | undefined;
88
97
 
89
98
  /**
90
99
  * Accessibility label for drawer item.
91
100
  */
92
- accessibilityLabel?: string;
101
+ accessibilityLabel?: string | undefined;
93
102
  /**
94
103
  * ID to locate this drawer item in tests.
95
104
  */
96
- testID?: string;
105
+ testID?: string | undefined;
97
106
  };
98
107
 
99
108
  /**
@@ -134,7 +143,59 @@ export function DrawerItem(props: Props) {
134
143
  'rgba(0, 0, 0, 0.06)')
135
144
  : inactiveBackgroundColor;
136
145
 
137
- const iconNode = icon ? icon({ size: 24, focused, color }) : null;
146
+ const iconNode = React.useMemo(() => {
147
+ if (!icon) {
148
+ return null;
149
+ }
150
+
151
+ const size = 24;
152
+
153
+ const iconValue =
154
+ typeof icon === 'function' ? icon({ size, focused, color }) : icon;
155
+
156
+ if (React.isValidElement(iconValue)) {
157
+ return iconValue;
158
+ }
159
+
160
+ if (
161
+ typeof iconValue === 'object' &&
162
+ iconValue != null &&
163
+ 'type' in iconValue
164
+ ) {
165
+ switch (iconValue.type) {
166
+ case 'image':
167
+ return (
168
+ <Image
169
+ source={iconValue.source}
170
+ style={{
171
+ width: size,
172
+ height: size,
173
+ tintColor: iconValue.tinted === false ? undefined : color,
174
+ }}
175
+ />
176
+ );
177
+ case 'sfSymbol':
178
+ return <SFSymbol name={iconValue.name} size={size} color={color} />;
179
+ case 'materialSymbol':
180
+ return (
181
+ <MaterialSymbol
182
+ name={iconValue.name}
183
+ variant={iconValue.variant}
184
+ weight={iconValue.weight}
185
+ size={size}
186
+ color={color}
187
+ />
188
+ );
189
+ default: {
190
+ const _exhaustiveCheck: never = iconValue;
191
+
192
+ return _exhaustiveCheck;
193
+ }
194
+ }
195
+ }
196
+
197
+ return null;
198
+ }, [icon, focused, color]);
138
199
 
139
200
  return (
140
201
  <View
@@ -147,7 +208,10 @@ export function DrawerItem(props: Props) {
147
208
  onPress={onPress}
148
209
  role="button"
149
210
  aria-label={accessibilityLabel}
150
- aria-selected={focused}
211
+ aria-current={
212
+ Platform.OS === 'web' ? (focused ? 'page' : undefined) : undefined
213
+ }
214
+ aria-selected={Platform.OS === 'web' ? undefined : focused}
151
215
  pressColor={pressColor}
152
216
  pressOpacity={pressOpacity}
153
217
  hoverEffect={typeof color === 'string' ? { color } : undefined}
@@ -23,8 +23,12 @@ export function DrawerItemList({ state, navigation, descriptors }: Props) {
23
23
  const { buildHref } = useLinkBuilder();
24
24
 
25
25
  const focusedRoute = state.routes[state.index];
26
- const focusedDescriptor = descriptors[focusedRoute.key];
27
- const focusedOptions = focusedDescriptor.options;
26
+
27
+ if (focusedRoute == null) {
28
+ throw new Error(`Couldn't find a route at index ${state.index}.`);
29
+ }
30
+
31
+ const focusedOptions = descriptors[focusedRoute.key]?.options ?? {};
28
32
 
29
33
  const {
30
34
  drawerActiveTintColor,
@@ -34,6 +38,12 @@ export function DrawerItemList({ state, navigation, descriptors }: Props) {
34
38
  } = focusedOptions;
35
39
 
36
40
  return state.routes.map((route, i) => {
41
+ const descriptor = descriptors[route.key];
42
+
43
+ if (descriptor == null) {
44
+ throw new Error(`Couldn't find a descriptor for route '${route.key}'.`);
45
+ }
46
+
37
47
  const focused = i === state.index;
38
48
 
39
49
  const onPress = () => {
@@ -47,7 +57,7 @@ export function DrawerItemList({ state, navigation, descriptors }: Props) {
47
57
  navigation.dispatch({
48
58
  ...(focused
49
59
  ? DrawerActions.closeDrawer()
50
- : CommonActions.navigate(route)),
60
+ : CommonActions.navigate(route.name, route.params)),
51
61
  target: state.key,
52
62
  });
53
63
  }
@@ -59,8 +69,9 @@ export function DrawerItemList({ state, navigation, descriptors }: Props) {
59
69
  drawerIcon,
60
70
  drawerLabelStyle,
61
71
  drawerItemStyle,
72
+ drawerItemTestID,
62
73
  drawerAllowFontScaling,
63
- } = descriptors[route.key].options;
74
+ } = descriptor.options;
64
75
 
65
76
  return (
66
77
  <DrawerItem
@@ -84,6 +95,7 @@ export function DrawerItemList({ state, navigation, descriptors }: Props) {
84
95
  labelStyle={drawerLabelStyle}
85
96
  style={drawerItemStyle}
86
97
  onPress={onPress}
98
+ testID={drawerItemTestID}
87
99
  />
88
100
  );
89
101
  }) as React.ReactNode as React.ReactElement;
@@ -1,51 +1,95 @@
1
- import { HeaderButton } from '@react-navigation/elements';
2
- import { DrawerActions, useNavigation } from '@react-navigation/native';
1
+ import { HeaderButton, type Icon } from '@react-navigation/elements';
3
2
  import {
4
- type ColorValue,
5
- Image,
6
- type ImageSourcePropType,
7
- StyleSheet,
8
- } from 'react-native';
3
+ DrawerActions,
4
+ MaterialSymbol,
5
+ SFSymbol,
6
+ useNavigation,
7
+ } from '@react-navigation/native';
8
+ import * as React from 'react';
9
+ import { type ColorValue, Image, Platform, StyleSheet } from 'react-native';
9
10
 
10
11
  import toggleDrawerIcon from './assets/toggle-drawer-icon.png';
11
12
 
12
13
  type Props = {
13
- accessibilityLabel?: string;
14
- pressColor?: ColorValue;
15
- pressOpacity?: number;
16
- tintColor?: ColorValue;
17
- imageSource?: ImageSourcePropType;
14
+ icon?:
15
+ | Icon
16
+ | ((props: { tintColor: ColorValue | undefined }) => React.ReactNode)
17
+ | undefined;
18
+ accessibilityLabel?: string | undefined;
19
+ pressColor?: ColorValue | undefined;
20
+ pressOpacity?: number | undefined;
21
+ tintColor?: ColorValue | undefined;
22
+ testID?: string | undefined;
18
23
  };
19
24
 
20
25
  export function DrawerToggleButton({
26
+ icon,
21
27
  tintColor,
22
28
  accessibilityLabel = 'Show navigation menu',
23
- imageSource = toggleDrawerIcon,
24
29
  ...rest
25
30
  }: Props) {
26
31
  const navigation = useNavigation();
27
32
 
33
+ const drawerIcon =
34
+ icon ??
35
+ Platform.select<Icon>({
36
+ ios: {
37
+ type: 'sfSymbol',
38
+ name: 'line.3.horizontal',
39
+ },
40
+ android: {
41
+ type: 'materialSymbol',
42
+ name: 'menu',
43
+ },
44
+ default: {
45
+ type: 'image',
46
+ source: toggleDrawerIcon,
47
+ },
48
+ });
49
+
28
50
  return (
29
51
  <HeaderButton
30
52
  {...rest}
31
53
  accessibilityLabel={accessibilityLabel}
32
54
  onPress={() => navigation.dispatch(DrawerActions.toggleDrawer())}
33
55
  >
34
- <Image
35
- resizeMode="contain"
36
- source={imageSource}
37
- fadeDuration={0}
38
- tintColor={tintColor}
39
- style={styles.icon}
40
- />
56
+ {typeof drawerIcon === 'function' ? (
57
+ drawerIcon({ tintColor })
58
+ ) : drawerIcon.type === 'sfSymbol' ? (
59
+ <SFSymbol
60
+ name={drawerIcon.name}
61
+ size={ICON_SIZE}
62
+ color={tintColor}
63
+ style={styles.icon}
64
+ />
65
+ ) : drawerIcon.type === 'materialSymbol' ? (
66
+ <MaterialSymbol
67
+ name={drawerIcon.name}
68
+ variant={drawerIcon.variant}
69
+ weight={drawerIcon.weight}
70
+ size={ICON_SIZE}
71
+ color={tintColor}
72
+ style={styles.icon}
73
+ />
74
+ ) : (
75
+ <Image
76
+ resizeMode="contain"
77
+ source={drawerIcon.source}
78
+ fadeDuration={0}
79
+ tintColor={tintColor}
80
+ style={styles.icon}
81
+ />
82
+ )}
41
83
  </HeaderButton>
42
84
  );
43
85
  }
44
86
 
87
+ const ICON_SIZE = 24;
88
+
45
89
  const styles = StyleSheet.create({
46
90
  icon: {
47
- height: 24,
48
- width: 24,
91
+ height: ICON_SIZE,
92
+ width: ICON_SIZE,
49
93
  marginVertical: 8,
50
94
  marginHorizontal: 5,
51
95
  },