@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.
- package/lib/commonjs/views/DrawerItem.js +2 -0
- package/lib/commonjs/views/DrawerItem.js.map +1 -1
- package/lib/commonjs/views/DrawerItemList.js +22 -9
- package/lib/commonjs/views/DrawerItemList.js.map +1 -1
- package/lib/commonjs/views/DrawerView.js +5 -6
- package/lib/commonjs/views/DrawerView.js.map +1 -1
- package/lib/commonjs/views/ScreenFallback.js.map +1 -1
- package/lib/commonjs/views/legacy/Drawer.js +2 -2
- package/lib/commonjs/views/legacy/Drawer.js.map +1 -1
- package/lib/commonjs/views/modern/Drawer.js +7 -4
- package/lib/commonjs/views/modern/Drawer.js.map +1 -1
- package/lib/module/views/DrawerItem.js +2 -0
- package/lib/module/views/DrawerItem.js.map +1 -1
- package/lib/module/views/DrawerItemList.js +22 -9
- package/lib/module/views/DrawerItemList.js.map +1 -1
- package/lib/module/views/DrawerView.js +5 -6
- package/lib/module/views/DrawerView.js.map +1 -1
- package/lib/module/views/ScreenFallback.js.map +1 -1
- package/lib/module/views/legacy/Drawer.js +2 -2
- package/lib/module/views/legacy/Drawer.js.map +1 -1
- package/lib/module/views/modern/Drawer.js +8 -5
- package/lib/module/views/modern/Drawer.js.map +1 -1
- package/lib/typescript/src/types.d.ts +16 -12
- 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 +3 -1
- package/lib/typescript/src/views/modern/Overlay.d.ts +3 -1
- package/package.json +6 -6
- package/src/types.tsx +14 -13
- package/src/views/DrawerItem.tsx +6 -0
- package/src/views/DrawerItemList.tsx +21 -8
- package/src/views/DrawerView.tsx +5 -7
- package/src/views/ScreenFallback.tsx +1 -0
- package/src/views/legacy/Drawer.tsx +2 -2
- 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;
|
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 {
|
|
@@ -80,12 +80,9 @@ function DrawerViewBase({
|
|
|
80
80
|
detachInactiveScreens = Platform.OS === 'web' ||
|
|
81
81
|
Platform.OS === 'android' ||
|
|
82
82
|
Platform.OS === 'ios',
|
|
83
|
-
//
|
|
84
|
-
// @ts-expect-error
|
|
85
|
-
useLegacyImplementation = !
|
|
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) => {
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
271
|
+
[]
|
|
269
272
|
: [
|
|
270
273
|
{
|
|
271
|
-
translateX:
|
|
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
|
-
|
|
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
|
-
:
|
|
290
|
-
|
|
291
|
-
: translateX.value - drawerWidth,
|
|
302
|
+
: translateX.value +
|
|
303
|
+
drawerWidth * (drawerPosition === 'left' ? 1 : -1),
|
|
292
304
|
},
|
|
293
305
|
],
|
|
294
306
|
};
|