@react-navigation/drawer 8.0.0-alpha.4 → 8.0.0-alpha.40
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/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 +52 -9
- package/lib/module/views/DrawerItem.js.map +1 -1
- package/lib/module/views/DrawerItemList.js +13 -5
- package/lib/module/views/DrawerItemList.js.map +1 -1
- package/lib/module/views/DrawerToggleButton.js +37 -7
- package/lib/module/views/DrawerToggleButton.js.map +1 -1
- package/lib/module/views/DrawerView.js +24 -17
- 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/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 +19 -18
- 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/useDrawerStatus.tsx +1 -1
- package/src/views/DrawerContent.tsx +6 -2
- package/src/views/DrawerContentScrollView.tsx +31 -15
- package/src/views/DrawerItem.tsx +88 -24
- package/src/views/DrawerItemList.tsx +16 -4
- package/src/views/DrawerToggleButton.tsx +66 -22
- package/src/views/DrawerView.tsx +37 -20
- 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,6 +25,7 @@ import type {
|
|
|
24
25
|
DrawerHeaderProps,
|
|
25
26
|
DrawerNavigationConfig,
|
|
26
27
|
DrawerNavigationHelpers,
|
|
28
|
+
DrawerNavigationOptions,
|
|
27
29
|
DrawerNavigationProp,
|
|
28
30
|
} from '../types';
|
|
29
31
|
import { addCancelListener } from '../utils/addCancelListener';
|
|
@@ -52,13 +54,19 @@ function DrawerViewBase({
|
|
|
52
54
|
descriptors,
|
|
53
55
|
defaultStatus,
|
|
54
56
|
drawerContent = renderDrawerContentDefault,
|
|
55
|
-
detachInactiveScreens = Platform.OS === 'web' ||
|
|
56
|
-
Platform.OS === 'android' ||
|
|
57
|
-
Platform.OS === 'ios',
|
|
58
57
|
}: Props) {
|
|
59
58
|
const { direction } = useLocale();
|
|
60
59
|
|
|
61
|
-
const
|
|
60
|
+
const focusedRoute = state.routes[state.index];
|
|
61
|
+
|
|
62
|
+
if (focusedRoute == null) {
|
|
63
|
+
throw new Error(`Couldn't find a route at index ${state.index}.`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const focusedRouteKey = focusedRoute.key;
|
|
67
|
+
const focusedOptions: DrawerNavigationOptions =
|
|
68
|
+
descriptors[focusedRouteKey]?.options ?? {};
|
|
69
|
+
|
|
62
70
|
const {
|
|
63
71
|
drawerHideStatusBarOnOpen,
|
|
64
72
|
drawerPosition = direction === 'rtl' ? 'right' : 'left',
|
|
@@ -74,7 +82,7 @@ function DrawerViewBase({
|
|
|
74
82
|
swipeMinDistance,
|
|
75
83
|
overlayStyle,
|
|
76
84
|
overlayAccessibilityLabel,
|
|
77
|
-
} =
|
|
85
|
+
} = focusedOptions;
|
|
78
86
|
|
|
79
87
|
const [loaded, setLoaded] = React.useState([focusedRouteKey]);
|
|
80
88
|
|
|
@@ -209,13 +217,16 @@ function DrawerViewBase({
|
|
|
209
217
|
|
|
210
218
|
const renderSceneContent = () => {
|
|
211
219
|
return (
|
|
212
|
-
<
|
|
213
|
-
enabled={detachInactiveScreens}
|
|
214
|
-
hasTwoStates
|
|
215
|
-
style={styles.content}
|
|
216
|
-
>
|
|
220
|
+
<Container style={styles.content}>
|
|
217
221
|
{state.routes.map((route, index) => {
|
|
218
222
|
const descriptor = descriptors[route.key];
|
|
223
|
+
|
|
224
|
+
if (descriptor == null) {
|
|
225
|
+
throw new Error(
|
|
226
|
+
`Couldn't find a descriptor for route '${route.key}'.`
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
219
230
|
const { lazy = true } = descriptor.options;
|
|
220
231
|
const isFocused = state.index === index;
|
|
221
232
|
const isPreloaded = state.preloadedRouteKeys.includes(route.key);
|
|
@@ -231,7 +242,7 @@ function DrawerViewBase({
|
|
|
231
242
|
}
|
|
232
243
|
|
|
233
244
|
const {
|
|
234
|
-
|
|
245
|
+
inactiveBehavior = 'pause',
|
|
235
246
|
header = ({ options }: DrawerHeaderProps) => (
|
|
236
247
|
<Header
|
|
237
248
|
{...options}
|
|
@@ -254,14 +265,20 @@ function DrawerViewBase({
|
|
|
254
265
|
sceneStyle,
|
|
255
266
|
} = descriptor.options;
|
|
256
267
|
|
|
268
|
+
// For preloaded screens and if lazy is false,
|
|
269
|
+
// Keep them active so that the effects can run
|
|
270
|
+
const isActive =
|
|
271
|
+
inactiveBehavior === 'none' ||
|
|
272
|
+
isFocused ||
|
|
273
|
+
isPreloaded ||
|
|
274
|
+
(lazy === false && !loaded.includes(route.key));
|
|
275
|
+
|
|
257
276
|
return (
|
|
258
|
-
<
|
|
277
|
+
<ActivityView
|
|
259
278
|
key={route.key}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
freezeOnBlur={freezeOnBlur}
|
|
264
|
-
shouldFreeze={!isFocused && !isPreloaded}
|
|
279
|
+
mode={isFocused ? 'normal' : isActive ? 'inert' : 'paused'}
|
|
280
|
+
visible={isFocused}
|
|
281
|
+
style={{ ...StyleSheet.absoluteFill, zIndex: isFocused ? 0 : -1 }}
|
|
265
282
|
>
|
|
266
283
|
<ScreenContent
|
|
267
284
|
focused={isFocused}
|
|
@@ -280,10 +297,10 @@ function DrawerViewBase({
|
|
|
280
297
|
>
|
|
281
298
|
{descriptor.render()}
|
|
282
299
|
</ScreenContent>
|
|
283
|
-
</
|
|
300
|
+
</ActivityView>
|
|
284
301
|
);
|
|
285
302
|
})}
|
|
286
|
-
</
|
|
303
|
+
</Container>
|
|
287
304
|
);
|
|
288
305
|
};
|
|
289
306
|
|
|
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
|