@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.
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/navigators/createNativeStackNavigator.js +29 -25
- package/lib/commonjs/navigators/createNativeStackNavigator.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils/getModalRoutesKeys.js +17 -0
- package/lib/commonjs/utils/getModalRoutesKeys.js.map +1 -0
- package/lib/commonjs/utils/useAnimatedHeaderHeight.js +19 -0
- package/lib/commonjs/utils/useAnimatedHeaderHeight.js.map +1 -0
- package/lib/commonjs/utils/useDismissedRouteError.js +3 -4
- package/lib/commonjs/utils/useDismissedRouteError.js.map +1 -1
- package/lib/commonjs/utils/useInvalidPreventRemoveError.js +4 -5
- package/lib/commonjs/utils/useInvalidPreventRemoveError.js.map +1 -1
- package/lib/commonjs/views/DebugContainer.js +2 -2
- package/lib/commonjs/views/DebugContainer.js.map +1 -1
- package/lib/commonjs/views/DebugContainer.native.js +19 -7
- package/lib/commonjs/views/DebugContainer.native.js.map +1 -1
- package/lib/commonjs/views/FontProcessor.js.map +1 -1
- package/lib/commonjs/views/FontProcessor.native.js +2 -4
- package/lib/commonjs/views/FontProcessor.native.js.map +1 -1
- package/lib/commonjs/views/HeaderConfig.js +18 -29
- package/lib/commonjs/views/HeaderConfig.js.map +1 -1
- package/lib/commonjs/views/NativeStackView.js +27 -17
- package/lib/commonjs/views/NativeStackView.js.map +1 -1
- package/lib/commonjs/views/NativeStackView.native.js +131 -49
- package/lib/commonjs/views/NativeStackView.native.js.map +1 -1
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/navigators/createNativeStackNavigator.js +26 -21
- package/lib/module/navigators/createNativeStackNavigator.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/getModalRoutesKeys.js +10 -0
- package/lib/module/utils/getModalRoutesKeys.js.map +1 -0
- package/lib/module/utils/useAnimatedHeaderHeight.js +10 -0
- package/lib/module/utils/useAnimatedHeaderHeight.js.map +1 -0
- package/lib/module/utils/useDismissedRouteError.js +1 -2
- package/lib/module/utils/useDismissedRouteError.js.map +1 -1
- package/lib/module/utils/useInvalidPreventRemoveError.js +2 -3
- package/lib/module/utils/useInvalidPreventRemoveError.js.map +1 -1
- package/lib/module/views/DebugContainer.js.map +1 -1
- package/lib/module/views/DebugContainer.native.js +18 -4
- package/lib/module/views/DebugContainer.native.js.map +1 -1
- package/lib/module/views/FontProcessor.js.map +1 -1
- package/lib/module/views/FontProcessor.native.js +2 -4
- package/lib/module/views/FontProcessor.native.js.map +1 -1
- package/lib/module/views/HeaderConfig.js +18 -29
- package/lib/module/views/HeaderConfig.js.map +1 -1
- package/lib/module/views/NativeStackView.js +25 -15
- package/lib/module/views/NativeStackView.js.map +1 -1
- package/lib/module/views/NativeStackView.native.js +130 -48
- package/lib/module/views/NativeStackView.native.js.map +1 -1
- package/lib/typescript/src/index.d.ts +5 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/navigators/createNativeStackNavigator.d.ts +14 -8
- package/lib/typescript/src/navigators/createNativeStackNavigator.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +97 -12
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils/getModalRoutesKeys.d.ts +4 -0
- package/lib/typescript/src/utils/getModalRoutesKeys.d.ts.map +1 -0
- package/lib/typescript/src/utils/useAnimatedHeaderHeight.d.ts +5 -0
- package/lib/typescript/src/utils/useAnimatedHeaderHeight.d.ts.map +1 -0
- package/lib/typescript/src/views/DebugContainer.d.ts +2 -2
- package/lib/typescript/src/views/DebugContainer.d.ts.map +1 -1
- package/lib/typescript/src/views/DebugContainer.native.d.ts +7 -2
- package/lib/typescript/src/views/DebugContainer.native.d.ts.map +1 -1
- package/lib/typescript/src/views/FontProcessor.native.d.ts.map +1 -1
- package/lib/typescript/src/views/HeaderConfig.d.ts +2 -2
- package/lib/typescript/src/views/HeaderConfig.d.ts.map +1 -1
- package/lib/typescript/src/views/NativeStackView.d.ts +3 -2
- package/lib/typescript/src/views/NativeStackView.d.ts.map +1 -1
- package/lib/typescript/src/views/NativeStackView.native.d.ts +3 -2
- package/lib/typescript/src/views/NativeStackView.native.d.ts.map +1 -1
- package/package.json +15 -16
- package/src/index.tsx +6 -0
- package/src/navigators/createNativeStackNavigator.tsx +39 -11
- package/src/types.tsx +104 -12
- package/src/utils/getModalRoutesKeys.ts +21 -0
- package/src/utils/useAnimatedHeaderHeight.tsx +18 -0
- package/src/views/DebugContainer.native.tsx +12 -6
- package/src/views/DebugContainer.tsx +1 -1
- package/src/views/FontProcessor.native.tsx +1 -2
- package/src/views/HeaderConfig.tsx +106 -134
- package/src/views/NativeStackView.native.tsx +273 -167
- 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
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
72
|
+
const canGoBack = headerBack !== undefined;
|
|
60
73
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
93
|
+
const nextPresentation = nextDescriptor?.options.presentation;
|
|
81
94
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
143
|
+
href={headerBack.href}
|
|
129
144
|
/>
|
|
130
145
|
)
|
|
131
146
|
: headerLeft
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
headerTitle
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
(nextPresentation
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
>
|
|
170
|
-
<
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
});
|