@react-navigation/drawer 6.2.0 → 6.3.2

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 (35) hide show
  1. package/lib/commonjs/views/DrawerItem.js +2 -0
  2. package/lib/commonjs/views/DrawerItem.js.map +1 -1
  3. package/lib/commonjs/views/DrawerItemList.js +22 -9
  4. package/lib/commonjs/views/DrawerItemList.js.map +1 -1
  5. package/lib/commonjs/views/DrawerView.js +5 -6
  6. package/lib/commonjs/views/DrawerView.js.map +1 -1
  7. package/lib/commonjs/views/ScreenFallback.js.map +1 -1
  8. package/lib/commonjs/views/legacy/Drawer.js +2 -2
  9. package/lib/commonjs/views/legacy/Drawer.js.map +1 -1
  10. package/lib/commonjs/views/modern/Drawer.js +7 -4
  11. package/lib/commonjs/views/modern/Drawer.js.map +1 -1
  12. package/lib/module/views/DrawerItem.js +2 -0
  13. package/lib/module/views/DrawerItem.js.map +1 -1
  14. package/lib/module/views/DrawerItemList.js +22 -9
  15. package/lib/module/views/DrawerItemList.js.map +1 -1
  16. package/lib/module/views/DrawerView.js +5 -6
  17. package/lib/module/views/DrawerView.js.map +1 -1
  18. package/lib/module/views/ScreenFallback.js.map +1 -1
  19. package/lib/module/views/legacy/Drawer.js +2 -2
  20. package/lib/module/views/legacy/Drawer.js.map +1 -1
  21. package/lib/module/views/modern/Drawer.js +8 -5
  22. package/lib/module/views/modern/Drawer.js.map +1 -1
  23. package/lib/typescript/src/types.d.ts +16 -12
  24. package/lib/typescript/src/views/DrawerItem.d.ts +4 -0
  25. package/lib/typescript/src/views/ScreenFallback.d.ts +1 -0
  26. package/lib/typescript/src/views/legacy/Overlay.d.ts +3 -1
  27. package/lib/typescript/src/views/modern/Overlay.d.ts +3 -1
  28. package/package.json +6 -6
  29. package/src/types.tsx +14 -13
  30. package/src/views/DrawerItem.tsx +6 -0
  31. package/src/views/DrawerItemList.tsx +21 -8
  32. package/src/views/DrawerView.tsx +5 -7
  33. package/src/views/ScreenFallback.tsx +1 -0
  34. package/src/views/legacy/Drawer.tsx +2 -2
  35. package/src/views/modern/Drawer.tsx +18 -6
@@ -39,12 +39,31 @@ export default function DrawerItemList({
39
39
 
40
40
  return state.routes.map((route, i) => {
41
41
  const focused = i === state.index;
42
+
43
+ const onPress = () => {
44
+ const event = navigation.emit({
45
+ type: 'drawerItemPress',
46
+ target: route.key,
47
+ canPreventDefault: true,
48
+ });
49
+
50
+ if (!event.defaultPrevented) {
51
+ navigation.dispatch({
52
+ ...(focused
53
+ ? DrawerActions.closeDrawer()
54
+ : CommonActions.navigate({ name: route.name, merge: true })),
55
+ target: state.key,
56
+ });
57
+ }
58
+ };
59
+
42
60
  const {
43
61
  title,
44
62
  drawerLabel,
45
63
  drawerIcon,
46
64
  drawerLabelStyle,
47
65
  drawerItemStyle,
66
+ drawerAllowFontScaling,
48
67
  } = descriptors[route.key].options;
49
68
 
50
69
  return (
@@ -63,17 +82,11 @@ export default function DrawerItemList({
63
82
  inactiveTintColor={drawerInactiveTintColor}
64
83
  activeBackgroundColor={drawerActiveBackgroundColor}
65
84
  inactiveBackgroundColor={drawerInactiveBackgroundColor}
85
+ allowFontScaling={drawerAllowFontScaling}
66
86
  labelStyle={drawerLabelStyle}
67
87
  style={drawerItemStyle}
68
88
  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
- }}
89
+ onPress={onPress}
77
90
  />
78
91
  );
79
92
  }) as React.ReactNode as React.ReactElement;
@@ -19,7 +19,7 @@ import {
19
19
  StyleSheet,
20
20
  View,
21
21
  } from 'react-native';
22
- import Animated from 'react-native-reanimated';
22
+ import * as Reanimated from 'react-native-reanimated';
23
23
  import { useSafeAreaFrame } from 'react-native-safe-area-context';
24
24
 
25
25
  import type {
@@ -80,12 +80,9 @@ function DrawerViewBase({
80
80
  detachInactiveScreens = Platform.OS === 'web' ||
81
81
  Platform.OS === 'android' ||
82
82
  Platform.OS === 'ios',
83
- // Running in chrome debugger
84
- // @ts-expect-error
85
- useLegacyImplementation = !global.nativeCallSyncHook ||
86
- // Reanimated 2 is not configured
87
- // @ts-expect-error: the type definitions are incomplete
88
- !Animated.isConfigured?.(),
83
+ // Reanimated 2 is not configured
84
+ // @ts-expect-error: the type definitions are incomplete
85
+ useLegacyImplementation = !Reanimated.isConfigured?.(),
89
86
  }: Props) {
90
87
  const Drawer: React.ComponentType<DrawerProps> = useLegacyImplementation
91
88
  ? require('./legacy/Drawer').default
@@ -205,6 +202,7 @@ function DrawerViewBase({
205
202
  return (
206
203
  <MaybeScreenContainer
207
204
  enabled={detachInactiveScreens}
205
+ hasTwoStates
208
206
  style={styles.content}
209
207
  >
210
208
  {state.routes.map((route, index) => {
@@ -22,6 +22,7 @@ export const MaybeScreenContainer = ({
22
22
  ...rest
23
23
  }: ViewProps & {
24
24
  enabled: boolean;
25
+ hasTwoStates: boolean;
25
26
  children: React.ReactNode;
26
27
  }) => {
27
28
  if (Screens?.screensEnabled?.()) {
@@ -558,7 +558,7 @@ export default class DrawerView extends React.Component<DrawerProps> {
558
558
  drawerType === 'permanent'
559
559
  ? // Reanimated needs the property to be present, but it results in Browser bug
560
560
  // https://bugs.chromium.org/p/chromium/issues/detail?id=20574
561
- undefined
561
+ []
562
562
  : [{ translateX: contentTranslateX }],
563
563
  },
564
564
  ]}
@@ -619,7 +619,7 @@ export default class DrawerView extends React.Component<DrawerProps> {
619
619
  drawerType === 'permanent'
620
620
  ? // Reanimated needs the property to be present, but it results in Browser bug
621
621
  // https://bugs.chromium.org/p/chromium/issues/detail?id=20574
622
- undefined
622
+ []
623
623
  : [{ translateX: drawerTranslateX }],
624
624
  opacity: this.drawerOpacity,
625
625
  },
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import {
3
+ I18nManager,
3
4
  InteractionManager,
4
5
  Keyboard,
5
6
  Platform,
@@ -260,15 +261,26 @@ export default function Drawer({
260
261
  });
261
262
 
262
263
  const drawerAnimatedStyle = useAnimatedStyle(() => {
264
+ const distanceFromEdge = dimensions.width - drawerWidth;
265
+
263
266
  return {
264
267
  transform:
265
268
  drawerType === 'permanent'
266
269
  ? // Reanimated needs the property to be present, but it results in Browser bug
267
270
  // https://bugs.chromium.org/p/chromium/issues/detail?id=20574
268
- undefined
271
+ []
269
272
  : [
270
273
  {
271
- translateX: drawerType === 'back' ? 0 : translateX.value,
274
+ translateX:
275
+ // The drawer stays in place when `drawerType` is `back`
276
+ (drawerType === 'back' ? 0 : translateX.value) +
277
+ (drawerPosition === 'left'
278
+ ? I18nManager.isRTL
279
+ ? -distanceFromEdge
280
+ : 0
281
+ : I18nManager.isRTL
282
+ ? 0
283
+ : distanceFromEdge),
272
284
  },
273
285
  ],
274
286
  };
@@ -280,15 +292,15 @@ export default function Drawer({
280
292
  drawerType === 'permanent'
281
293
  ? // Reanimated needs the property to be present, but it results in Browser bug
282
294
  // https://bugs.chromium.org/p/chromium/issues/detail?id=20574
283
- undefined
295
+ []
284
296
  : [
285
297
  {
286
298
  translateX:
299
+ // The screen content stays in place when `drawerType` is `front`
287
300
  drawerType === 'front'
288
301
  ? 0
289
- : drawerPosition === 'left'
290
- ? drawerWidth + translateX.value
291
- : translateX.value - drawerWidth,
302
+ : translateX.value +
303
+ drawerWidth * (drawerPosition === 'left' ? 1 : -1),
292
304
  },
293
305
  ],
294
306
  };