@react-navigation/drawer 8.0.0-alpha.5 → 8.0.0-alpha.51
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/module/index.js.map +1 -1
- package/lib/module/navigators/createDrawerNavigator.js +3 -7
- package/lib/module/navigators/createDrawerNavigator.js.map +1 -1
- package/lib/module/utils/getDrawerStatusFromState.js.map +1 -1
- package/lib/module/utils/useDrawerStatus.js +1 -1
- package/lib/module/utils/useDrawerStatus.js.map +1 -1
- package/lib/module/views/DrawerContent.js +4 -2
- package/lib/module/views/DrawerContent.js.map +1 -1
- package/lib/module/views/DrawerContentScrollView.js +30 -13
- package/lib/module/views/DrawerContentScrollView.js.map +1 -1
- package/lib/module/views/DrawerItem.js +26 -8
- package/lib/module/views/DrawerItem.js.map +1 -1
- package/lib/module/views/DrawerItemList.js +17 -7
- package/lib/module/views/DrawerItemList.js.map +1 -1
- package/lib/module/views/DrawerToggleButton.js +27 -10
- package/lib/module/views/DrawerToggleButton.js.map +1 -1
- package/lib/module/views/DrawerView.js +28 -20
- package/lib/module/views/DrawerView.js.map +1 -1
- package/lib/typescript/src/index.d.ts +11 -11
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/navigators/createDrawerNavigator.d.ts +9 -15
- package/lib/typescript/src/navigators/createDrawerNavigator.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +24 -25
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils/getDrawerStatusFromState.d.ts.map +1 -1
- package/lib/typescript/src/views/DrawerContent.d.ts +2 -2
- package/lib/typescript/src/views/DrawerContent.d.ts.map +1 -1
- package/lib/typescript/src/views/DrawerContentScrollView.d.ts +5 -2
- package/lib/typescript/src/views/DrawerContentScrollView.d.ts.map +1 -1
- package/lib/typescript/src/views/DrawerItem.d.ts +18 -17
- package/lib/typescript/src/views/DrawerItem.d.ts.map +1 -1
- package/lib/typescript/src/views/DrawerItemList.d.ts +1 -1
- package/lib/typescript/src/views/DrawerItemList.d.ts.map +1 -1
- package/lib/typescript/src/views/DrawerToggleButton.d.ts +12 -7
- package/lib/typescript/src/views/DrawerToggleButton.d.ts.map +1 -1
- package/lib/typescript/src/views/DrawerView.d.ts +3 -2
- package/lib/typescript/src/views/DrawerView.d.ts.map +1 -1
- package/package.json +26 -26
- package/src/index.tsx +1 -0
- package/src/navigators/createDrawerNavigator.tsx +9 -40
- package/src/types.tsx +30 -25
- package/src/utils/getDrawerStatusFromState.tsx +1 -3
- package/src/utils/useDrawerStatus.tsx +1 -1
- package/src/views/DrawerContent.tsx +6 -2
- package/src/views/DrawerContentScrollView.tsx +31 -15
- package/src/views/DrawerItem.tsx +57 -23
- package/src/views/DrawerItemList.tsx +22 -8
- package/src/views/DrawerToggleButton.tsx +48 -22
- package/src/views/DrawerView.tsx +47 -26
- package/lib/module/views/assets/toggle-drawer-icon@1x.android.png +0 -0
- package/lib/module/views/assets/toggle-drawer-icon@1x.ios.png +0 -0
- package/lib/module/views/assets/toggle-drawer-icon@2x.android.png +0 -0
- package/lib/module/views/assets/toggle-drawer-icon@2x.ios.png +0 -0
- package/lib/module/views/assets/toggle-drawer-icon@3x.android.png +0 -0
- package/lib/module/views/assets/toggle-drawer-icon@3x.ios.png +0 -0
- package/lib/module/views/assets/toggle-drawer-icon@4x.android.png +0 -0
- package/lib/module/views/assets/toggle-drawer-icon@4x.ios.png +0 -0
- package/src/views/assets/toggle-drawer-icon@1x.android.png +0 -0
- package/src/views/assets/toggle-drawer-icon@1x.ios.png +0 -0
- package/src/views/assets/toggle-drawer-icon@2x.android.png +0 -0
- package/src/views/assets/toggle-drawer-icon@2x.ios.png +0 -0
- package/src/views/assets/toggle-drawer-icon@3x.android.png +0 -0
- package/src/views/assets/toggle-drawer-icon@3x.ios.png +0 -0
- package/src/views/assets/toggle-drawer-icon@4x.android.png +0 -0
- package/src/views/assets/toggle-drawer-icon@4x.ios.png +0 -0
package/src/views/DrawerView.tsx
CHANGED
|
@@ -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 {
|
|
@@ -24,7 +25,7 @@ import type {
|
|
|
24
25
|
DrawerHeaderProps,
|
|
25
26
|
DrawerNavigationConfig,
|
|
26
27
|
DrawerNavigationHelpers,
|
|
27
|
-
|
|
28
|
+
DrawerNavigationOptions,
|
|
28
29
|
} from '../types';
|
|
29
30
|
import { addCancelListener } from '../utils/addCancelListener';
|
|
30
31
|
import { DrawerPositionContext } from '../utils/DrawerPositionContext';
|
|
@@ -52,13 +53,19 @@ 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
|
|
|
61
|
-
const
|
|
59
|
+
const focusedRoute = state.routes[state.index];
|
|
60
|
+
|
|
61
|
+
if (focusedRoute == null) {
|
|
62
|
+
throw new Error(`Couldn't find a route at index ${state.index}.`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const focusedRouteKey = focusedRoute.key;
|
|
66
|
+
const focusedOptions: DrawerNavigationOptions =
|
|
67
|
+
descriptors[focusedRouteKey]?.options ?? {};
|
|
68
|
+
|
|
62
69
|
const {
|
|
63
70
|
drawerHideStatusBarOnOpen,
|
|
64
71
|
drawerPosition = direction === 'rtl' ? 'right' : 'left',
|
|
@@ -74,7 +81,7 @@ function DrawerViewBase({
|
|
|
74
81
|
swipeMinDistance,
|
|
75
82
|
overlayStyle,
|
|
76
83
|
overlayAccessibilityLabel,
|
|
77
|
-
} =
|
|
84
|
+
} = focusedOptions;
|
|
78
85
|
|
|
79
86
|
const [loaded, setLoaded] = React.useState([focusedRouteKey]);
|
|
80
87
|
|
|
@@ -91,11 +98,17 @@ function DrawerViewBase({
|
|
|
91
98
|
previousRouteKey !== focusedRouteKey &&
|
|
92
99
|
descriptors[previousRouteKey]?.options.popToTopOnBlur
|
|
93
100
|
) {
|
|
94
|
-
const
|
|
101
|
+
const currentState = navigation.getState();
|
|
102
|
+
const prevRoute = currentState.routes.find(
|
|
95
103
|
(route) => route.key === previousRouteKey
|
|
96
104
|
);
|
|
97
105
|
|
|
98
|
-
if (
|
|
106
|
+
if (
|
|
107
|
+
prevRoute?.state?.type === 'stack' &&
|
|
108
|
+
prevRoute.state.key &&
|
|
109
|
+
((prevRoute.state.index ?? prevRoute.state.routes.length - 1) > 0 ||
|
|
110
|
+
prevRoute.state.routes[0]?.history?.length)
|
|
111
|
+
) {
|
|
99
112
|
navigation.dispatch({
|
|
100
113
|
...StackActions.popToTop(),
|
|
101
114
|
target: prevRoute.state.key,
|
|
@@ -104,7 +117,7 @@ function DrawerViewBase({
|
|
|
104
117
|
}
|
|
105
118
|
|
|
106
119
|
previousRouteKeyRef.current = focusedRouteKey;
|
|
107
|
-
}, [descriptors, focusedRouteKey, navigation
|
|
120
|
+
}, [descriptors, focusedRouteKey, navigation]);
|
|
108
121
|
|
|
109
122
|
const { colors } = useTheme();
|
|
110
123
|
|
|
@@ -209,13 +222,16 @@ function DrawerViewBase({
|
|
|
209
222
|
|
|
210
223
|
const renderSceneContent = () => {
|
|
211
224
|
return (
|
|
212
|
-
<
|
|
213
|
-
enabled={detachInactiveScreens}
|
|
214
|
-
hasTwoStates
|
|
215
|
-
style={styles.content}
|
|
216
|
-
>
|
|
225
|
+
<Container style={styles.content}>
|
|
217
226
|
{state.routes.map((route, index) => {
|
|
218
227
|
const descriptor = descriptors[route.key];
|
|
228
|
+
|
|
229
|
+
if (descriptor == null) {
|
|
230
|
+
throw new Error(
|
|
231
|
+
`Couldn't find a descriptor for route '${route.key}'.`
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
219
235
|
const { lazy = true } = descriptor.options;
|
|
220
236
|
const isFocused = state.index === index;
|
|
221
237
|
const isPreloaded = state.preloadedRouteKeys.includes(route.key);
|
|
@@ -231,7 +247,7 @@ function DrawerViewBase({
|
|
|
231
247
|
}
|
|
232
248
|
|
|
233
249
|
const {
|
|
234
|
-
|
|
250
|
+
inactiveBehavior = 'pause',
|
|
235
251
|
header = ({ options }: DrawerHeaderProps) => (
|
|
236
252
|
<Header
|
|
237
253
|
{...options}
|
|
@@ -254,14 +270,20 @@ function DrawerViewBase({
|
|
|
254
270
|
sceneStyle,
|
|
255
271
|
} = descriptor.options;
|
|
256
272
|
|
|
273
|
+
// For preloaded screens and if lazy is false,
|
|
274
|
+
// Keep them active so that the effects can run
|
|
275
|
+
const isActive =
|
|
276
|
+
inactiveBehavior === 'none' ||
|
|
277
|
+
isFocused ||
|
|
278
|
+
isPreloaded ||
|
|
279
|
+
(lazy === false && !loaded.includes(route.key));
|
|
280
|
+
|
|
257
281
|
return (
|
|
258
|
-
<
|
|
282
|
+
<ActivityView
|
|
259
283
|
key={route.key}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
freezeOnBlur={freezeOnBlur}
|
|
264
|
-
shouldFreeze={!isFocused && !isPreloaded}
|
|
284
|
+
mode={isFocused ? 'normal' : isActive ? 'inert' : 'paused'}
|
|
285
|
+
visible={isFocused}
|
|
286
|
+
style={{ ...StyleSheet.absoluteFill, zIndex: isFocused ? 0 : -1 }}
|
|
265
287
|
>
|
|
266
288
|
<ScreenContent
|
|
267
289
|
focused={isFocused}
|
|
@@ -272,18 +294,17 @@ function DrawerViewBase({
|
|
|
272
294
|
headerTransparent={headerTransparent}
|
|
273
295
|
header={header({
|
|
274
296
|
route: descriptor.route,
|
|
275
|
-
navigation:
|
|
276
|
-
descriptor.navigation as DrawerNavigationProp<ParamListBase>,
|
|
297
|
+
navigation: descriptor.navigation,
|
|
277
298
|
options: descriptor.options,
|
|
278
299
|
})}
|
|
279
300
|
style={sceneStyle}
|
|
280
301
|
>
|
|
281
302
|
{descriptor.render()}
|
|
282
303
|
</ScreenContent>
|
|
283
|
-
</
|
|
304
|
+
</ActivityView>
|
|
284
305
|
);
|
|
285
306
|
})}
|
|
286
|
-
</
|
|
307
|
+
</Container>
|
|
287
308
|
);
|
|
288
309
|
};
|
|
289
310
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|