@react-navigation/native-stack 7.0.0-alpha.1 → 7.0.0-alpha.11

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 (77) 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 +24 -24
  4. package/lib/commonjs/navigators/createNativeStackNavigator.js.map +1 -1
  5. package/lib/commonjs/types.js.map +1 -1
  6. package/lib/commonjs/utils/useAnimatedHeaderHeight.js +19 -0
  7. package/lib/commonjs/utils/useAnimatedHeaderHeight.js.map +1 -0
  8. package/lib/commonjs/utils/useDismissedRouteError.js +3 -4
  9. package/lib/commonjs/utils/useDismissedRouteError.js.map +1 -1
  10. package/lib/commonjs/utils/useInvalidPreventRemoveError.js +4 -5
  11. package/lib/commonjs/utils/useInvalidPreventRemoveError.js.map +1 -1
  12. package/lib/commonjs/views/DebugContainer.js +2 -2
  13. package/lib/commonjs/views/DebugContainer.js.map +1 -1
  14. package/lib/commonjs/views/DebugContainer.native.js +19 -7
  15. package/lib/commonjs/views/DebugContainer.native.js.map +1 -1
  16. package/lib/commonjs/views/FontProcessor.js.map +1 -1
  17. package/lib/commonjs/views/FontProcessor.native.js +2 -4
  18. package/lib/commonjs/views/FontProcessor.native.js.map +1 -1
  19. package/lib/commonjs/views/HeaderConfig.js +10 -23
  20. package/lib/commonjs/views/HeaderConfig.js.map +1 -1
  21. package/lib/commonjs/views/NativeStackView.js +25 -16
  22. package/lib/commonjs/views/NativeStackView.js.map +1 -1
  23. package/lib/commonjs/views/NativeStackView.native.js +124 -47
  24. package/lib/commonjs/views/NativeStackView.native.js.map +1 -1
  25. package/lib/module/index.js +5 -0
  26. package/lib/module/index.js.map +1 -1
  27. package/lib/module/navigators/createNativeStackNavigator.js +21 -20
  28. package/lib/module/navigators/createNativeStackNavigator.js.map +1 -1
  29. package/lib/module/types.js.map +1 -1
  30. package/lib/module/utils/useAnimatedHeaderHeight.js +10 -0
  31. package/lib/module/utils/useAnimatedHeaderHeight.js.map +1 -0
  32. package/lib/module/utils/useDismissedRouteError.js +1 -2
  33. package/lib/module/utils/useDismissedRouteError.js.map +1 -1
  34. package/lib/module/utils/useInvalidPreventRemoveError.js +2 -3
  35. package/lib/module/utils/useInvalidPreventRemoveError.js.map +1 -1
  36. package/lib/module/views/DebugContainer.js.map +1 -1
  37. package/lib/module/views/DebugContainer.native.js +18 -4
  38. package/lib/module/views/DebugContainer.native.js.map +1 -1
  39. package/lib/module/views/FontProcessor.js.map +1 -1
  40. package/lib/module/views/FontProcessor.native.js +2 -4
  41. package/lib/module/views/FontProcessor.native.js.map +1 -1
  42. package/lib/module/views/HeaderConfig.js +10 -23
  43. package/lib/module/views/HeaderConfig.js.map +1 -1
  44. package/lib/module/views/NativeStackView.js +23 -14
  45. package/lib/module/views/NativeStackView.js.map +1 -1
  46. package/lib/module/views/NativeStackView.native.js +123 -46
  47. package/lib/module/views/NativeStackView.native.js.map +1 -1
  48. package/lib/typescript/src/index.d.ts +4 -0
  49. package/lib/typescript/src/index.d.ts.map +1 -1
  50. package/lib/typescript/src/navigators/createNativeStackNavigator.d.ts +4 -4
  51. package/lib/typescript/src/navigators/createNativeStackNavigator.d.ts.map +1 -1
  52. package/lib/typescript/src/types.d.ts +88 -10
  53. package/lib/typescript/src/types.d.ts.map +1 -1
  54. package/lib/typescript/src/utils/useAnimatedHeaderHeight.d.ts +5 -0
  55. package/lib/typescript/src/utils/useAnimatedHeaderHeight.d.ts.map +1 -0
  56. package/lib/typescript/src/views/DebugContainer.d.ts +2 -2
  57. package/lib/typescript/src/views/DebugContainer.d.ts.map +1 -1
  58. package/lib/typescript/src/views/DebugContainer.native.d.ts +7 -2
  59. package/lib/typescript/src/views/DebugContainer.native.d.ts.map +1 -1
  60. package/lib/typescript/src/views/FontProcessor.native.d.ts.map +1 -1
  61. package/lib/typescript/src/views/HeaderConfig.d.ts +2 -3
  62. package/lib/typescript/src/views/HeaderConfig.d.ts.map +1 -1
  63. package/lib/typescript/src/views/NativeStackView.d.ts +3 -3
  64. package/lib/typescript/src/views/NativeStackView.d.ts.map +1 -1
  65. package/lib/typescript/src/views/NativeStackView.native.d.ts +3 -3
  66. package/lib/typescript/src/views/NativeStackView.native.d.ts.map +1 -1
  67. package/package.json +16 -17
  68. package/src/index.tsx +5 -0
  69. package/src/navigators/createNativeStackNavigator.tsx +9 -5
  70. package/src/types.tsx +88 -11
  71. package/src/utils/useAnimatedHeaderHeight.tsx +18 -0
  72. package/src/views/DebugContainer.native.tsx +12 -6
  73. package/src/views/DebugContainer.tsx +1 -1
  74. package/src/views/FontProcessor.native.tsx +1 -2
  75. package/src/views/HeaderConfig.tsx +101 -131
  76. package/src/views/NativeStackView.native.tsx +264 -166
  77. package/src/views/NativeStackView.tsx +131 -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,92 @@ 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
+ })
123
+ : headerLeft === undefined && canGoBack
111
124
  ? ({ tintColor }) => (
112
125
  <HeaderBackButton
113
126
  tintColor={tintColor}
@@ -116,6 +129,7 @@ export function NativeStackView({ state, descriptors }: Props) {
116
129
  ? () => (
117
130
  <Image
118
131
  source={headerBackImageSource}
132
+ resizeMode="contain"
119
133
  style={[
120
134
  styles.backImage,
121
135
  { tintColor },
@@ -125,65 +139,60 @@ export function NativeStackView({ state, descriptors }: Props) {
125
139
  : undefined
126
140
  }
127
141
  onPress={navigation.goBack}
128
- canGoBack={canGoBack}
142
+ href={headerBack.href}
129
143
  />
130
144
  )
131
145
  : 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>
146
+ }
147
+ headerRight={
148
+ typeof headerRight === 'function'
149
+ ? ({ tintColor }) => headerRight({ tintColor, canGoBack })
150
+ : headerRight
151
+ }
152
+ headerTitle={
153
+ typeof headerTitle === 'function'
154
+ ? ({ children, tintColor }) =>
155
+ headerTitle({ children, tintColor })
156
+ : headerTitle
157
+ }
158
+ headerTitleAlign={headerTitleAlign}
159
+ headerTitleStyle={headerTitleStyle}
160
+ headerTransparent={headerTransparent}
161
+ headerShadowVisible={headerShadowVisible}
162
+ headerBackground={headerBackground}
163
+ headerStyle={headerStyle}
164
+ />
165
+ )
166
+ }
167
+ style={[
168
+ StyleSheet.absoluteFill,
169
+ {
170
+ display:
171
+ isFocused ||
172
+ (nextPresentation != null &&
173
+ TRANSPARENT_PRESENTATIONS.includes(nextPresentation))
174
+ ? 'flex'
175
+ : 'none',
176
+ },
177
+ presentation != null &&
178
+ TRANSPARENT_PRESENTATIONS.includes(presentation)
179
+ ? { backgroundColor: 'transparent' }
180
+ : null,
181
+ ]}
182
+ >
183
+ <HeaderBackContext.Provider value={headerBack}>
184
+ <View style={[styles.contentContainer, contentStyle]}>
185
+ {render()}
186
+ </View>
187
+ </HeaderBackContext.Provider>
188
+ </Screen>
189
+ );
190
+ })}
179
191
  </SafeAreaProviderCompat>
180
192
  );
181
193
  }
182
194
 
183
195
  const styles = StyleSheet.create({
184
- container: {
185
- flex: 1,
186
- },
187
196
  contentContainer: {
188
197
  flex: 1,
189
198
  },
@@ -191,6 +200,5 @@ const styles = StyleSheet.create({
191
200
  height: 24,
192
201
  width: 24,
193
202
  margin: 3,
194
- resizeMode: 'contain',
195
203
  },
196
204
  });