@react-navigation/drawer 6.1.5 → 6.2.0
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 +22 -16
- package/lib/commonjs/navigators/createDrawerNavigator.js.map +1 -1
- package/lib/commonjs/utils/DrawerStatusContext.js.map +1 -1
- package/lib/commonjs/utils/getDrawerStatusFromState.js +2 -2
- package/lib/commonjs/utils/getDrawerStatusFromState.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 +14 -12
- package/lib/commonjs/views/DrawerItem.js.map +1 -1
- package/lib/commonjs/views/DrawerItemList.js +6 -5
- 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 +43 -34
- 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 +22 -16
- package/lib/module/navigators/createDrawerNavigator.js.map +1 -1
- package/lib/module/utils/DrawerStatusContext.js.map +1 -1
- package/lib/module/utils/getDrawerStatusFromState.js +2 -2
- package/lib/module/utils/getDrawerStatusFromState.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 +14 -12
- package/lib/module/views/DrawerItem.js.map +1 -1
- package/lib/module/views/DrawerItemList.js +6 -5
- 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 +42 -33
- 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/utils/DrawerStatusContext.d.ts +2 -1
- package/lib/typescript/src/utils/getDrawerStatusFromState.d.ts +2 -2
- package/lib/typescript/src/utils/useDrawerStatus.d.ts +2 -1
- package/lib/typescript/src/views/DrawerView.d.ts +2 -1
- package/lib/typescript/src/views/legacy/Overlay.d.ts +4 -0
- package/lib/typescript/src/views/modern/Overlay.d.ts +4 -0
- package/package.json +10 -10
- package/src/index.tsx +1 -0
- package/src/navigators/createDrawerNavigator.tsx +22 -14
- package/src/utils/DrawerStatusContext.tsx +4 -2
- package/src/utils/getDrawerStatusFromState.tsx +4 -3
- package/src/utils/useDrawerStatus.tsx +2 -1
- package/src/views/DrawerView.tsx +20 -6
- 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
package/src/views/DrawerView.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
DrawerActions,
|
|
9
9
|
DrawerNavigationState,
|
|
10
|
+
DrawerStatus,
|
|
10
11
|
ParamListBase,
|
|
11
12
|
useTheme,
|
|
12
13
|
} from '@react-navigation/native';
|
|
@@ -39,6 +40,7 @@ import { GestureHandlerRootView } from './GestureHandler';
|
|
|
39
40
|
import { MaybeScreen, MaybeScreenContainer } from './ScreenFallback';
|
|
40
41
|
|
|
41
42
|
type Props = DrawerNavigationConfig & {
|
|
43
|
+
defaultStatus: DrawerStatus;
|
|
42
44
|
state: DrawerNavigationState<ParamListBase>;
|
|
43
45
|
navigation: DrawerNavigationHelpers;
|
|
44
46
|
descriptors: DrawerDescriptorMap;
|
|
@@ -71,6 +73,7 @@ function DrawerViewBase({
|
|
|
71
73
|
state,
|
|
72
74
|
navigation,
|
|
73
75
|
descriptors,
|
|
76
|
+
defaultStatus,
|
|
74
77
|
drawerContent = (props: DrawerContentComponentProps) => (
|
|
75
78
|
<DrawerContent {...props} />
|
|
76
79
|
),
|
|
@@ -132,25 +135,29 @@ function DrawerViewBase({
|
|
|
132
135
|
}, [navigation, state.key]);
|
|
133
136
|
|
|
134
137
|
React.useEffect(() => {
|
|
135
|
-
if (drawerStatus
|
|
138
|
+
if (drawerStatus === defaultStatus || drawerType === 'permanent') {
|
|
136
139
|
return;
|
|
137
140
|
}
|
|
138
141
|
|
|
139
|
-
const
|
|
142
|
+
const handleHardwareBack = () => {
|
|
140
143
|
// We shouldn't handle the back button if the parent screen isn't focused
|
|
141
144
|
// This will avoid the drawer overriding event listeners from a focused screen
|
|
142
145
|
if (!navigation.isFocused()) {
|
|
143
146
|
return false;
|
|
144
147
|
}
|
|
145
148
|
|
|
146
|
-
|
|
149
|
+
if (defaultStatus === 'open') {
|
|
150
|
+
handleDrawerOpen();
|
|
151
|
+
} else {
|
|
152
|
+
handleDrawerClose();
|
|
153
|
+
}
|
|
147
154
|
|
|
148
155
|
return true;
|
|
149
156
|
};
|
|
150
157
|
|
|
151
158
|
const handleEscape = (e: KeyboardEvent) => {
|
|
152
159
|
if (e.key === 'Escape') {
|
|
153
|
-
|
|
160
|
+
handleHardwareBack();
|
|
154
161
|
}
|
|
155
162
|
};
|
|
156
163
|
|
|
@@ -159,7 +166,7 @@ function DrawerViewBase({
|
|
|
159
166
|
// This will make sure that our handler will run first when back button is pressed
|
|
160
167
|
const subscription = BackHandler.addEventListener(
|
|
161
168
|
'hardwareBackPress',
|
|
162
|
-
|
|
169
|
+
handleHardwareBack
|
|
163
170
|
);
|
|
164
171
|
|
|
165
172
|
if (Platform.OS === 'web') {
|
|
@@ -173,7 +180,14 @@ function DrawerViewBase({
|
|
|
173
180
|
document?.body?.removeEventListener?.('keyup', handleEscape);
|
|
174
181
|
}
|
|
175
182
|
};
|
|
176
|
-
}, [
|
|
183
|
+
}, [
|
|
184
|
+
defaultStatus,
|
|
185
|
+
drawerStatus,
|
|
186
|
+
drawerType,
|
|
187
|
+
handleDrawerClose,
|
|
188
|
+
handleDrawerOpen,
|
|
189
|
+
navigation,
|
|
190
|
+
]);
|
|
177
191
|
|
|
178
192
|
const renderDrawerContent = () => {
|
|
179
193
|
return (
|
|
@@ -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
|
+
undefined
|
|
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
|
+
undefined
|
|
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
|
+
undefined
|
|
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
|
+
undefined
|
|
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>
|