@react-navigation/drawer 6.1.7 → 6.3.1
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/lib/commonjs/index.js +14 -14
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/navigators/createDrawerNavigator.js +19 -15
- package/lib/commonjs/navigators/createDrawerNavigator.js.map +1 -1
- package/lib/commonjs/utils/DrawerStatusContext.js.map +1 -1
- package/lib/commonjs/utils/useDrawerStatus.js.map +1 -1
- package/lib/commonjs/views/DrawerContent.js +6 -5
- package/lib/commonjs/views/DrawerContent.js.map +1 -1
- package/lib/commonjs/views/DrawerContentScrollView.js +7 -6
- package/lib/commonjs/views/DrawerContentScrollView.js.map +1 -1
- package/lib/commonjs/views/DrawerItem.js +15 -10
- package/lib/commonjs/views/DrawerItem.js.map +1 -1
- package/lib/commonjs/views/DrawerItemList.js +28 -14
- package/lib/commonjs/views/DrawerItemList.js.map +1 -1
- package/lib/commonjs/views/DrawerToggleButton.js +5 -4
- package/lib/commonjs/views/DrawerToggleButton.js.map +1 -1
- package/lib/commonjs/views/DrawerView.js +34 -30
- package/lib/commonjs/views/DrawerView.js.map +1 -1
- package/lib/commonjs/views/GestureHandler.js +7 -4
- package/lib/commonjs/views/GestureHandler.js.map +1 -1
- package/lib/commonjs/views/GestureHandlerNative.js +1 -1
- package/lib/commonjs/views/ScreenFallback.js +13 -9
- package/lib/commonjs/views/ScreenFallback.js.map +1 -1
- package/lib/commonjs/views/legacy/Drawer.js +20 -13
- package/lib/commonjs/views/legacy/Drawer.js.map +1 -1
- package/lib/commonjs/views/legacy/Overlay.js +8 -6
- package/lib/commonjs/views/legacy/Overlay.js.map +1 -1
- package/lib/commonjs/views/modern/Drawer.js +28 -30
- package/lib/commonjs/views/modern/Drawer.js.map +1 -1
- package/lib/commonjs/views/modern/Overlay.js +18 -9
- package/lib/commonjs/views/modern/Overlay.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/navigators/createDrawerNavigator.js +19 -15
- package/lib/module/navigators/createDrawerNavigator.js.map +1 -1
- package/lib/module/utils/DrawerStatusContext.js.map +1 -1
- package/lib/module/utils/useDrawerStatus.js.map +1 -1
- package/lib/module/views/DrawerContent.js +6 -5
- package/lib/module/views/DrawerContent.js.map +1 -1
- package/lib/module/views/DrawerContentScrollView.js +7 -6
- package/lib/module/views/DrawerContentScrollView.js.map +1 -1
- package/lib/module/views/DrawerItem.js +15 -10
- package/lib/module/views/DrawerItem.js.map +1 -1
- package/lib/module/views/DrawerItemList.js +28 -14
- package/lib/module/views/DrawerItemList.js.map +1 -1
- package/lib/module/views/DrawerToggleButton.js +5 -4
- package/lib/module/views/DrawerToggleButton.js.map +1 -1
- package/lib/module/views/DrawerView.js +33 -29
- package/lib/module/views/DrawerView.js.map +1 -1
- package/lib/module/views/GestureHandler.js +6 -3
- package/lib/module/views/GestureHandler.js.map +1 -1
- package/lib/module/views/ScreenFallback.js +13 -9
- package/lib/module/views/ScreenFallback.js.map +1 -1
- package/lib/module/views/legacy/Drawer.js +20 -13
- package/lib/module/views/legacy/Drawer.js.map +1 -1
- package/lib/module/views/legacy/Overlay.js +8 -6
- package/lib/module/views/legacy/Overlay.js.map +1 -1
- package/lib/module/views/modern/Drawer.js +28 -30
- package/lib/module/views/modern/Drawer.js.map +1 -1
- package/lib/module/views/modern/Overlay.js +19 -10
- package/lib/module/views/modern/Overlay.js.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/navigators/createDrawerNavigator.d.ts +1 -1
- package/lib/typescript/src/types.d.ts +13 -1
- package/lib/typescript/src/utils/useDrawerStatus.d.ts +2 -1
- package/lib/typescript/src/views/DrawerItem.d.ts +4 -0
- package/lib/typescript/src/views/ScreenFallback.d.ts +1 -0
- package/lib/typescript/src/views/legacy/Overlay.d.ts +7 -1
- package/lib/typescript/src/views/modern/Overlay.d.ts +7 -1
- package/package.json +10 -10
- package/src/index.tsx +1 -0
- package/src/navigators/createDrawerNavigator.tsx +11 -7
- package/src/types.tsx +11 -1
- package/src/utils/DrawerStatusContext.tsx +3 -2
- package/src/utils/useDrawerStatus.tsx +2 -1
- package/src/views/DrawerItem.tsx +6 -0
- package/src/views/DrawerItemList.tsx +21 -8
- package/src/views/DrawerView.tsx +3 -2
- package/src/views/ScreenFallback.tsx +1 -0
- package/src/views/legacy/Drawer.tsx +21 -9
- package/src/views/legacy/Overlay.tsx +1 -0
- package/src/views/modern/Drawer.tsx +25 -23
- package/src/views/modern/Overlay.tsx +16 -3
|
@@ -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;
|
package/src/views/DrawerView.tsx
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
StyleSheet,
|
|
20
20
|
View,
|
|
21
21
|
} from 'react-native';
|
|
22
|
-
import
|
|
22
|
+
import * as Reanimated from 'react-native-reanimated';
|
|
23
23
|
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
|
24
24
|
|
|
25
25
|
import type {
|
|
@@ -85,7 +85,7 @@ function DrawerViewBase({
|
|
|
85
85
|
useLegacyImplementation = !global.nativeCallSyncHook ||
|
|
86
86
|
// Reanimated 2 is not configured
|
|
87
87
|
// @ts-expect-error: the type definitions are incomplete
|
|
88
|
-
!
|
|
88
|
+
!Reanimated.isConfigured?.(),
|
|
89
89
|
}: Props) {
|
|
90
90
|
const Drawer: React.ComponentType<DrawerProps> = useLegacyImplementation
|
|
91
91
|
? require('./legacy/Drawer').default
|
|
@@ -205,6 +205,7 @@ function DrawerViewBase({
|
|
|
205
205
|
return (
|
|
206
206
|
<MaybeScreenContainer
|
|
207
207
|
enabled={detachInactiveScreens}
|
|
208
|
+
hasTwoStates
|
|
208
209
|
style={styles.content}
|
|
209
210
|
>
|
|
210
211
|
{state.routes.map((route, index) => {
|
|
@@ -553,9 +553,14 @@ export default class DrawerView extends React.Component<DrawerProps> {
|
|
|
553
553
|
<Animated.View
|
|
554
554
|
style={[
|
|
555
555
|
styles.content,
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
556
|
+
{
|
|
557
|
+
transform:
|
|
558
|
+
drawerType === 'permanent'
|
|
559
|
+
? // Reanimated needs the property to be present, but it results in Browser bug
|
|
560
|
+
// https://bugs.chromium.org/p/chromium/issues/detail?id=20574
|
|
561
|
+
[]
|
|
562
|
+
: [{ translateX: contentTranslateX }],
|
|
563
|
+
},
|
|
559
564
|
]}
|
|
560
565
|
>
|
|
561
566
|
<View
|
|
@@ -578,6 +583,10 @@ export default class DrawerView extends React.Component<DrawerProps> {
|
|
|
578
583
|
progress={progress}
|
|
579
584
|
onPress={() => this.toggleDrawer(false)}
|
|
580
585
|
style={overlayStyle as any}
|
|
586
|
+
accessibilityElementsHidden={!isOpen}
|
|
587
|
+
importantForAccessibility={
|
|
588
|
+
isOpen ? 'auto' : 'no-hide-descendants'
|
|
589
|
+
}
|
|
581
590
|
/>
|
|
582
591
|
)
|
|
583
592
|
}
|
|
@@ -605,12 +614,15 @@ export default class DrawerView extends React.Component<DrawerProps> {
|
|
|
605
614
|
onLayout={this.handleDrawerLayout}
|
|
606
615
|
style={[
|
|
607
616
|
styles.container,
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
617
|
+
{
|
|
618
|
+
transform:
|
|
619
|
+
drawerType === 'permanent'
|
|
620
|
+
? // Reanimated needs the property to be present, but it results in Browser bug
|
|
621
|
+
// https://bugs.chromium.org/p/chromium/issues/detail?id=20574
|
|
622
|
+
[]
|
|
623
|
+
: [{ translateX: drawerTranslateX }],
|
|
624
|
+
opacity: this.drawerOpacity,
|
|
625
|
+
},
|
|
614
626
|
drawerType === 'permanent'
|
|
615
627
|
? // Without this, the `left`/`right` values don't get reset
|
|
616
628
|
isRight
|
|
@@ -260,35 +260,37 @@ export default function Drawer({
|
|
|
260
260
|
});
|
|
261
261
|
|
|
262
262
|
const drawerAnimatedStyle = useAnimatedStyle(() => {
|
|
263
|
-
if (drawerType === 'permanent') {
|
|
264
|
-
return {};
|
|
265
|
-
}
|
|
266
|
-
|
|
267
263
|
return {
|
|
268
|
-
transform:
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
264
|
+
transform:
|
|
265
|
+
drawerType === 'permanent'
|
|
266
|
+
? // Reanimated needs the property to be present, but it results in Browser bug
|
|
267
|
+
// https://bugs.chromium.org/p/chromium/issues/detail?id=20574
|
|
268
|
+
[]
|
|
269
|
+
: [
|
|
270
|
+
{
|
|
271
|
+
translateX: drawerType === 'back' ? 0 : translateX.value,
|
|
272
|
+
},
|
|
273
|
+
],
|
|
273
274
|
};
|
|
274
275
|
});
|
|
275
276
|
|
|
276
277
|
const contentAnimatedStyle = useAnimatedStyle(() => {
|
|
277
|
-
if (drawerType === 'permanent') {
|
|
278
|
-
return {};
|
|
279
|
-
}
|
|
280
|
-
|
|
281
278
|
return {
|
|
282
|
-
transform:
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
279
|
+
transform:
|
|
280
|
+
drawerType === 'permanent'
|
|
281
|
+
? // Reanimated needs the property to be present, but it results in Browser bug
|
|
282
|
+
// https://bugs.chromium.org/p/chromium/issues/detail?id=20574
|
|
283
|
+
[]
|
|
284
|
+
: [
|
|
285
|
+
{
|
|
286
|
+
translateX:
|
|
287
|
+
drawerType === 'front'
|
|
288
|
+
? 0
|
|
289
|
+
: drawerPosition === 'left'
|
|
290
|
+
? drawerWidth + translateX.value
|
|
291
|
+
: translateX.value - drawerWidth,
|
|
292
|
+
},
|
|
293
|
+
],
|
|
292
294
|
};
|
|
293
295
|
});
|
|
294
296
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Platform, Pressable, StyleSheet } from 'react-native';
|
|
3
|
-
import Animated, {
|
|
3
|
+
import Animated, {
|
|
4
|
+
useAnimatedProps,
|
|
5
|
+
useAnimatedStyle,
|
|
6
|
+
} from 'react-native-reanimated';
|
|
4
7
|
|
|
5
8
|
const PROGRESS_EPSILON = 0.05;
|
|
6
9
|
|
|
@@ -17,17 +20,27 @@ const Overlay = React.forwardRef(function Overlay(
|
|
|
17
20
|
return {
|
|
18
21
|
opacity: progress.value,
|
|
19
22
|
// We don't want the user to be able to press through the overlay when drawer is open
|
|
20
|
-
//
|
|
21
|
-
// But we can also send the overlay behind the screen
|
|
23
|
+
// We can send the overlay behind the screen to avoid it
|
|
22
24
|
zIndex: progress.value > PROGRESS_EPSILON ? 0 : -1,
|
|
23
25
|
};
|
|
24
26
|
});
|
|
25
27
|
|
|
28
|
+
const animatedProps = useAnimatedProps(() => {
|
|
29
|
+
const active = progress.value > PROGRESS_EPSILON;
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
pointerEvents: active ? 'auto' : 'none',
|
|
33
|
+
accessibilityElementsHidden: !active,
|
|
34
|
+
importantForAccessibility: active ? 'auto' : 'no-hide-descendants',
|
|
35
|
+
} as const;
|
|
36
|
+
});
|
|
37
|
+
|
|
26
38
|
return (
|
|
27
39
|
<Animated.View
|
|
28
40
|
{...props}
|
|
29
41
|
ref={ref}
|
|
30
42
|
style={[styles.overlay, overlayStyle, animatedStyle, style]}
|
|
43
|
+
animatedProps={animatedProps}
|
|
31
44
|
>
|
|
32
45
|
<Pressable onPress={onPress} style={styles.pressable} />
|
|
33
46
|
</Animated.View>
|