@react-navigation/native-stack 7.0.0-alpha.9 → 7.0.0-rc.0
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.map +1 -1
- package/lib/commonjs/navigators/createNativeStackNavigator.js +19 -16
- package/lib/commonjs/navigators/createNativeStackNavigator.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils/debounce.js +16 -0
- package/lib/commonjs/utils/debounce.js.map +1 -0
- package/lib/commonjs/utils/getModalRoutesKeys.js +17 -0
- package/lib/commonjs/utils/getModalRoutesKeys.js.map +1 -0
- package/lib/commonjs/utils/useAnimatedHeaderHeight.js +1 -1
- package/lib/commonjs/utils/useAnimatedHeaderHeight.js.map +1 -1
- package/lib/commonjs/utils/useDismissedRouteError.js +1 -1
- package/lib/commonjs/utils/useDismissedRouteError.js.map +1 -1
- package/lib/commonjs/utils/useInvalidPreventRemoveError.js +1 -1
- package/lib/commonjs/utils/useInvalidPreventRemoveError.js.map +1 -1
- package/lib/commonjs/views/DebugContainer.js +1 -1
- package/lib/commonjs/views/DebugContainer.js.map +1 -1
- package/lib/commonjs/views/DebugContainer.native.js +3 -3
- 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 +1 -1
- package/lib/commonjs/views/FontProcessor.native.js.map +1 -1
- package/lib/commonjs/views/HeaderConfig.js +41 -39
- package/lib/commonjs/views/HeaderConfig.js.map +1 -1
- package/lib/commonjs/views/NativeStackView.js +47 -57
- package/lib/commonjs/views/NativeStackView.js.map +1 -1
- package/lib/commonjs/views/NativeStackView.native.js +110 -54
- package/lib/commonjs/views/NativeStackView.native.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/navigators/createNativeStackNavigator.js +17 -14
- package/lib/module/navigators/createNativeStackNavigator.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/debounce.js +10 -0
- package/lib/module/utils/debounce.js.map +1 -0
- package/lib/module/utils/getModalRoutesKeys.js +10 -0
- package/lib/module/utils/getModalRoutesKeys.js.map +1 -0
- package/lib/module/utils/useAnimatedHeaderHeight.js.map +1 -1
- package/lib/module/utils/useDismissedRouteError.js.map +1 -1
- 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 +1 -1
- 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.map +1 -1
- package/lib/module/views/HeaderConfig.js +40 -38
- package/lib/module/views/HeaderConfig.js.map +1 -1
- package/lib/module/views/NativeStackView.js +47 -57
- package/lib/module/views/NativeStackView.js.map +1 -1
- package/lib/module/views/NativeStackView.native.js +109 -53
- package/lib/module/views/NativeStackView.native.js.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/navigators/createNativeStackNavigator.d.ts +13 -8
- package/lib/typescript/src/navigators/createNativeStackNavigator.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +16 -4
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils/debounce.d.ts +2 -0
- package/lib/typescript/src/utils/debounce.d.ts.map +1 -0
- 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 +2 -2
- package/lib/typescript/src/utils/useAnimatedHeaderHeight.d.ts.map +1 -1
- package/lib/typescript/src/views/HeaderConfig.d.ts.map +1 -1
- package/lib/typescript/src/views/NativeStackView.d.ts.map +1 -1
- package/lib/typescript/src/views/NativeStackView.native.d.ts +1 -1
- package/lib/typescript/src/views/NativeStackView.native.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/index.tsx +1 -0
- package/src/navigators/createNativeStackNavigator.tsx +30 -6
- package/src/types.tsx +23 -2
- package/src/utils/debounce.tsx +14 -0
- package/src/utils/getModalRoutesKeys.ts +21 -0
- package/src/utils/useAnimatedHeaderHeight.tsx +1 -1
- package/src/views/HeaderConfig.tsx +12 -5
- package/src/views/NativeStackView.native.tsx +180 -101
- package/src/views/NativeStackView.tsx +141 -144
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
type ParamListBase,
|
|
11
11
|
type StackNavigationState,
|
|
12
12
|
useLinkBuilder,
|
|
13
|
+
useTheme,
|
|
13
14
|
} from '@react-navigation/native';
|
|
14
15
|
import * as React from 'react';
|
|
15
16
|
import { Image, StyleSheet, View } from 'react-native';
|
|
@@ -35,6 +36,7 @@ const TRANSPARENT_PRESENTATIONS = [
|
|
|
35
36
|
export function NativeStackView({ state, descriptors }: Props) {
|
|
36
37
|
const parentHeaderBack = React.useContext(HeaderBackContext);
|
|
37
38
|
const { buildHref } = useLinkBuilder();
|
|
39
|
+
const { colors } = useTheme();
|
|
38
40
|
|
|
39
41
|
if (state.preloadedRoutes.length !== 0) {
|
|
40
42
|
throw new Error(
|
|
@@ -43,160 +45,155 @@ export function NativeStackView({ state, descriptors }: Props) {
|
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
return (
|
|
46
|
-
<SafeAreaProviderCompat>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
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];
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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;
|
|
70
71
|
|
|
71
|
-
|
|
72
|
+
const canGoBack = headerBack !== undefined;
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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;
|
|
91
92
|
|
|
92
|
-
|
|
93
|
+
const nextPresentation = nextDescriptor?.options.presentation;
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
</View>
|
|
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
|
|
125
|
+
? ({ tintColor }) => (
|
|
126
|
+
<HeaderBackButton
|
|
127
|
+
tintColor={tintColor}
|
|
128
|
+
backImage={
|
|
129
|
+
headerBackImageSource !== undefined
|
|
130
|
+
? () => (
|
|
131
|
+
<Image
|
|
132
|
+
source={headerBackImageSource}
|
|
133
|
+
resizeMode="contain"
|
|
134
|
+
style={[
|
|
135
|
+
styles.backImage,
|
|
136
|
+
{ tintColor },
|
|
137
|
+
]}
|
|
138
|
+
/>
|
|
139
|
+
)
|
|
140
|
+
: undefined
|
|
141
|
+
}
|
|
142
|
+
onPress={navigation.goBack}
|
|
143
|
+
href={headerBack.href}
|
|
144
|
+
/>
|
|
145
|
+
)
|
|
146
|
+
: headerLeft
|
|
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
|
+
})}
|
|
192
192
|
</SafeAreaProviderCompat>
|
|
193
193
|
);
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
const styles = StyleSheet.create({
|
|
197
|
-
container: {
|
|
198
|
-
flex: 1,
|
|
199
|
-
},
|
|
200
197
|
contentContainer: {
|
|
201
198
|
flex: 1,
|
|
202
199
|
},
|