@react-navigation/native-stack 7.0.0-rc.27 → 7.0.0-rc.28

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 (68) hide show
  1. package/lib/commonjs/navigators/createNativeStackNavigator.js +3 -1
  2. package/lib/commonjs/navigators/createNativeStackNavigator.js.map +1 -1
  3. package/lib/commonjs/views/DebugContainer.native.js +8 -10
  4. package/lib/commonjs/views/DebugContainer.native.js.map +1 -1
  5. package/lib/commonjs/views/FooterComponent.js +19 -0
  6. package/lib/commonjs/views/FooterComponent.js.map +1 -0
  7. package/lib/commonjs/views/HeaderConfig.js +24 -14
  8. package/lib/commonjs/views/HeaderConfig.js.map +1 -1
  9. package/lib/commonjs/views/NativeStackView.js +10 -7
  10. package/lib/commonjs/views/NativeStackView.js.map +1 -1
  11. package/lib/commonjs/views/NativeStackView.native.js +56 -18
  12. package/lib/commonjs/views/NativeStackView.native.js.map +1 -1
  13. package/lib/module/navigators/createNativeStackNavigator.js +3 -1
  14. package/lib/module/navigators/createNativeStackNavigator.js.map +1 -1
  15. package/lib/module/views/DebugContainer.native.js +9 -11
  16. package/lib/module/views/DebugContainer.native.js.map +1 -1
  17. package/lib/module/views/FooterComponent.js +14 -0
  18. package/lib/module/views/FooterComponent.js.map +1 -0
  19. package/lib/module/views/HeaderConfig.js +24 -14
  20. package/lib/module/views/HeaderConfig.js.map +1 -1
  21. package/lib/module/views/NativeStackView.js +10 -7
  22. package/lib/module/views/NativeStackView.js.map +1 -1
  23. package/lib/module/views/NativeStackView.native.js +56 -18
  24. package/lib/module/views/NativeStackView.native.js.map +1 -1
  25. package/lib/typescript/commonjs/src/index.d.ts +1 -1
  26. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  27. package/lib/typescript/commonjs/src/navigators/createNativeStackNavigator.d.ts.map +1 -1
  28. package/lib/typescript/commonjs/src/types.d.ts +80 -18
  29. package/lib/typescript/commonjs/src/types.d.ts.map +1 -1
  30. package/lib/typescript/commonjs/src/views/DebugContainer.d.ts +1 -1
  31. package/lib/typescript/commonjs/src/views/DebugContainer.d.ts.map +1 -1
  32. package/lib/typescript/commonjs/src/views/DebugContainer.native.d.ts +1 -1
  33. package/lib/typescript/commonjs/src/views/DebugContainer.native.d.ts.map +1 -1
  34. package/lib/typescript/commonjs/src/views/FooterComponent.d.ts +7 -0
  35. package/lib/typescript/commonjs/src/views/FooterComponent.d.ts.map +1 -0
  36. package/lib/typescript/commonjs/src/views/HeaderConfig.d.ts.map +1 -1
  37. package/lib/typescript/commonjs/src/views/NativeStackView.d.ts +4 -3
  38. package/lib/typescript/commonjs/src/views/NativeStackView.d.ts.map +1 -1
  39. package/lib/typescript/commonjs/src/views/NativeStackView.native.d.ts +4 -3
  40. package/lib/typescript/commonjs/src/views/NativeStackView.native.d.ts.map +1 -1
  41. package/lib/typescript/commonjs/tsconfig.build.tsbuildinfo +1 -1
  42. package/lib/typescript/module/src/index.d.ts +1 -1
  43. package/lib/typescript/module/src/index.d.ts.map +1 -1
  44. package/lib/typescript/module/src/navigators/createNativeStackNavigator.d.ts.map +1 -1
  45. package/lib/typescript/module/src/types.d.ts +80 -18
  46. package/lib/typescript/module/src/types.d.ts.map +1 -1
  47. package/lib/typescript/module/src/views/DebugContainer.d.ts +1 -1
  48. package/lib/typescript/module/src/views/DebugContainer.d.ts.map +1 -1
  49. package/lib/typescript/module/src/views/DebugContainer.native.d.ts +1 -1
  50. package/lib/typescript/module/src/views/DebugContainer.native.d.ts.map +1 -1
  51. package/lib/typescript/module/src/views/FooterComponent.d.ts +7 -0
  52. package/lib/typescript/module/src/views/FooterComponent.d.ts.map +1 -0
  53. package/lib/typescript/module/src/views/HeaderConfig.d.ts.map +1 -1
  54. package/lib/typescript/module/src/views/NativeStackView.d.ts +4 -3
  55. package/lib/typescript/module/src/views/NativeStackView.d.ts.map +1 -1
  56. package/lib/typescript/module/src/views/NativeStackView.native.d.ts +4 -3
  57. package/lib/typescript/module/src/views/NativeStackView.native.d.ts.map +1 -1
  58. package/lib/typescript/module/tsconfig.build.tsbuildinfo +1 -1
  59. package/package.json +7 -7
  60. package/src/index.tsx +2 -0
  61. package/src/navigators/createNativeStackNavigator.tsx +2 -1
  62. package/src/types.tsx +74 -18
  63. package/src/views/DebugContainer.native.tsx +13 -6
  64. package/src/views/DebugContainer.tsx +1 -1
  65. package/src/views/FooterComponent.tsx +10 -0
  66. package/src/views/HeaderConfig.tsx +23 -21
  67. package/src/views/NativeStackView.native.tsx +81 -14
  68. package/src/views/NativeStackView.tsx +23 -11
@@ -9,6 +9,7 @@ import {
9
9
  } from '@react-navigation/elements';
10
10
  import {
11
11
  type ParamListBase,
12
+ type RouteProp,
12
13
  type StackNavigationState,
13
14
  useLinkBuilder,
14
15
  useTheme,
@@ -17,6 +18,7 @@ import * as React from 'react';
17
18
  import { Animated, Image, StyleSheet, View } from 'react-native';
18
19
 
19
20
  import type {
21
+ NativeStackDescriptor,
20
22
  NativeStackDescriptorMap,
21
23
  NativeStackNavigationHelpers,
22
24
  } from '../types';
@@ -27,6 +29,10 @@ type Props = {
27
29
  // This is used for the native implementation of the stack.
28
30
  navigation: NativeStackNavigationHelpers;
29
31
  descriptors: NativeStackDescriptorMap;
32
+ describe: (
33
+ route: RouteProp<ParamListBase>,
34
+ placeholder: boolean
35
+ ) => NativeStackDescriptor;
30
36
  };
31
37
 
32
38
  const TRANSPARENT_PRESENTATIONS = [
@@ -34,20 +40,20 @@ const TRANSPARENT_PRESENTATIONS = [
34
40
  'containedTransparentModal',
35
41
  ];
36
42
 
37
- export function NativeStackView({ state, descriptors }: Props) {
43
+ export function NativeStackView({ state, descriptors, describe }: Props) {
38
44
  const parentHeaderBack = React.useContext(HeaderBackContext);
39
45
  const { buildHref } = useLinkBuilder();
40
46
  const { colors } = useTheme();
41
47
 
42
- if (state.preloadedRoutes.length !== 0) {
43
- throw new Error(
44
- 'Preloading routes is not supported in the NativeStackNavigator navigator.'
45
- );
46
- }
48
+ const preloadedDescriptors =
49
+ state.preloadedRoutes.reduce<NativeStackDescriptorMap>((acc, route) => {
50
+ acc[route.key] = acc[route.key] || describe(route, true);
51
+ return acc;
52
+ }, {});
47
53
 
48
54
  return (
49
55
  <SafeAreaProviderCompat style={{ backgroundColor: colors.background }}>
50
- {state.routes.map((route, i) => {
56
+ {state.routes.concat(state.preloadedRoutes).map((route, i) => {
51
57
  const isFocused = state.index === i;
52
58
  const previousKey = state.routes[i - 1]?.key;
53
59
  const nextKey = state.routes[i + 1]?.key;
@@ -55,7 +61,8 @@ export function NativeStackView({ state, descriptors }: Props) {
55
61
  ? descriptors[previousKey]
56
62
  : undefined;
57
63
  const nextDescriptor = nextKey ? descriptors[nextKey] : undefined;
58
- const { options, navigation, render } = descriptors[route.key];
64
+ const { options, navigation, render } =
65
+ descriptors[route.key] ?? preloadedDescriptors[route.key];
59
66
 
60
67
  const headerBack = previousDescriptor
61
68
  ? {
@@ -86,6 +93,10 @@ export function NativeStackView({ state, descriptors }: Props) {
86
93
 
87
94
  const nextPresentation = nextDescriptor?.options.presentation;
88
95
 
96
+ const isPreloaded =
97
+ preloadedDescriptors[route.key] !== undefined &&
98
+ descriptors[route.key] === undefined;
99
+
89
100
  return (
90
101
  <Screen
91
102
  key={route.key}
@@ -146,9 +157,10 @@ export function NativeStackView({ state, descriptors }: Props) {
146
157
  StyleSheet.absoluteFill,
147
158
  {
148
159
  display:
149
- isFocused ||
150
- (nextPresentation != null &&
151
- TRANSPARENT_PRESENTATIONS.includes(nextPresentation))
160
+ (isFocused ||
161
+ (nextPresentation != null &&
162
+ TRANSPARENT_PRESENTATIONS.includes(nextPresentation))) &&
163
+ !isPreloaded
152
164
  ? 'flex'
153
165
  : 'none',
154
166
  },