Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

@react-navigation%2Fnative-stack@7.21.0.patch

358 lines14.8 KB

1diff --git a/lib/module/views/NativeStackView.native.js b/lib/module/views/NativeStackView.native.js
2index 6882090..011ad0e 100644
3--- a/lib/module/views/NativeStackView.native.js
4+++ b/lib/module/views/NativeStackView.native.js
5@@ -17,8 +17,12 @@ const ANDROID_DEFAULT_HEADER_HEIGHT = 56;
6 function isFabric() {
7 return 'nativeFabricUIManager' in global;
8 }
9+function SceneNavigationProvider({ presentationEnvelope, ...props }) {
10+ return presentationEnvelope ? props.children : /*#__PURE__*/_jsx(NavigationProvider, props);
11+}
12 const useNativeDriver = Platform.OS !== 'web';
13 const SceneView = /*#__PURE__*/React.memo(function SceneView({
14+ presentationEnvelope,
15 index,
16 focused,
17 shouldFreeze,
18@@ -305,7 +309,8 @@ const SceneView = /*#__PURE__*/React.memo(function SceneView({
19 }
20 }
21 });
22- return /*#__PURE__*/_jsx(NavigationProvider, {
23+ return /*#__PURE__*/_jsx(SceneNavigationProvider, {
24+ presentationEnvelope,
25 route: route,
26 navigation: navigation,
27 children: /*#__PURE__*/_jsx(ScreenStackItem, {
28@@ -427,6 +432,7 @@ const SceneView = /*#__PURE__*/React.memo(function SceneView({
29 });
30 });
31 export function NativeStackView({
32+ presentationEnvelope,
33 state,
34 navigation,
35 descriptors,
36@@ -444,6 +450,17 @@ export function NativeStackView({
37 return /*#__PURE__*/_jsx(SafeAreaProviderCompat, {
38 children: /*#__PURE__*/_jsx(ScreenStack, {
39 style: styles.container,
40+ onFinishTransitioning: () => {
41+ // Surface UIKit's transition-completion callback to every route of
42+ // this navigator. Unlike transitionEnd, this also fires when a modal
43+ // finishes dismissing — where the presenting screen below receives no
44+ // appearance callbacks — and for a gesture-driven dismissal it fires
45+ // before the state pop, while the modal route is still the focused
46+ // one, so the event must not be targeted at a single route.
47+ navigation.emit({
48+ type: 'finishTransitioning'
49+ });
50+ },
51 children: state.routes.concat(state.preloadedRoutes).map((route, index) => {
52 const descriptor = descriptors[route.key] ?? preloadedDescriptors[route.key];
53 const isFocused = state.index === index;
54@@ -460,6 +477,7 @@ export function NativeStackView({
55 // due to component being unmounted. To avoid this, we don't freeze the previous screen there
56 const shouldFreeze = isFabric() ? !isPreloaded && !isFocused && !isBelowFocused && !isModalOnIos : !isPreloaded && !isFocused && !isModalOnIos;
57 return /*#__PURE__*/_jsx(SceneView, {
58+ presentationEnvelope,
59 index: index,
60 focused: isFocused,
61 shouldFreeze: shouldFreeze,
62diff --git a/lib/module/views/useHeaderConfigProps.js b/lib/module/views/useHeaderConfigProps.js
63index 08055b2..8718847 100644
64--- a/lib/module/views/useHeaderConfigProps.js
65+++ b/lib/module/views/useHeaderConfigProps.js
66@@ -18,6 +18,12 @@ const processBarButtonItems = (items, colors, fonts) => {
67 }
68 return item;
69 }
70+ if (item.type === 'mailSearchToolbar' || item.type === 'searchBarPlacement') {
71+ return {
72+ ...item,
73+ index
74+ };
75+ }
76 if (item.type === 'button' || item.type === 'menu') {
77 if (item.type === 'menu' && item.menu == null) {
78 throw new Error(`Menu item must have a 'menu' property defined: ${JSON.stringify(item)}`);
79@@ -81,7 +87,7 @@ const processBarButtonItems = (items, colors, fonts) => {
80 }
81 return processedItem;
82 }
83- throw new Error(`Invalid item type: ${JSON.stringify(item)}. Valid types are 'button', 'menu', 'custom' and 'spacing'.`);
84+ throw new Error(`Invalid item type: ${JSON.stringify(item)}. Valid types are 'button', 'menu', 'custom', 'spacing', 'mailSearchToolbar' and 'searchBarPlacement'.`);
85 }).filter(item => item != null);
86 };
87 const transformIcon = icon => {
88@@ -165,8 +171,12 @@ export function useHeaderConfigProps({
89 route,
90 title,
91 unstable_headerInsets: headerInsets,
92+ unstable_headerCenterItems: headerCenterItems,
93 unstable_headerLeftItems: headerLeftItems,
94- unstable_headerRightItems: headerRightItems
95+ unstable_headerRightItems: headerRightItems,
96+ unstable_headerSubtitle: headerSubtitle,
97+ unstable_headerToolbarItems: headerToolbarItems,
98+ unstable_navigationItemStyle: navigationItemStyle
99 }) {
100 const {
101 direction
102@@ -264,6 +274,10 @@ export function useHeaderConfigProps({
103 tintColor,
104 canGoBack
105 });
106+ const centerItems = headerCenterItems?.({
107+ tintColor,
108+ canGoBack
109+ });
110 let rightItems = headerRightItems?.({
111 tintColor,
112 canGoBack
113@@ -273,6 +287,10 @@ export function useHeaderConfigProps({
114 // So we need to reverse them here to match the order
115 rightItems = [...rightItems].reverse();
116 }
117+ const toolbarItems = headerToolbarItems?.({
118+ tintColor,
119+ canGoBack
120+ });
121 const children = /*#__PURE__*/_jsxs(_Fragment, {
122 children: [Platform.OS === 'ios' ? /*#__PURE__*/_jsxs(_Fragment, {
123 children: [leftItems ? leftItems.map((item, index) => {
124@@ -281,6 +299,7 @@ export function useHeaderConfigProps({
125 // eslint-disable-next-line @eslint-react/no-array-index-key
126 , {
127 hidesSharedBackground: item.hidesSharedBackground,
128+ identifier: item.identifier,
129 children: item.element
130 }, index);
131 }
132@@ -288,7 +307,16 @@ export function useHeaderConfigProps({
133 }) : headerLeftElement != null ? /*#__PURE__*/_jsx(ScreenStackHeaderLeftView, {
134 hidesSharedBackground: headerLeftBackgroundVisible === false,
135 children: headerLeftElement
136- }) : null, headerTitleElement != null ? /*#__PURE__*/_jsx(ScreenStackHeaderCenterView, {
137+ }) : null, centerItems?.length ? centerItems.map((item, index) => {
138+ if (item.type === 'custom') {
139+ return /*#__PURE__*/_jsx(ScreenStackHeaderCenterView, {
140+ hidesSharedBackground: item.hidesSharedBackground,
141+ identifier: item.identifier,
142+ children: item.element
143+ }, index);
144+ }
145+ return null;
146+ }) : headerTitleElement != null ? /*#__PURE__*/_jsx(ScreenStackHeaderCenterView, {
147 children: headerTitleElement
148 }) : null]
149 }) : /*#__PURE__*/_jsxs(_Fragment, {
150@@ -331,6 +359,7 @@ export function useHeaderConfigProps({
151 // eslint-disable-next-line @eslint-react/no-array-index-key
152 , {
153 hidesSharedBackground: item.hidesSharedBackground,
154+ identifier: item.identifier,
155 children: item.element
156 }, index);
157 }
158@@ -367,6 +396,7 @@ export function useHeaderConfigProps({
159 largeTitleFontWeight,
160 largeTitleHideShadow: headerLargeTitleShadowVisible === false,
161 title: titleText,
162+ subtitle: headerSubtitle,
163 titleColor,
164 titleFontFamily,
165 titleFontSize,
166@@ -378,6 +408,9 @@ export function useHeaderConfigProps({
167 disableBottomInsetApplication: headerInsets?.bottom !== undefined ? !headerInsets.bottom : undefined,
168 translucent: translucent === true,
169 children,
170+ navigationItemStyle,
171+ headerToolbarItems: processBarButtonItems(toolbarItems, colors, fonts),
172+ headerCenterBarButtonItems: processBarButtonItems(centerItems, colors, fonts),
173 headerLeftBarButtonItems: processBarButtonItems(leftItems, colors, fonts),
174 headerRightBarButtonItems: processBarButtonItems(rightItems, colors, fonts),
175 experimental_userInterfaceStyle: dark ? 'dark' : 'light'
176diff --git a/lib/typescript/src/types.d.ts b/lib/typescript/src/types.d.ts
177index 27a3d8e..3adf86e 100644
178--- a/lib/typescript/src/types.d.ts
179+++ b/lib/typescript/src/types.d.ts
180@@ -903,6 +903,8 @@ type SharedHeaderItem = {
181 * Read more: https://developer.apple.com/documentation/uikit/uibarbuttonitem/sharesbackground
182 */
183 sharesBackground?: boolean;
184+ /** Native bar axis preference on iOS 27.1 and later. */
185+ axisBehavior?: 'automatic' | 'horizontalOnly' | 'verticalPreferred';
186 /**
187 * An identifier used to match items across transitions.
188 * Only available from iOS 26.0 and later.
189@@ -1148,6 +1150,13 @@ export type NativeStackHeaderItemSpacing = {
190 */
191 export type NativeStackHeaderItemCustom = {
192 type: 'custom';
193+ /**
194+ * An identifier used to match items across transitions.
195+ * Only available from iOS 26.0 and later.
196+ *
197+ * Read more: https://developer.apple.com/documentation/uikit/uibarbuttonitem/identifier
198+ */
199+ identifier?: string;
200 /**
201 * A React Element to display as the item.
202 */
203diff --git a/lib/typescript/src/views/NativeStackView.d.ts b/lib/typescript/src/views/NativeStackView.d.ts
204index cc688e2..0ec33c8 100644
205--- a/lib/typescript/src/views/NativeStackView.d.ts
206+++ b/lib/typescript/src/views/NativeStackView.d.ts
207@@ -2,6 +2,7 @@ import { type ParamListBase, type RouteProp, type StackNavigationState } from '@
208 import * as React from 'react';
209 import type { NativeStackDescriptor, NativeStackDescriptorMap, NativeStackNavigationHelpers } from '../types.js';
210 type Props = {
211+ presentationEnvelope?: boolean;
212 state: StackNavigationState<ParamListBase>;
213 navigation: NativeStackNavigationHelpers;
214 descriptors: NativeStackDescriptorMap;
215diff --git a/lib/typescript/src/views/NativeStackView.native.d.ts b/lib/typescript/src/views/NativeStackView.native.d.ts
216index d533cd9..857b7ad 100644
217--- a/lib/typescript/src/views/NativeStackView.native.d.ts
218+++ b/lib/typescript/src/views/NativeStackView.native.d.ts
219@@ -2,11 +2,12 @@ import { type ParamListBase, type RouteProp, type StackNavigationState } from '@
220 import * as React from 'react';
221 import type { NativeStackDescriptor, NativeStackDescriptorMap, NativeStackNavigationHelpers } from '../types.js';
222 type Props = {
223+ presentationEnvelope?: boolean;
224 state: StackNavigationState<ParamListBase>;
225 navigation: NativeStackNavigationHelpers;
226 descriptors: NativeStackDescriptorMap;
227 describe: (route: RouteProp<ParamListBase>, placeholder: boolean) => NativeStackDescriptor;
228 };
229-export declare function NativeStackView({ state, navigation, descriptors, describe, }: Props): React.JSX.Element;
230+export declare function NativeStackView({ presentationEnvelope, state, navigation, descriptors, describe, }: Props): React.JSX.Element;
231 export {};
232 //# sourceMappingURL=NativeStackView.native.d.ts.map
233\ No newline at end of file
234diff --git a/src/types.tsx b/src/types.tsx
235index 5d63f41..e9c53ee 100644
236--- a/src/types.tsx
237+++ b/src/types.tsx
238@@ -959,6 +959,8 @@ type SharedHeaderItem = {
239 * Read more: https://developer.apple.com/documentation/uikit/uibarbuttonitem/sharesbackground
240 */
241 sharesBackground?: boolean;
242+ /** Native bar axis preference on iOS 27.1 and later. */
243+ axisBehavior?: 'automatic' | 'horizontalOnly' | 'verticalPreferred';
244 /**
245 * An identifier used to match items across transitions.
246 * Only available from iOS 26.0 and later.
247@@ -1213,6 +1215,13 @@ export type NativeStackHeaderItemSpacing = {
248 */
249 export type NativeStackHeaderItemCustom = {
250 type: 'custom';
251+ /**
252+ * An identifier used to match items across transitions.
253+ * Only available from iOS 26.0 and later.
254+ *
255+ * Read more: https://developer.apple.com/documentation/uikit/uibarbuttonitem/identifier
256+ */
257+ identifier?: string;
258 /**
259 * A React Element to display as the item.
260 */
261diff --git a/src/views/NativeStackView.native.tsx b/src/views/NativeStackView.native.tsx
262index aa13bc7..ab4a9d1 100644
263--- a/src/views/NativeStackView.native.tsx
264+++ b/src/views/NativeStackView.native.tsx
265@@ -52,7 +52,14 @@ function isFabric() {
266 return 'nativeFabricUIManager' in global;
267 }
269+// A presentation envelope contains descriptors from its owning navigator.
270+// Its synthetic route must not override those descriptors' focus state.
271+function SceneNavigationProvider({ presentationEnvelope, ...props }: React.ComponentProps<typeof NavigationProvider> & { presentationEnvelope?: boolean }) {
272+ return presentationEnvelope ? props.children : <NavigationProvider {...props} />;
273+}
275 type SceneViewProps = {
276+ presentationEnvelope?: boolean;
277 index: number;
278 focused: boolean;
279 shouldFreeze: boolean;
280@@ -71,6 +78,7 @@ type SceneViewProps = {
281 const useNativeDriver = Platform.OS !== 'web';
283 const SceneView = React.memo(function SceneView({
284+ presentationEnvelope,
285 index,
286 focused,
287 shouldFreeze,
288@@ -434,7 +442,7 @@ const SceneView = React.memo(function SceneView({
289 );
291 return (
292- <NavigationProvider route={route} navigation={navigation}>
293+ <SceneNavigationProvider presentationEnvelope={presentationEnvelope} route={route} navigation={navigation}>
294 <ScreenStackItem
295 screenId={route.key}
296 activityState={isPreloaded ? 0 : 2}
297@@ -571,11 +579,12 @@ const SceneView = React.memo(function SceneView({
298 </HeaderHeightContext.Provider>
299 </AnimatedHeaderHeightContext.Provider>
300 </ScreenStackItem>
301- </NavigationProvider>
302+ </SceneNavigationProvider>
303 );
304 });
306 type Props = {
307+ presentationEnvelope?: boolean;
308 state: StackNavigationState<ParamListBase>;
309 navigation: NativeStackNavigationHelpers;
310 descriptors: NativeStackDescriptorMap;
311@@ -586,6 +595,7 @@ type Props = {
312 };
314 export function NativeStackView({
315+ presentationEnvelope,
316 state,
317 navigation,
318 descriptors,
319@@ -633,6 +643,7 @@ export function NativeStackView({
321 return (
322 <SceneView
323+ presentationEnvelope={presentationEnvelope}
324 key={route.key}
325 index={index}
326 focused={isFocused}
327diff --git a/src/views/NativeStackView.tsx b/src/views/NativeStackView.tsx
328index c50a3fa..6305ed5 100644
329--- a/src/views/NativeStackView.tsx
330+++ b/src/views/NativeStackView.tsx
331@@ -25,6 +25,7 @@ import type {
332 import { AnimatedHeaderHeightContext } from '../utils/useAnimatedHeaderHeight';
334 type Props = {
335+ presentationEnvelope?: boolean;
336 state: StackNavigationState<ParamListBase>;
337 // This is used for the native implementation of the stack.
338 navigation: NativeStackNavigationHelpers;
339diff --git a/src/views/useHeaderConfigProps.tsx b/src/views/useHeaderConfigProps.tsx
340index 739134e..9bb056e 100644
341--- a/src/views/useHeaderConfigProps.tsx
342+++ b/src/views/useHeaderConfigProps.tsx
343@@ -412,6 +412,7 @@ export function useHeaderConfigProps({
344 // eslint-disable-next-line @eslint-react/no-array-index-key
345 key={index}
346 hidesSharedBackground={item.hidesSharedBackground}
347+ identifier={item.identifier}
348 >
349 {item.element}
350 </ScreenStackHeaderLeftView>
351@@ -488,6 +489,7 @@ export function useHeaderConfigProps({
352 // eslint-disable-next-line @eslint-react/no-array-index-key
353 key={index}
354 hidesSharedBackground={item.hidesSharedBackground}
355+ identifier={item.identifier}
356 >
357 {item.element}
358 </ScreenStackHeaderRightView>