@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.
Files changed (65) hide show
  1. package/lib/module/index.js.map +1 -1
  2. package/lib/module/navigators/createDrawerNavigator.js +3 -7
  3. package/lib/module/navigators/createDrawerNavigator.js.map +1 -1
  4. package/lib/module/utils/getDrawerStatusFromState.js.map +1 -1
  5. package/lib/module/utils/useDrawerStatus.js +1 -1
  6. package/lib/module/utils/useDrawerStatus.js.map +1 -1
  7. package/lib/module/views/DrawerContent.js +4 -2
  8. package/lib/module/views/DrawerContent.js.map +1 -1
  9. package/lib/module/views/DrawerContentScrollView.js +30 -13
  10. package/lib/module/views/DrawerContentScrollView.js.map +1 -1
  11. package/lib/module/views/DrawerItem.js +26 -8
  12. package/lib/module/views/DrawerItem.js.map +1 -1
  13. package/lib/module/views/DrawerItemList.js +17 -7
  14. package/lib/module/views/DrawerItemList.js.map +1 -1
  15. package/lib/module/views/DrawerToggleButton.js +27 -10
  16. package/lib/module/views/DrawerToggleButton.js.map +1 -1
  17. package/lib/module/views/DrawerView.js +28 -20
  18. package/lib/module/views/DrawerView.js.map +1 -1
  19. package/lib/typescript/src/index.d.ts +11 -11
  20. package/lib/typescript/src/index.d.ts.map +1 -1
  21. package/lib/typescript/src/navigators/createDrawerNavigator.d.ts +9 -15
  22. package/lib/typescript/src/navigators/createDrawerNavigator.d.ts.map +1 -1
  23. package/lib/typescript/src/types.d.ts +24 -25
  24. package/lib/typescript/src/types.d.ts.map +1 -1
  25. package/lib/typescript/src/utils/getDrawerStatusFromState.d.ts.map +1 -1
  26. package/lib/typescript/src/views/DrawerContent.d.ts +2 -2
  27. package/lib/typescript/src/views/DrawerContent.d.ts.map +1 -1
  28. package/lib/typescript/src/views/DrawerContentScrollView.d.ts +5 -2
  29. package/lib/typescript/src/views/DrawerContentScrollView.d.ts.map +1 -1
  30. package/lib/typescript/src/views/DrawerItem.d.ts +18 -17
  31. package/lib/typescript/src/views/DrawerItem.d.ts.map +1 -1
  32. package/lib/typescript/src/views/DrawerItemList.d.ts +1 -1
  33. package/lib/typescript/src/views/DrawerItemList.d.ts.map +1 -1
  34. package/lib/typescript/src/views/DrawerToggleButton.d.ts +12 -7
  35. package/lib/typescript/src/views/DrawerToggleButton.d.ts.map +1 -1
  36. package/lib/typescript/src/views/DrawerView.d.ts +3 -2
  37. package/lib/typescript/src/views/DrawerView.d.ts.map +1 -1
  38. package/package.json +26 -26
  39. package/src/index.tsx +1 -0
  40. package/src/navigators/createDrawerNavigator.tsx +9 -40
  41. package/src/types.tsx +30 -25
  42. package/src/utils/getDrawerStatusFromState.tsx +1 -3
  43. package/src/utils/useDrawerStatus.tsx +1 -1
  44. package/src/views/DrawerContent.tsx +6 -2
  45. package/src/views/DrawerContentScrollView.tsx +31 -15
  46. package/src/views/DrawerItem.tsx +57 -23
  47. package/src/views/DrawerItemList.tsx +22 -8
  48. package/src/views/DrawerToggleButton.tsx +48 -22
  49. package/src/views/DrawerView.tsx +47 -26
  50. package/lib/module/views/assets/toggle-drawer-icon@1x.android.png +0 -0
  51. package/lib/module/views/assets/toggle-drawer-icon@1x.ios.png +0 -0
  52. package/lib/module/views/assets/toggle-drawer-icon@2x.android.png +0 -0
  53. package/lib/module/views/assets/toggle-drawer-icon@2x.ios.png +0 -0
  54. package/lib/module/views/assets/toggle-drawer-icon@3x.android.png +0 -0
  55. package/lib/module/views/assets/toggle-drawer-icon@3x.ios.png +0 -0
  56. package/lib/module/views/assets/toggle-drawer-icon@4x.android.png +0 -0
  57. package/lib/module/views/assets/toggle-drawer-icon@4x.ios.png +0 -0
  58. package/src/views/assets/toggle-drawer-icon@1x.android.png +0 -0
  59. package/src/views/assets/toggle-drawer-icon@1x.ios.png +0 -0
  60. package/src/views/assets/toggle-drawer-icon@2x.android.png +0 -0
  61. package/src/views/assets/toggle-drawer-icon@2x.ios.png +0 -0
  62. package/src/views/assets/toggle-drawer-icon@3x.android.png +0 -0
  63. package/src/views/assets/toggle-drawer-icon@3x.ios.png +0 -0
  64. package/src/views/assets/toggle-drawer-icon@4x.android.png +0 -0
  65. package/src/views/assets/toggle-drawer-icon@4x.ios.png +0 -0
@@ -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
- DrawerNavigationProp,
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 focusedRouteKey = state.routes[state.index].key;
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
- } = descriptors[focusedRouteKey].options;
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 prevRoute = state.routes.find(
101
+ const currentState = navigation.getState();
102
+ const prevRoute = currentState.routes.find(
95
103
  (route) => route.key === previousRouteKey
96
104
  );
97
105
 
98
- if (prevRoute?.state?.type === 'stack' && prevRoute.state.key) {
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, state.routes]);
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
- <ScreenContainer
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
- freezeOnBlur,
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
- <Screen
282
+ <ActivityView
259
283
  key={route.key}
260
- style={[StyleSheet.absoluteFill, { zIndex: isFocused ? 0 : -1 }]}
261
- activityState={isFocused ? 2 : 0}
262
- enabled={detachInactiveScreens}
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
- </Screen>
304
+ </ActivityView>
284
305
  );
285
306
  })}
286
- </ScreenContainer>
307
+ </Container>
287
308
  );
288
309
  };
289
310