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

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

337 lines13.9 KB

1diff --git a/lib/module/views/NativeStackView.native.js b/lib/module/views/NativeStackView.native.js
2index c342e90bffde9ad5044b6167bdde2e19be219270..4a045490f0650b4a0c821b3e799cf3d18531417f 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 = ({
14+ presentationEnvelope,
15 index,
16 focused,
17 shouldFreeze,
18@@ -231,7 +235,8 @@ const 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@@ -353,6 +358,7 @@ const SceneView = ({
29 });
30 };
31 export function NativeStackView({
32+ presentationEnvelope,
33 state,
34 navigation,
35 descriptors,
36@@ -370,6 +376,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@@ -386,6 +403,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 9c21aa48cb580704aa17e59d9cdadcc612a1e4ff..a1b3a38368c5ef2257570f382e87df5d6f55b11e 100644
64--- a/lib/module/views/useHeaderConfigProps.js
65+++ b/lib/module/views/useHeaderConfigProps.js
66@@ -19,6 +19,12 @@ const processBarButtonItems = (items, colors, fonts) => {
67 }
68 return item;
69 }
70+ if (item.type === 'mailSearchToolbar') {
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@@ -79,7 +85,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' and 'mailSearchToolbar'.`);
85 }).filter(item => item != null);
86 };
87 const transformIcon = icon => {
88@@ -158,8 +164,12 @@ export function useHeaderConfigProps({
89 headerBack,
90 route,
91 title,
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@@ -255,6 +265,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@@ -264,6 +278,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@@ -272,13 +290,23 @@ 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 return null;
133 }) : headerLeftElement != null ? /*#__PURE__*/_jsx(ScreenStackHeaderLeftView, {
134 children: headerLeftElement
135- }) : null, headerTitleElement != null ? /*#__PURE__*/_jsx(ScreenStackHeaderCenterView, {
136+ }) : null, centerItems ? centerItems.map((item, index) => {
137+ if (item.type === 'custom') {
138+ return /*#__PURE__*/_jsx(ScreenStackHeaderCenterView, {
139+ hidesSharedBackground: item.hidesSharedBackground,
140+ identifier: item.identifier,
141+ children: item.element
142+ }, index);
143+ }
144+ return null;
145+ }) : headerTitleElement != null ? /*#__PURE__*/_jsx(ScreenStackHeaderCenterView, {
146 children: headerTitleElement
147 }) : null]
148 }) : /*#__PURE__*/_jsxs(_Fragment, {
149@@ -321,6 +349,7 @@ export function useHeaderConfigProps({
150 // eslint-disable-next-line @eslint-react/no-array-index-key
151 , {
152 hidesSharedBackground: item.hidesSharedBackground,
153+ identifier: item.identifier,
154 children: item.element
155 }, index);
156 }
157@@ -356,6 +385,7 @@ export function useHeaderConfigProps({
158 largeTitleFontWeight,
159 largeTitleHideShadow: headerLargeTitleShadowVisible === false,
160 title: titleText,
161+ subtitle: headerSubtitle,
162 titleColor,
163 titleFontFamily,
164 titleFontSize,
165@@ -364,6 +394,9 @@ export function useHeaderConfigProps({
166 disableTopInsetApplication: !headerTopInsetEnabled,
167 translucent: translucent === true,
168 children,
169+ navigationItemStyle,
170+ headerToolbarItems: processBarButtonItems(toolbarItems, colors, fonts),
171+ headerCenterBarButtonItems: processBarButtonItems(centerItems, colors, fonts),
172 headerLeftBarButtonItems: processBarButtonItems(leftItems, colors, fonts),
173 headerRightBarButtonItems: processBarButtonItems(rightItems, colors, fonts),
174 experimental_userInterfaceStyle: dark ? 'dark' : 'light'
175diff --git a/lib/typescript/src/types.d.ts b/lib/typescript/src/types.d.ts
176index 2f1351a89f0f2e67e854dc81e392198326b71834..ccf8556911fa1fa17588f06b56edb2151a712bf0 100644
177--- a/lib/typescript/src/types.d.ts
178+++ b/lib/typescript/src/types.d.ts
179@@ -1091,6 +1091,13 @@ export type NativeStackHeaderItemSpacing = {
180 */
181 export type NativeStackHeaderItemCustom = {
182 type: 'custom';
183+ /**
184+ * An identifier used to match items across transitions.
185+ * Only available from iOS 26.0 and later.
186+ *
187+ * Read more: https://developer.apple.com/documentation/uikit/uibarbuttonitem/identifier
188+ */
189+ identifier?: string;
190 /**
191 * A React Element to display as the item.
192 */
193diff --git a/src/types.tsx b/src/types.tsx
194index 7488b1cf20afe36b5c585fbfcd369471fdb6ab8d..f4bd78e48c687024ba84e998fac79e9eb16f1a80 100644
195--- a/src/types.tsx
196+++ b/src/types.tsx
197@@ -1156,6 +1156,13 @@ export type NativeStackHeaderItemSpacing = {
198 */
199 export type NativeStackHeaderItemCustom = {
200 type: 'custom';
201+ /**
202+ * An identifier used to match items across transitions.
203+ * Only available from iOS 26.0 and later.
204+ *
205+ * Read more: https://developer.apple.com/documentation/uikit/uibarbuttonitem/identifier
206+ */
207+ identifier?: string;
208 /**
209 * A React Element to display as the item.
210 */
211diff --git a/src/views/useHeaderConfigProps.tsx b/src/views/useHeaderConfigProps.tsx
212index 3f3fff405048b3c2250afbe99dd7f35cecb9a6d5..bb062b898cfa77f8c02f951dc9d81b51672d7d0e 100644
213--- a/src/views/useHeaderConfigProps.tsx
214+++ b/src/views/useHeaderConfigProps.tsx
215@@ -397,6 +397,7 @@ export function useHeaderConfigProps({
216 // eslint-disable-next-line @eslint-react/no-array-index-key
217 key={index}
218 hidesSharedBackground={item.hidesSharedBackground}
219+ identifier={item.identifier}
220 >
221 {item.element}
222 </ScreenStackHeaderLeftView>
223@@ -471,6 +472,7 @@ export function useHeaderConfigProps({
224 // eslint-disable-next-line @eslint-react/no-array-index-key
225 key={index}
226 hidesSharedBackground={item.hidesSharedBackground}
227+ identifier={item.identifier}
228 >
229 {item.element}
230 </ScreenStackHeaderRightView>
231diff --git a/lib/typescript/src/views/NativeStackView.native.d.ts b/lib/typescript/src/views/NativeStackView.native.d.ts
232index c0d37db3b4a2a4e9340c76333821f44a87cd624b..eb3db8f511799b335a17edea31a2acd17627f909 100644
233--- a/lib/typescript/src/views/NativeStackView.native.d.ts
234+++ b/lib/typescript/src/views/NativeStackView.native.d.ts
235@@ -1,11 +1,12 @@
236 import { type ParamListBase, type RouteProp, type StackNavigationState } from '@react-navigation/native';
237 import type { NativeStackDescriptor, NativeStackDescriptorMap, NativeStackNavigationHelpers } from '../types.js';
238 type Props = {
239+ presentationEnvelope?: boolean;
240 state: StackNavigationState<ParamListBase>;
241 navigation: NativeStackNavigationHelpers;
242 descriptors: NativeStackDescriptorMap;
243 describe: (route: RouteProp<ParamListBase>, placeholder: boolean) => NativeStackDescriptor;
244 };
245-export declare function NativeStackView({ state, navigation, descriptors, describe, }: Props): import("react/jsx-runtime").JSX.Element;
246+export declare function NativeStackView({ presentationEnvelope, state, navigation, descriptors, describe, }: Props): import("react/jsx-runtime").JSX.Element;
247 export {};
248 //# sourceMappingURL=NativeStackView.native.d.ts.map
249\ No newline at end of file
250diff --git a/src/views/NativeStackView.native.tsx b/src/views/NativeStackView.native.tsx
251index 416cd90057cea362371a4308dd9985b086c5ccaa..7188a3daf0af2004303b21f89d3c0c7073517ef8 100644
252--- a/src/views/NativeStackView.native.tsx
253+++ b/src/views/NativeStackView.native.tsx
254@@ -51,7 +51,14 @@ function isFabric() {
255 return 'nativeFabricUIManager' in global;
256 }
257​
258+// A presentation envelope contains descriptors from its owning navigator.
259+// Its synthetic route must not override those descriptors' focus state.
260+function SceneNavigationProvider({ presentationEnvelope, ...props }: React.ComponentProps<typeof NavigationProvider> & { presentationEnvelope?: boolean }) {
261+ return presentationEnvelope ? props.children : <NavigationProvider {...props} />;
262+}
264 type SceneViewProps = {
265+ presentationEnvelope?: boolean;
266 index: number;
267 focused: boolean;
268 shouldFreeze: boolean;
269@@ -74,6 +81,7 @@ type SceneViewProps = {
270 const useNativeDriver = Platform.OS !== 'web';
271​
272 const SceneView = ({
273+ presentationEnvelope,
274 index,
275 focused,
276 shouldFreeze,
277@@ -356,7 +364,7 @@ const SceneView = ({
278 );
279​
280 return (
281- <NavigationProvider route={route} navigation={navigation}>
282+ <SceneNavigationProvider presentationEnvelope={presentationEnvelope} route={route} navigation={navigation}>
283 <ScreenStackItem
284 screenId={route.key}
285 activityState={isPreloaded ? 0 : 2}
286@@ -493,11 +501,12 @@ const SceneView = ({
287 </HeaderHeightContext.Provider>
288 </AnimatedHeaderHeightContext.Provider>
289 </ScreenStackItem>
290- </NavigationProvider>
291+ </SceneNavigationProvider>
292 );
293 };
294​
295 type Props = {
296+ presentationEnvelope?: boolean;
297 state: StackNavigationState<ParamListBase>;
298 navigation: NativeStackNavigationHelpers;
299 descriptors: NativeStackDescriptorMap;
300@@ -508,6 +517,7 @@ type Props = {
301 };
302​
303 export function NativeStackView({
304+ presentationEnvelope,
305 state,
306 navigation,
307 descriptors,
308@@ -555,6 +565,7 @@ export function NativeStackView({
309​
310 return (
311 <SceneView
312+ presentationEnvelope={presentationEnvelope}
313 key={route.key}
314 index={index}
315 focused={isFocused}
316diff --git a/lib/typescript/src/views/NativeStackView.d.ts b/lib/typescript/src/views/NativeStackView.d.ts
317--- a/lib/typescript/src/views/NativeStackView.d.ts
318+++ b/lib/typescript/src/views/NativeStackView.d.ts
319@@ -1,6 +1,7 @@
320 import { type ParamListBase, type RouteProp, type StackNavigationState } from '@react-navigation/native';
321 import type { NativeStackDescriptor, NativeStackDescriptorMap, NativeStackNavigationHelpers } from '../types.js';
322 type Props = {
323+ presentationEnvelope?: boolean;
324 state: StackNavigationState<ParamListBase>;
325 navigation: NativeStackNavigationHelpers;
326 descriptors: NativeStackDescriptorMap;
327diff --git a/src/views/NativeStackView.tsx b/src/views/NativeStackView.tsx
328--- a/src/views/NativeStackView.tsx
329+++ b/src/views/NativeStackView.tsx
330@@ -24,6 +24,7 @@
331 import { AnimatedHeaderHeightContext } from '../utils/useAnimatedHeaderHeight';
332​
333 type Props = {
334+ presentationEnvelope?: boolean;
335 state: StackNavigationState<ParamListBase>;
336 // This is used for the native implementation of the stack.
337 navigation: NativeStackNavigationHelpers;