@react-navigation/drawer 8.0.0-alpha.2 → 8.0.0-alpha.20

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 (45) hide show
  1. package/lib/module/utils/useDrawerStatus.js +1 -1
  2. package/lib/module/utils/useDrawerStatus.js.map +1 -1
  3. package/lib/module/views/DrawerContentScrollView.js +23 -14
  4. package/lib/module/views/DrawerContentScrollView.js.map +1 -1
  5. package/lib/module/views/DrawerItem.js +50 -8
  6. package/lib/module/views/DrawerItem.js.map +1 -1
  7. package/lib/module/views/DrawerItemList.js +3 -1
  8. package/lib/module/views/DrawerItemList.js.map +1 -1
  9. package/lib/module/views/DrawerToggleButton.js +37 -7
  10. package/lib/module/views/DrawerToggleButton.js.map +1 -1
  11. package/lib/module/views/DrawerView.js +14 -15
  12. package/lib/module/views/DrawerView.js.map +1 -1
  13. package/lib/typescript/src/types.d.ts +20 -17
  14. package/lib/typescript/src/types.d.ts.map +1 -1
  15. package/lib/typescript/src/views/DrawerContentScrollView.d.ts.map +1 -1
  16. package/lib/typescript/src/views/DrawerItem.d.ts +18 -17
  17. package/lib/typescript/src/views/DrawerItem.d.ts.map +1 -1
  18. package/lib/typescript/src/views/DrawerItemList.d.ts.map +1 -1
  19. package/lib/typescript/src/views/DrawerToggleButton.d.ts +12 -7
  20. package/lib/typescript/src/views/DrawerToggleButton.d.ts.map +1 -1
  21. package/lib/typescript/src/views/DrawerView.d.ts.map +1 -1
  22. package/package.json +20 -19
  23. package/src/types.tsx +26 -20
  24. package/src/utils/useDrawerStatus.tsx +1 -1
  25. package/src/views/DrawerContentScrollView.tsx +28 -18
  26. package/src/views/DrawerItem.tsx +84 -23
  27. package/src/views/DrawerItemList.tsx +2 -0
  28. package/src/views/DrawerToggleButton.tsx +66 -22
  29. package/src/views/DrawerView.tsx +18 -18
  30. package/lib/module/views/assets/toggle-drawer-icon@1x.android.png +0 -0
  31. package/lib/module/views/assets/toggle-drawer-icon@1x.ios.png +0 -0
  32. package/lib/module/views/assets/toggle-drawer-icon@2x.android.png +0 -0
  33. package/lib/module/views/assets/toggle-drawer-icon@2x.ios.png +0 -0
  34. package/lib/module/views/assets/toggle-drawer-icon@3x.android.png +0 -0
  35. package/lib/module/views/assets/toggle-drawer-icon@3x.ios.png +0 -0
  36. package/lib/module/views/assets/toggle-drawer-icon@4x.android.png +0 -0
  37. package/lib/module/views/assets/toggle-drawer-icon@4x.ios.png +0 -0
  38. package/src/views/assets/toggle-drawer-icon@1x.android.png +0 -0
  39. package/src/views/assets/toggle-drawer-icon@1x.ios.png +0 -0
  40. package/src/views/assets/toggle-drawer-icon@2x.android.png +0 -0
  41. package/src/views/assets/toggle-drawer-icon@2x.ios.png +0 -0
  42. package/src/views/assets/toggle-drawer-icon@3x.android.png +0 -0
  43. package/src/views/assets/toggle-drawer-icon@3x.ios.png +0 -0
  44. package/src/views/assets/toggle-drawer-icon@4x.android.png +0 -0
  45. package/src/views/assets/toggle-drawer-icon@4x.ios.png +0 -0
@@ -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
  },
@@ -1,5 +1,7 @@
1
1
  import { getHeaderTitle, Header } from '@react-navigation/elements';
2
2
  import {
3
+ ActivityView,
4
+ Container,
3
5
  SafeAreaProviderCompat,
4
6
  Screen as ScreenContent,
5
7
  } from '@react-navigation/elements/internal';
@@ -15,7 +17,6 @@ import {
15
17
  import * as React from 'react';
16
18
  import { Platform, StyleSheet } from 'react-native';
17
19
  import { Drawer } from 'react-native-drawer-layout';
18
- import { Screen, ScreenContainer } from 'react-native-screens';
19
20
  import useLatestCallback from 'use-latest-callback';
20
21
 
21
22
  import type {
@@ -52,9 +53,6 @@ function DrawerViewBase({
52
53
  descriptors,
53
54
  defaultStatus,
54
55
  drawerContent = renderDrawerContentDefault,
55
- detachInactiveScreens = Platform.OS === 'web' ||
56
- Platform.OS === 'android' ||
57
- Platform.OS === 'ios',
58
56
  }: Props) {
59
57
  const { direction } = useLocale();
60
58
 
@@ -209,11 +207,7 @@ function DrawerViewBase({
209
207
 
210
208
  const renderSceneContent = () => {
211
209
  return (
212
- <ScreenContainer
213
- enabled={detachInactiveScreens}
214
- hasTwoStates
215
- style={styles.content}
216
- >
210
+ <Container style={styles.content}>
217
211
  {state.routes.map((route, index) => {
218
212
  const descriptor = descriptors[route.key];
219
213
  const { lazy = true } = descriptor.options;
@@ -231,7 +225,7 @@ function DrawerViewBase({
231
225
  }
232
226
 
233
227
  const {
234
- freezeOnBlur,
228
+ inactiveBehavior = 'pause',
235
229
  header = ({ options }: DrawerHeaderProps) => (
236
230
  <Header
237
231
  {...options}
@@ -254,14 +248,20 @@ function DrawerViewBase({
254
248
  sceneStyle,
255
249
  } = descriptor.options;
256
250
 
251
+ // For preloaded screens and if lazy is false,
252
+ // Keep them active so that the effects can run
253
+ const isActive =
254
+ inactiveBehavior === 'none' ||
255
+ isFocused ||
256
+ isPreloaded ||
257
+ (lazy === false && !loaded.includes(route.key));
258
+
257
259
  return (
258
- <Screen
260
+ <ActivityView
259
261
  key={route.key}
260
- style={[StyleSheet.absoluteFill, { zIndex: isFocused ? 0 : -1 }]}
261
- activityState={isFocused ? 2 : 0}
262
- enabled={detachInactiveScreens}
263
- freezeOnBlur={freezeOnBlur}
264
- shouldFreeze={!isFocused && !isPreloaded}
262
+ mode={isFocused ? 'normal' : isActive ? 'inert' : 'paused'}
263
+ visible={isFocused}
264
+ style={{ ...StyleSheet.absoluteFill, zIndex: isFocused ? 0 : -1 }}
265
265
  >
266
266
  <ScreenContent
267
267
  focused={isFocused}
@@ -280,10 +280,10 @@ function DrawerViewBase({
280
280
  >
281
281
  {descriptor.render()}
282
282
  </ScreenContent>
283
- </Screen>
283
+ </ActivityView>
284
284
  );
285
285
  })}
286
- </ScreenContainer>
286
+ </Container>
287
287
  );
288
288
  };
289
289