@react-navigation/native-stack 7.0.0-alpha.2 → 7.0.0-alpha.20

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 (84) hide show
  1. package/lib/commonjs/index.js +7 -0
  2. package/lib/commonjs/index.js.map +1 -1
  3. package/lib/commonjs/navigators/createNativeStackNavigator.js +29 -25
  4. package/lib/commonjs/navigators/createNativeStackNavigator.js.map +1 -1
  5. package/lib/commonjs/types.js.map +1 -1
  6. package/lib/commonjs/utils/getModalRoutesKeys.js +17 -0
  7. package/lib/commonjs/utils/getModalRoutesKeys.js.map +1 -0
  8. package/lib/commonjs/utils/useAnimatedHeaderHeight.js +19 -0
  9. package/lib/commonjs/utils/useAnimatedHeaderHeight.js.map +1 -0
  10. package/lib/commonjs/utils/useDismissedRouteError.js +3 -4
  11. package/lib/commonjs/utils/useDismissedRouteError.js.map +1 -1
  12. package/lib/commonjs/utils/useInvalidPreventRemoveError.js +4 -5
  13. package/lib/commonjs/utils/useInvalidPreventRemoveError.js.map +1 -1
  14. package/lib/commonjs/views/DebugContainer.js +2 -2
  15. package/lib/commonjs/views/DebugContainer.js.map +1 -1
  16. package/lib/commonjs/views/DebugContainer.native.js +19 -7
  17. package/lib/commonjs/views/DebugContainer.native.js.map +1 -1
  18. package/lib/commonjs/views/FontProcessor.js.map +1 -1
  19. package/lib/commonjs/views/FontProcessor.native.js +2 -4
  20. package/lib/commonjs/views/FontProcessor.native.js.map +1 -1
  21. package/lib/commonjs/views/HeaderConfig.js +18 -29
  22. package/lib/commonjs/views/HeaderConfig.js.map +1 -1
  23. package/lib/commonjs/views/NativeStackView.js +27 -17
  24. package/lib/commonjs/views/NativeStackView.js.map +1 -1
  25. package/lib/commonjs/views/NativeStackView.native.js +131 -49
  26. package/lib/commonjs/views/NativeStackView.native.js.map +1 -1
  27. package/lib/module/index.js +5 -0
  28. package/lib/module/index.js.map +1 -1
  29. package/lib/module/navigators/createNativeStackNavigator.js +26 -21
  30. package/lib/module/navigators/createNativeStackNavigator.js.map +1 -1
  31. package/lib/module/types.js.map +1 -1
  32. package/lib/module/utils/getModalRoutesKeys.js +10 -0
  33. package/lib/module/utils/getModalRoutesKeys.js.map +1 -0
  34. package/lib/module/utils/useAnimatedHeaderHeight.js +10 -0
  35. package/lib/module/utils/useAnimatedHeaderHeight.js.map +1 -0
  36. package/lib/module/utils/useDismissedRouteError.js +1 -2
  37. package/lib/module/utils/useDismissedRouteError.js.map +1 -1
  38. package/lib/module/utils/useInvalidPreventRemoveError.js +2 -3
  39. package/lib/module/utils/useInvalidPreventRemoveError.js.map +1 -1
  40. package/lib/module/views/DebugContainer.js.map +1 -1
  41. package/lib/module/views/DebugContainer.native.js +18 -4
  42. package/lib/module/views/DebugContainer.native.js.map +1 -1
  43. package/lib/module/views/FontProcessor.js.map +1 -1
  44. package/lib/module/views/FontProcessor.native.js +2 -4
  45. package/lib/module/views/FontProcessor.native.js.map +1 -1
  46. package/lib/module/views/HeaderConfig.js +18 -29
  47. package/lib/module/views/HeaderConfig.js.map +1 -1
  48. package/lib/module/views/NativeStackView.js +25 -15
  49. package/lib/module/views/NativeStackView.js.map +1 -1
  50. package/lib/module/views/NativeStackView.native.js +130 -48
  51. package/lib/module/views/NativeStackView.native.js.map +1 -1
  52. package/lib/typescript/src/index.d.ts +5 -1
  53. package/lib/typescript/src/index.d.ts.map +1 -1
  54. package/lib/typescript/src/navigators/createNativeStackNavigator.d.ts +14 -8
  55. package/lib/typescript/src/navigators/createNativeStackNavigator.d.ts.map +1 -1
  56. package/lib/typescript/src/types.d.ts +97 -12
  57. package/lib/typescript/src/types.d.ts.map +1 -1
  58. package/lib/typescript/src/utils/getModalRoutesKeys.d.ts +4 -0
  59. package/lib/typescript/src/utils/getModalRoutesKeys.d.ts.map +1 -0
  60. package/lib/typescript/src/utils/useAnimatedHeaderHeight.d.ts +5 -0
  61. package/lib/typescript/src/utils/useAnimatedHeaderHeight.d.ts.map +1 -0
  62. package/lib/typescript/src/views/DebugContainer.d.ts +2 -2
  63. package/lib/typescript/src/views/DebugContainer.d.ts.map +1 -1
  64. package/lib/typescript/src/views/DebugContainer.native.d.ts +7 -2
  65. package/lib/typescript/src/views/DebugContainer.native.d.ts.map +1 -1
  66. package/lib/typescript/src/views/FontProcessor.native.d.ts.map +1 -1
  67. package/lib/typescript/src/views/HeaderConfig.d.ts +2 -2
  68. package/lib/typescript/src/views/HeaderConfig.d.ts.map +1 -1
  69. package/lib/typescript/src/views/NativeStackView.d.ts +3 -2
  70. package/lib/typescript/src/views/NativeStackView.d.ts.map +1 -1
  71. package/lib/typescript/src/views/NativeStackView.native.d.ts +3 -2
  72. package/lib/typescript/src/views/NativeStackView.native.d.ts.map +1 -1
  73. package/package.json +15 -16
  74. package/src/index.tsx +6 -0
  75. package/src/navigators/createNativeStackNavigator.tsx +39 -11
  76. package/src/types.tsx +104 -12
  77. package/src/utils/getModalRoutesKeys.ts +21 -0
  78. package/src/utils/useAnimatedHeaderHeight.tsx +18 -0
  79. package/src/views/DebugContainer.native.tsx +12 -6
  80. package/src/views/DebugContainer.tsx +1 -1
  81. package/src/views/FontProcessor.native.tsx +1 -2
  82. package/src/views/HeaderConfig.tsx +106 -134
  83. package/src/views/NativeStackView.native.tsx +273 -167
  84. package/src/views/NativeStackView.tsx +132 -123
@@ -6,9 +6,11 @@ import {
6
6
  SafeAreaProviderCompat,
7
7
  Screen,
8
8
  } from '@react-navigation/elements';
9
- import type {
10
- ParamListBase,
11
- StackNavigationState,
9
+ import {
10
+ type ParamListBase,
11
+ type StackNavigationState,
12
+ useLinkBuilder,
13
+ useTheme,
12
14
  } from '@react-navigation/native';
13
15
  import * as React from 'react';
14
16
  import { Image, StyleSheet, View } from 'react-native';
@@ -33,81 +35,93 @@ const TRANSPARENT_PRESENTATIONS = [
33
35
 
34
36
  export function NativeStackView({ state, descriptors }: Props) {
35
37
  const parentHeaderBack = React.useContext(HeaderBackContext);
38
+ const { buildHref } = useLinkBuilder();
39
+ const { colors } = useTheme();
40
+
41
+ if (state.preloadedRoutes.length !== 0) {
42
+ throw new Error(
43
+ 'Preloading routes is not supported in the NativeStackNavigator navigator.'
44
+ );
45
+ }
36
46
 
37
47
  return (
38
- <SafeAreaProviderCompat>
39
- <View style={styles.container}>
40
- {state.routes.map((route, i) => {
41
- const isFocused = state.index === i;
42
- const previousKey = state.routes[i - 1]?.key;
43
- const nextKey = state.routes[i + 1]?.key;
44
- const previousDescriptor = previousKey
45
- ? descriptors[previousKey]
46
- : undefined;
47
- const nextDescriptor = nextKey ? descriptors[nextKey] : undefined;
48
- const { options, navigation, render } = descriptors[route.key];
48
+ <SafeAreaProviderCompat style={{ backgroundColor: colors.background }}>
49
+ {state.routes.map((route, i) => {
50
+ const isFocused = state.index === i;
51
+ const previousKey = state.routes[i - 1]?.key;
52
+ const nextKey = state.routes[i + 1]?.key;
53
+ const previousDescriptor = previousKey
54
+ ? descriptors[previousKey]
55
+ : undefined;
56
+ const nextDescriptor = nextKey ? descriptors[nextKey] : undefined;
57
+ const { options, navigation, render } = descriptors[route.key];
49
58
 
50
- const headerBack = previousDescriptor
51
- ? {
52
- title: getHeaderTitle(
53
- previousDescriptor.options,
54
- previousDescriptor.route.name
55
- ),
56
- }
57
- : parentHeaderBack;
59
+ const headerBack = previousDescriptor
60
+ ? {
61
+ title: getHeaderTitle(
62
+ previousDescriptor.options,
63
+ previousDescriptor.route.name
64
+ ),
65
+ href: buildHref(
66
+ previousDescriptor.route.name,
67
+ previousDescriptor.route.params
68
+ ),
69
+ }
70
+ : parentHeaderBack;
58
71
 
59
- const canGoBack = headerBack !== undefined;
72
+ const canGoBack = headerBack !== undefined;
60
73
 
61
- const {
62
- header,
63
- headerShown,
64
- headerTintColor,
65
- headerBackImageSource,
66
- headerLeft,
67
- headerRight,
68
- headerTitle,
69
- headerTitleAlign,
70
- headerTitleStyle,
71
- headerStyle,
72
- headerShadowVisible,
73
- headerTransparent,
74
- headerBackground,
75
- headerBackTitle,
76
- presentation,
77
- contentStyle,
78
- } = options;
74
+ const {
75
+ header,
76
+ headerShown,
77
+ headerTintColor,
78
+ headerBackImageSource,
79
+ headerLeft,
80
+ headerRight,
81
+ headerTitle,
82
+ headerTitleAlign,
83
+ headerTitleStyle,
84
+ headerStyle,
85
+ headerShadowVisible,
86
+ headerTransparent,
87
+ headerBackground,
88
+ headerBackTitle,
89
+ presentation,
90
+ contentStyle,
91
+ } = options;
79
92
 
80
- const nextPresentation = nextDescriptor?.options.presentation;
93
+ const nextPresentation = nextDescriptor?.options.presentation;
81
94
 
82
- return (
83
- <Screen
84
- key={route.key}
85
- focused={isFocused}
86
- route={route}
87
- navigation={navigation}
88
- headerShown={headerShown}
89
- headerTransparent={headerTransparent}
90
- header={
91
- header !== undefined ? (
92
- header({
93
- back: headerBack,
94
- options,
95
- route,
96
- navigation,
97
- })
98
- ) : (
99
- <Header
100
- title={getHeaderTitle(options, route.name)}
101
- headerTintColor={headerTintColor}
102
- headerLeft={
103
- typeof headerLeft === 'function'
104
- ? ({ tintColor }) =>
105
- headerLeft({
106
- tintColor,
107
- canGoBack,
108
- label: headerBackTitle,
109
- })
110
- : headerLeft === undefined && canGoBack
95
+ return (
96
+ <Screen
97
+ key={route.key}
98
+ focused={isFocused}
99
+ route={route}
100
+ navigation={navigation}
101
+ headerShown={headerShown}
102
+ headerTransparent={headerTransparent}
103
+ header={
104
+ header !== undefined ? (
105
+ header({
106
+ back: headerBack,
107
+ options,
108
+ route,
109
+ navigation,
110
+ })
111
+ ) : (
112
+ <Header
113
+ title={getHeaderTitle(options, route.name)}
114
+ headerTintColor={headerTintColor}
115
+ headerLeft={
116
+ typeof headerLeft === 'function'
117
+ ? ({ tintColor }) =>
118
+ headerLeft({
119
+ tintColor,
120
+ canGoBack,
121
+ label: headerBackTitle,
122
+ href: headerBack?.href,
123
+ })
124
+ : headerLeft === undefined && canGoBack
111
125
  ? ({ tintColor }) => (
112
126
  <HeaderBackButton
113
127
  tintColor={tintColor}
@@ -116,6 +130,7 @@ export function NativeStackView({ state, descriptors }: Props) {
116
130
  ? () => (
117
131
  <Image
118
132
  source={headerBackImageSource}
133
+ resizeMode="contain"
119
134
  style={[
120
135
  styles.backImage,
121
136
  { tintColor },
@@ -125,65 +140,60 @@ export function NativeStackView({ state, descriptors }: Props) {
125
140
  : undefined
126
141
  }
127
142
  onPress={navigation.goBack}
128
- canGoBack={canGoBack}
143
+ href={headerBack.href}
129
144
  />
130
145
  )
131
146
  : headerLeft
132
- }
133
- headerRight={
134
- typeof headerRight === 'function'
135
- ? ({ tintColor }) =>
136
- headerRight({ tintColor, canGoBack })
137
- : headerRight
138
- }
139
- headerTitle={
140
- typeof headerTitle === 'function'
141
- ? ({ children, tintColor }) =>
142
- headerTitle({ children, tintColor })
143
- : headerTitle
144
- }
145
- headerTitleAlign={headerTitleAlign}
146
- headerTitleStyle={headerTitleStyle}
147
- headerTransparent={headerTransparent}
148
- headerShadowVisible={headerShadowVisible}
149
- headerBackground={headerBackground}
150
- headerStyle={headerStyle}
151
- />
152
- )
153
- }
154
- style={[
155
- StyleSheet.absoluteFill,
156
- {
157
- display:
158
- isFocused ||
159
- (nextPresentation != null &&
160
- TRANSPARENT_PRESENTATIONS.includes(nextPresentation))
161
- ? 'flex'
162
- : 'none',
163
- },
164
- presentation != null &&
165
- TRANSPARENT_PRESENTATIONS.includes(presentation)
166
- ? { backgroundColor: 'transparent' }
167
- : null,
168
- ]}
169
- >
170
- <HeaderBackContext.Provider value={headerBack}>
171
- <View style={[styles.contentContainer, contentStyle]}>
172
- {render()}
173
- </View>
174
- </HeaderBackContext.Provider>
175
- </Screen>
176
- );
177
- })}
178
- </View>
147
+ }
148
+ headerRight={
149
+ typeof headerRight === 'function'
150
+ ? ({ tintColor }) => headerRight({ tintColor, canGoBack })
151
+ : headerRight
152
+ }
153
+ headerTitle={
154
+ typeof headerTitle === 'function'
155
+ ? ({ children, tintColor }) =>
156
+ headerTitle({ children, tintColor })
157
+ : headerTitle
158
+ }
159
+ headerTitleAlign={headerTitleAlign}
160
+ headerTitleStyle={headerTitleStyle}
161
+ headerTransparent={headerTransparent}
162
+ headerShadowVisible={headerShadowVisible}
163
+ headerBackground={headerBackground}
164
+ headerStyle={headerStyle}
165
+ />
166
+ )
167
+ }
168
+ style={[
169
+ StyleSheet.absoluteFill,
170
+ {
171
+ display:
172
+ isFocused ||
173
+ (nextPresentation != null &&
174
+ TRANSPARENT_PRESENTATIONS.includes(nextPresentation))
175
+ ? 'flex'
176
+ : 'none',
177
+ },
178
+ presentation != null &&
179
+ TRANSPARENT_PRESENTATIONS.includes(presentation)
180
+ ? { backgroundColor: 'transparent' }
181
+ : null,
182
+ ]}
183
+ >
184
+ <HeaderBackContext.Provider value={headerBack}>
185
+ <View style={[styles.contentContainer, contentStyle]}>
186
+ {render()}
187
+ </View>
188
+ </HeaderBackContext.Provider>
189
+ </Screen>
190
+ );
191
+ })}
179
192
  </SafeAreaProviderCompat>
180
193
  );
181
194
  }
182
195
 
183
196
  const styles = StyleSheet.create({
184
- container: {
185
- flex: 1,
186
- },
187
197
  contentContainer: {
188
198
  flex: 1,
189
199
  },
@@ -191,6 +201,5 @@ const styles = StyleSheet.create({
191
201
  height: 24,
192
202
  width: 24,
193
203
  margin: 3,
194
- resizeMode: 'contain',
195
204
  },
196
205
  });