@react-navigation/native-stack 6.2.2 → 6.3.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 +8 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/navigators/createNativeStackNavigator.js +12 -10
- package/lib/commonjs/navigators/createNativeStackNavigator.js.map +1 -1
- package/lib/commonjs/views/HeaderConfig.js +56 -38
- package/lib/commonjs/views/HeaderConfig.js.map +1 -1
- package/lib/commonjs/views/NativeStackView.js +62 -40
- package/lib/commonjs/views/NativeStackView.js.map +1 -1
- package/lib/commonjs/views/NativeStackView.native.js +51 -40
- 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 +12 -10
- package/lib/module/navigators/createNativeStackNavigator.js.map +1 -1
- package/lib/module/views/HeaderConfig.js +55 -37
- package/lib/module/views/HeaderConfig.js.map +1 -1
- package/lib/module/views/NativeStackView.js +61 -40
- package/lib/module/views/NativeStackView.js.map +1 -1
- package/lib/module/views/NativeStackView.native.js +53 -42
- package/lib/module/views/NativeStackView.native.js.map +1 -1
- package/lib/typescript/src/index.d.ts +5 -1
- package/lib/typescript/src/types.d.ts +14 -8
- package/lib/typescript/src/views/HeaderConfig.d.ts +2 -1
- package/package.json +6 -6
- package/src/index.tsx +6 -0
- package/src/navigators/createNativeStackNavigator.tsx +21 -18
- package/src/types.tsx +15 -6
- package/src/views/HeaderConfig.tsx +135 -98
- package/src/views/NativeStackView.native.tsx +61 -47
- package/src/views/NativeStackView.tsx +25 -3
package/src/types.tsx
CHANGED
|
@@ -85,20 +85,23 @@ export type NativeStackHeaderProps = {
|
|
|
85
85
|
navigation: NativeStackNavigationProp<ParamListBase>;
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
export type
|
|
88
|
+
export type HeaderButtonProps = {
|
|
89
89
|
/**
|
|
90
90
|
* Tint color for the header.
|
|
91
91
|
*/
|
|
92
92
|
tintColor?: string;
|
|
93
|
+
/**
|
|
94
|
+
* Whether it's possible to navigate back in stack.
|
|
95
|
+
*/
|
|
96
|
+
canGoBack: boolean;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export type HeaderBackButtonProps = HeaderButtonProps & {
|
|
93
100
|
/**
|
|
94
101
|
* Label text for the button. Usually the title of the previous screen.
|
|
95
102
|
* By default, this is only shown on iOS.
|
|
96
103
|
*/
|
|
97
104
|
label?: string;
|
|
98
|
-
/**
|
|
99
|
-
* Whether it's possible to navigate back in stack.
|
|
100
|
-
*/
|
|
101
|
-
canGoBack: boolean;
|
|
102
105
|
};
|
|
103
106
|
|
|
104
107
|
export type NativeStackNavigationOptions = {
|
|
@@ -245,6 +248,12 @@ export type NativeStackNavigationOptions = {
|
|
|
245
248
|
* Tint color for the header. Changes the color of back button and title.
|
|
246
249
|
*/
|
|
247
250
|
headerTintColor?: string;
|
|
251
|
+
/**
|
|
252
|
+
* Function which returns a React Element to render as the background of the header.
|
|
253
|
+
* This is useful for using backgrounds such as an image, a gradient, blur effect etc.
|
|
254
|
+
* You can use this with `headerTransparent` to render content underneath a translucent header.
|
|
255
|
+
*/
|
|
256
|
+
headerBackground?: () => React.ReactNode;
|
|
248
257
|
/**
|
|
249
258
|
* Function which returns a React Element to display on the left side of the header.
|
|
250
259
|
* This replaces the back button. See `headerBackVisible` to show the back button along side left element.
|
|
@@ -253,7 +262,7 @@ export type NativeStackNavigationOptions = {
|
|
|
253
262
|
/**
|
|
254
263
|
* Function which returns a React Element to display on the right side of the header.
|
|
255
264
|
*/
|
|
256
|
-
headerRight?: (props:
|
|
265
|
+
headerRight?: (props: HeaderButtonProps) => React.ReactNode;
|
|
257
266
|
/**
|
|
258
267
|
* String or a function that returns a React Element to be used by the header.
|
|
259
268
|
* Defaults to screen `title` or route name.
|
|
@@ -23,11 +23,13 @@ import type { NativeStackNavigationOptions } from '../types';
|
|
|
23
23
|
import { processFonts } from './FontProcessor';
|
|
24
24
|
|
|
25
25
|
type Props = NativeStackNavigationOptions & {
|
|
26
|
+
headerHeight: number;
|
|
26
27
|
route: Route<string>;
|
|
27
28
|
canGoBack: boolean;
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
export default function HeaderConfig({
|
|
32
|
+
headerHeight,
|
|
31
33
|
headerBackImageSource,
|
|
32
34
|
headerBackButtonMenuEnabled,
|
|
33
35
|
headerBackTitle,
|
|
@@ -39,6 +41,7 @@ export default function HeaderConfig({
|
|
|
39
41
|
headerLargeTitle,
|
|
40
42
|
headerLargeTitleShadowVisible,
|
|
41
43
|
headerLargeTitleStyle,
|
|
44
|
+
headerBackground,
|
|
42
45
|
headerLeft,
|
|
43
46
|
headerRight,
|
|
44
47
|
headerShown,
|
|
@@ -55,6 +58,7 @@ export default function HeaderConfig({
|
|
|
55
58
|
canGoBack,
|
|
56
59
|
}: Props): JSX.Element {
|
|
57
60
|
const insets = useSafeAreaInsets();
|
|
61
|
+
|
|
58
62
|
const { colors } = useTheme();
|
|
59
63
|
const tintColor =
|
|
60
64
|
headerTintColor ?? (Platform.OS === 'ios' ? colors.primary : colors.text);
|
|
@@ -96,10 +100,13 @@ export default function HeaderConfig({
|
|
|
96
100
|
|
|
97
101
|
const headerLeftElement = headerLeft?.({
|
|
98
102
|
tintColor,
|
|
103
|
+
canGoBack,
|
|
99
104
|
label: headerBackTitle,
|
|
105
|
+
});
|
|
106
|
+
const headerRightElement = headerRight?.({
|
|
107
|
+
tintColor,
|
|
100
108
|
canGoBack,
|
|
101
109
|
});
|
|
102
|
-
const headerRightElement = headerRight?.({ tintColor });
|
|
103
110
|
const headerTitleElement =
|
|
104
111
|
typeof headerTitle === 'function'
|
|
105
112
|
? headerTitle({ tintColor, children: titleText })
|
|
@@ -125,104 +132,124 @@ export default function HeaderConfig({
|
|
|
125
132
|
: Platform.OS === 'android' && headerTitleElement != null;
|
|
126
133
|
|
|
127
134
|
return (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
direction={I18nManager.isRTL ? 'rtl' : 'ltr'}
|
|
140
|
-
disableBackButtonMenu={headerBackButtonMenuEnabled === false}
|
|
141
|
-
hidden={headerShown === false}
|
|
142
|
-
hideBackButton={headerBackVisible === false}
|
|
143
|
-
hideShadow={headerShadowVisible === false}
|
|
144
|
-
largeTitle={headerLargeTitle}
|
|
145
|
-
largeTitleBackgroundColor={headerLargeStyleFlattened.backgroundColor}
|
|
146
|
-
largeTitleColor={headerLargeTitleStyleFlattened.color}
|
|
147
|
-
largeTitleFontFamily={largeTitleFontFamily}
|
|
148
|
-
largeTitleFontSize={headerLargeTitleStyleFlattened.fontSize}
|
|
149
|
-
largeTitleFontWeight={headerLargeTitleStyleFlattened.fontWeight}
|
|
150
|
-
largeTitleHideShadow={headerLargeTitleShadowVisible === false}
|
|
151
|
-
title={typeof headerTitle === 'string' ? headerTitle : titleText}
|
|
152
|
-
titleColor={titleColor}
|
|
153
|
-
titleFontFamily={titleFontFamily}
|
|
154
|
-
titleFontSize={titleFontSize}
|
|
155
|
-
titleFontWeight={titleFontWeight}
|
|
156
|
-
topInsetEnabled={insets.top !== 0}
|
|
157
|
-
translucent={
|
|
158
|
-
// This defaults to `true`, so we can't pass `undefined`
|
|
159
|
-
headerTransparent === true
|
|
160
|
-
}
|
|
161
|
-
>
|
|
162
|
-
{Platform.OS === 'ios' ? (
|
|
163
|
-
<>
|
|
164
|
-
{headerLeftElement != null ? (
|
|
165
|
-
<ScreenStackHeaderLeftView>
|
|
166
|
-
{headerLeftElement}
|
|
167
|
-
</ScreenStackHeaderLeftView>
|
|
168
|
-
) : null}
|
|
169
|
-
{headerTitleElement != null ? (
|
|
170
|
-
<ScreenStackHeaderCenterView>
|
|
171
|
-
{headerTitleElement}
|
|
172
|
-
</ScreenStackHeaderCenterView>
|
|
173
|
-
) : null}
|
|
174
|
-
</>
|
|
175
|
-
) : (
|
|
176
|
-
<>
|
|
177
|
-
{headerLeftElement != null || typeof headerTitle === 'function' ? (
|
|
178
|
-
<ScreenStackHeaderLeftView>
|
|
179
|
-
<View style={styles.row}>
|
|
180
|
-
{headerLeftElement}
|
|
181
|
-
{headerTitleAlign !== 'center' ? (
|
|
182
|
-
typeof headerTitle === 'function' ? (
|
|
183
|
-
headerTitleElement
|
|
184
|
-
) : (
|
|
185
|
-
<HeaderTitle
|
|
186
|
-
tintColor={tintColor}
|
|
187
|
-
style={headerTitleStyleSupported}
|
|
188
|
-
>
|
|
189
|
-
{titleText}
|
|
190
|
-
</HeaderTitle>
|
|
191
|
-
)
|
|
192
|
-
) : null}
|
|
193
|
-
</View>
|
|
194
|
-
</ScreenStackHeaderLeftView>
|
|
195
|
-
) : null}
|
|
196
|
-
{headerTitleAlign === 'center' ? (
|
|
197
|
-
<ScreenStackHeaderCenterView>
|
|
198
|
-
{typeof headerTitle === 'function' ? (
|
|
199
|
-
headerTitleElement
|
|
200
|
-
) : (
|
|
201
|
-
<HeaderTitle
|
|
202
|
-
tintColor={tintColor}
|
|
203
|
-
style={headerTitleStyleSupported}
|
|
204
|
-
>
|
|
205
|
-
{titleText}
|
|
206
|
-
</HeaderTitle>
|
|
207
|
-
)}
|
|
208
|
-
</ScreenStackHeaderCenterView>
|
|
209
|
-
) : null}
|
|
210
|
-
</>
|
|
211
|
-
)}
|
|
212
|
-
{headerBackImageSource !== undefined ? (
|
|
213
|
-
<ScreenStackHeaderBackButtonImage source={headerBackImageSource} />
|
|
135
|
+
<>
|
|
136
|
+
{headerBackground != null ? (
|
|
137
|
+
<View
|
|
138
|
+
style={[
|
|
139
|
+
styles.background,
|
|
140
|
+
headerTransparent ? styles.translucent : null,
|
|
141
|
+
{ height: headerHeight },
|
|
142
|
+
]}
|
|
143
|
+
>
|
|
144
|
+
{headerBackground()}
|
|
145
|
+
</View>
|
|
214
146
|
) : null}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
147
|
+
<ScreenStackHeaderConfig
|
|
148
|
+
backButtonInCustomView={backButtonInCustomView}
|
|
149
|
+
backgroundColor={
|
|
150
|
+
headerStyleFlattened.backgroundColor ??
|
|
151
|
+
(headerBackground != null || headerTransparent
|
|
152
|
+
? 'transparent'
|
|
153
|
+
: colors.card)
|
|
154
|
+
}
|
|
155
|
+
backTitle={headerBackTitleVisible ? headerBackTitle : ' '}
|
|
156
|
+
backTitleFontFamily={backTitleFontFamily}
|
|
157
|
+
backTitleFontSize={headerBackTitleStyleFlattened.fontSize}
|
|
158
|
+
blurEffect={headerBlurEffect}
|
|
159
|
+
color={tintColor}
|
|
160
|
+
direction={I18nManager.isRTL ? 'rtl' : 'ltr'}
|
|
161
|
+
disableBackButtonMenu={headerBackButtonMenuEnabled === false}
|
|
162
|
+
hidden={headerShown === false}
|
|
163
|
+
hideBackButton={headerBackVisible === false}
|
|
164
|
+
hideShadow={
|
|
165
|
+
headerShadowVisible === false ||
|
|
166
|
+
headerBackground != null ||
|
|
167
|
+
headerTransparent
|
|
168
|
+
}
|
|
169
|
+
largeTitle={headerLargeTitle}
|
|
170
|
+
largeTitleBackgroundColor={headerLargeStyleFlattened.backgroundColor}
|
|
171
|
+
largeTitleColor={headerLargeTitleStyleFlattened.color}
|
|
172
|
+
largeTitleFontFamily={largeTitleFontFamily}
|
|
173
|
+
largeTitleFontSize={headerLargeTitleStyleFlattened.fontSize}
|
|
174
|
+
largeTitleFontWeight={headerLargeTitleStyleFlattened.fontWeight}
|
|
175
|
+
largeTitleHideShadow={headerLargeTitleShadowVisible === false}
|
|
176
|
+
title={typeof headerTitle === 'string' ? headerTitle : titleText}
|
|
177
|
+
titleColor={titleColor}
|
|
178
|
+
titleFontFamily={titleFontFamily}
|
|
179
|
+
titleFontSize={titleFontSize}
|
|
180
|
+
titleFontWeight={titleFontWeight}
|
|
181
|
+
topInsetEnabled={insets.top !== 0}
|
|
182
|
+
translucent={
|
|
183
|
+
headerBackground != null ||
|
|
184
|
+
// This defaults to `true`, so we can't pass `undefined`
|
|
185
|
+
headerTransparent === true
|
|
186
|
+
}
|
|
187
|
+
>
|
|
188
|
+
{Platform.OS === 'ios' ? (
|
|
189
|
+
<>
|
|
190
|
+
{headerLeftElement != null ? (
|
|
191
|
+
<ScreenStackHeaderLeftView>
|
|
192
|
+
{headerLeftElement}
|
|
193
|
+
</ScreenStackHeaderLeftView>
|
|
194
|
+
) : null}
|
|
195
|
+
{headerTitleElement != null ? (
|
|
196
|
+
<ScreenStackHeaderCenterView>
|
|
197
|
+
{headerTitleElement}
|
|
198
|
+
</ScreenStackHeaderCenterView>
|
|
199
|
+
) : null}
|
|
200
|
+
</>
|
|
201
|
+
) : (
|
|
202
|
+
<>
|
|
203
|
+
{headerLeftElement != null || typeof headerTitle === 'function' ? (
|
|
204
|
+
<ScreenStackHeaderLeftView>
|
|
205
|
+
<View style={styles.row}>
|
|
206
|
+
{headerLeftElement}
|
|
207
|
+
{headerTitleAlign !== 'center' ? (
|
|
208
|
+
typeof headerTitle === 'function' ? (
|
|
209
|
+
headerTitleElement
|
|
210
|
+
) : (
|
|
211
|
+
<HeaderTitle
|
|
212
|
+
tintColor={tintColor}
|
|
213
|
+
style={headerTitleStyleSupported}
|
|
214
|
+
>
|
|
215
|
+
{titleText}
|
|
216
|
+
</HeaderTitle>
|
|
217
|
+
)
|
|
218
|
+
) : null}
|
|
219
|
+
</View>
|
|
220
|
+
</ScreenStackHeaderLeftView>
|
|
221
|
+
) : null}
|
|
222
|
+
{headerTitleAlign === 'center' ? (
|
|
223
|
+
<ScreenStackHeaderCenterView>
|
|
224
|
+
{typeof headerTitle === 'function' ? (
|
|
225
|
+
headerTitleElement
|
|
226
|
+
) : (
|
|
227
|
+
<HeaderTitle
|
|
228
|
+
tintColor={tintColor}
|
|
229
|
+
style={headerTitleStyleSupported}
|
|
230
|
+
>
|
|
231
|
+
{titleText}
|
|
232
|
+
</HeaderTitle>
|
|
233
|
+
)}
|
|
234
|
+
</ScreenStackHeaderCenterView>
|
|
235
|
+
) : null}
|
|
236
|
+
</>
|
|
237
|
+
)}
|
|
238
|
+
{headerBackImageSource !== undefined ? (
|
|
239
|
+
<ScreenStackHeaderBackButtonImage source={headerBackImageSource} />
|
|
240
|
+
) : null}
|
|
241
|
+
{headerRightElement != null ? (
|
|
242
|
+
<ScreenStackHeaderRightView>
|
|
243
|
+
{headerRightElement}
|
|
244
|
+
</ScreenStackHeaderRightView>
|
|
245
|
+
) : null}
|
|
246
|
+
{Platform.OS === 'ios' && headerSearchBarOptions != null ? (
|
|
247
|
+
<ScreenStackHeaderSearchBarView>
|
|
248
|
+
<SearchBar {...headerSearchBarOptions} />
|
|
249
|
+
</ScreenStackHeaderSearchBarView>
|
|
250
|
+
) : null}
|
|
251
|
+
</ScreenStackHeaderConfig>
|
|
252
|
+
</>
|
|
226
253
|
);
|
|
227
254
|
}
|
|
228
255
|
|
|
@@ -231,4 +258,14 @@ const styles = StyleSheet.create({
|
|
|
231
258
|
flexDirection: 'row',
|
|
232
259
|
alignItems: 'center',
|
|
233
260
|
},
|
|
261
|
+
translucent: {
|
|
262
|
+
position: 'absolute',
|
|
263
|
+
top: 0,
|
|
264
|
+
left: 0,
|
|
265
|
+
right: 0,
|
|
266
|
+
zIndex: 1,
|
|
267
|
+
},
|
|
268
|
+
background: {
|
|
269
|
+
overflow: 'hidden',
|
|
270
|
+
},
|
|
234
271
|
});
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
SafeAreaProviderCompat,
|
|
7
7
|
} from '@react-navigation/elements';
|
|
8
8
|
import {
|
|
9
|
+
NavigationContext,
|
|
10
|
+
NavigationRouteContext,
|
|
9
11
|
ParamListBase,
|
|
10
12
|
Route,
|
|
11
13
|
StackActions,
|
|
@@ -13,7 +15,7 @@ import {
|
|
|
13
15
|
useTheme,
|
|
14
16
|
} from '@react-navigation/native';
|
|
15
17
|
import * as React from 'react';
|
|
16
|
-
import { Platform,
|
|
18
|
+
import { Platform, StyleSheet, View } from 'react-native';
|
|
17
19
|
import {
|
|
18
20
|
useSafeAreaFrame,
|
|
19
21
|
useSafeAreaInsets,
|
|
@@ -40,11 +42,13 @@ const MaybeNestedStack = ({
|
|
|
40
42
|
options,
|
|
41
43
|
route,
|
|
42
44
|
presentation,
|
|
45
|
+
headerHeight,
|
|
43
46
|
children,
|
|
44
47
|
}: {
|
|
45
48
|
options: NativeStackNavigationOptions;
|
|
46
49
|
route: Route<string>;
|
|
47
50
|
presentation: Exclude<StackPresentationTypes, 'push'> | 'card';
|
|
51
|
+
headerHeight: number;
|
|
48
52
|
children: React.ReactNode;
|
|
49
53
|
}) => {
|
|
50
54
|
const { colors } = useTheme();
|
|
@@ -83,33 +87,17 @@ const MaybeNestedStack = ({
|
|
|
83
87
|
</DebugContainer>
|
|
84
88
|
);
|
|
85
89
|
|
|
86
|
-
const insets = useSafeAreaInsets();
|
|
87
|
-
const dimensions = useSafeAreaFrame();
|
|
88
|
-
// landscape is meaningful only for iPhone
|
|
89
|
-
const isLandscape =
|
|
90
|
-
dimensions.width > dimensions.height &&
|
|
91
|
-
!(Platform as PlatformIOSStatic).isPad &&
|
|
92
|
-
!(Platform as PlatformIOSStatic).isTVOS;
|
|
93
|
-
// `modal` and `formSheet` presentations do not take whole screen, so should not take the inset.
|
|
94
|
-
const isFullScreenModal =
|
|
95
|
-
presentation !== 'modal' && presentation !== 'formSheet';
|
|
96
|
-
const topInset = isFullScreenModal && !isLandscape ? insets.top : 0;
|
|
97
|
-
const headerHeight = getDefaultHeaderHeight(
|
|
98
|
-
dimensions,
|
|
99
|
-
!isFullScreenModal,
|
|
100
|
-
topInset
|
|
101
|
-
);
|
|
102
|
-
|
|
103
90
|
if (isHeaderInModal) {
|
|
104
91
|
return (
|
|
105
92
|
<ScreenStack style={styles.container}>
|
|
106
93
|
<Screen enabled style={StyleSheet.absoluteFill}>
|
|
107
|
-
<
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
94
|
+
<HeaderConfig
|
|
95
|
+
{...options}
|
|
96
|
+
route={route}
|
|
97
|
+
headerHeight={headerHeight}
|
|
98
|
+
canGoBack
|
|
99
|
+
/>
|
|
100
|
+
{content}
|
|
113
101
|
</Screen>
|
|
114
102
|
</ScreenStack>
|
|
115
103
|
);
|
|
@@ -142,7 +130,7 @@ const SceneView = ({
|
|
|
142
130
|
gestureEnabled,
|
|
143
131
|
header,
|
|
144
132
|
headerShown,
|
|
145
|
-
animationTypeForReplace = '
|
|
133
|
+
animationTypeForReplace = 'push',
|
|
146
134
|
animation,
|
|
147
135
|
orientation,
|
|
148
136
|
statusBarAnimation,
|
|
@@ -162,14 +150,28 @@ const SceneView = ({
|
|
|
162
150
|
? headerShown
|
|
163
151
|
: presentation === 'card' && headerShown !== false;
|
|
164
152
|
|
|
165
|
-
const isParentHeaderShown = React.useContext(HeaderShownContext);
|
|
166
153
|
const insets = useSafeAreaInsets();
|
|
154
|
+
const frame = useSafeAreaFrame();
|
|
155
|
+
|
|
156
|
+
// `modal` and `formSheet` presentations do not take whole screen, so should not take the inset.
|
|
157
|
+
const isModal = presentation === 'modal' || presentation === 'formSheet';
|
|
158
|
+
|
|
159
|
+
// Modals are fullscreen in landscape only on iPhone
|
|
160
|
+
const isIPhone =
|
|
161
|
+
Platform.OS === 'ios' && !(Platform.isPad && Platform.isTVOS);
|
|
162
|
+
const isLandscape = frame.width > frame.height;
|
|
163
|
+
|
|
164
|
+
const topInset = isModal || (isIPhone && isLandscape) ? 0 : insets.top;
|
|
165
|
+
|
|
166
|
+
const isParentHeaderShown = React.useContext(HeaderShownContext);
|
|
167
167
|
const parentHeaderHeight = React.useContext(HeaderHeightContext);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
168
|
+
|
|
169
|
+
const defaultHeaderHeight = getDefaultHeaderHeight(frame, isModal, topInset);
|
|
170
|
+
|
|
171
|
+
const [customHeaderHeight, setCustomHeaderHeight] =
|
|
172
|
+
React.useState(defaultHeaderHeight);
|
|
173
|
+
|
|
174
|
+
const headerHeight = header ? customHeaderHeight : defaultHeaderHeight;
|
|
173
175
|
|
|
174
176
|
return (
|
|
175
177
|
<Screen
|
|
@@ -204,25 +206,35 @@ const SceneView = ({
|
|
|
204
206
|
}
|
|
205
207
|
>
|
|
206
208
|
{header !== undefined && headerShown !== false ? (
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
209
|
+
<NavigationContext.Provider value={navigation}>
|
|
210
|
+
<NavigationRouteContext.Provider value={route}>
|
|
211
|
+
<View
|
|
212
|
+
onLayout={(e) => {
|
|
213
|
+
setCustomHeaderHeight(e.nativeEvent.layout.height);
|
|
214
|
+
}}
|
|
215
|
+
>
|
|
216
|
+
{header({
|
|
217
|
+
back: previousDescriptor
|
|
218
|
+
? {
|
|
219
|
+
title: getHeaderTitle(
|
|
220
|
+
previousDescriptor.options,
|
|
221
|
+
previousDescriptor.route.name
|
|
222
|
+
),
|
|
223
|
+
}
|
|
224
|
+
: undefined,
|
|
225
|
+
options,
|
|
226
|
+
route,
|
|
227
|
+
navigation,
|
|
228
|
+
})}
|
|
229
|
+
</View>
|
|
230
|
+
</NavigationRouteContext.Provider>
|
|
231
|
+
</NavigationContext.Provider>
|
|
221
232
|
) : (
|
|
222
233
|
<HeaderConfig
|
|
223
234
|
{...options}
|
|
224
235
|
route={route}
|
|
225
236
|
headerShown={isHeaderInPush}
|
|
237
|
+
headerHeight={headerHeight}
|
|
226
238
|
canGoBack={index !== 0}
|
|
227
239
|
/>
|
|
228
240
|
)}
|
|
@@ -230,6 +242,7 @@ const SceneView = ({
|
|
|
230
242
|
options={options}
|
|
231
243
|
route={route}
|
|
232
244
|
presentation={presentation}
|
|
245
|
+
headerHeight={headerHeight}
|
|
233
246
|
>
|
|
234
247
|
{render()}
|
|
235
248
|
</MaybeNestedStack>
|
|
@@ -246,8 +259,9 @@ type Props = {
|
|
|
246
259
|
};
|
|
247
260
|
|
|
248
261
|
function NativeStackViewInner({ state, navigation, descriptors }: Props) {
|
|
249
|
-
const [nextDismissedKey, setNextDismissedKey] =
|
|
250
|
-
|
|
262
|
+
const [nextDismissedKey, setNextDismissedKey] = React.useState<string | null>(
|
|
263
|
+
null
|
|
264
|
+
);
|
|
251
265
|
|
|
252
266
|
const dismissedRouteName = nextDismissedKey
|
|
253
267
|
? state.routes.find((route) => route.key === nextDismissedKey)?.name
|
|
@@ -25,6 +25,11 @@ type Props = {
|
|
|
25
25
|
descriptors: NativeStackDescriptorMap;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
+
const TRANSPARENT_PRESENTATIONS = [
|
|
29
|
+
'transparentModal',
|
|
30
|
+
'containedTransparentModal',
|
|
31
|
+
];
|
|
32
|
+
|
|
28
33
|
export default function NativeStackView({ state, descriptors }: Props) {
|
|
29
34
|
return (
|
|
30
35
|
<SafeAreaProviderCompat>
|
|
@@ -33,9 +38,11 @@ export default function NativeStackView({ state, descriptors }: Props) {
|
|
|
33
38
|
const isFocused = state.index === i;
|
|
34
39
|
const canGoBack = i !== 0;
|
|
35
40
|
const previousKey = state.routes[i - 1]?.key;
|
|
41
|
+
const nextKey = state.routes[i + 1]?.key;
|
|
36
42
|
const previousDescriptor = previousKey
|
|
37
43
|
? descriptors[previousKey]
|
|
38
44
|
: undefined;
|
|
45
|
+
const nexDescriptor = nextKey ? descriptors[nextKey] : undefined;
|
|
39
46
|
const { options, navigation, render } = descriptors[route.key];
|
|
40
47
|
|
|
41
48
|
const {
|
|
@@ -51,10 +58,13 @@ export default function NativeStackView({ state, descriptors }: Props) {
|
|
|
51
58
|
headerStyle,
|
|
52
59
|
headerShadowVisible,
|
|
53
60
|
headerTransparent,
|
|
54
|
-
contentStyle,
|
|
55
61
|
headerBackTitle,
|
|
62
|
+
presentation,
|
|
63
|
+
contentStyle,
|
|
56
64
|
} = options;
|
|
57
65
|
|
|
66
|
+
const nextPresentation = nexDescriptor?.options.presentation;
|
|
67
|
+
|
|
58
68
|
return (
|
|
59
69
|
<Screen
|
|
60
70
|
key={route.key}
|
|
@@ -115,7 +125,8 @@ export default function NativeStackView({ state, descriptors }: Props) {
|
|
|
115
125
|
}
|
|
116
126
|
headerRight={
|
|
117
127
|
typeof headerRight === 'function'
|
|
118
|
-
? ({ tintColor }) =>
|
|
128
|
+
? ({ tintColor }) =>
|
|
129
|
+
headerRight({ tintColor, canGoBack })
|
|
119
130
|
: headerRight
|
|
120
131
|
}
|
|
121
132
|
headerTitle={
|
|
@@ -143,7 +154,18 @@ export default function NativeStackView({ state, descriptors }: Props) {
|
|
|
143
154
|
}
|
|
144
155
|
style={[
|
|
145
156
|
StyleSheet.absoluteFill,
|
|
146
|
-
{
|
|
157
|
+
{
|
|
158
|
+
display:
|
|
159
|
+
isFocused ||
|
|
160
|
+
(nextPresentation != null &&
|
|
161
|
+
TRANSPARENT_PRESENTATIONS.includes(nextPresentation))
|
|
162
|
+
? 'flex'
|
|
163
|
+
: 'none',
|
|
164
|
+
},
|
|
165
|
+
presentation != null &&
|
|
166
|
+
TRANSPARENT_PRESENTATIONS.includes(presentation)
|
|
167
|
+
? { backgroundColor: 'transparent' }
|
|
168
|
+
: null,
|
|
147
169
|
]}
|
|
148
170
|
>
|
|
149
171
|
<View style={[styles.contentContainer, contentStyle]}>
|