diff --git a/lib/module/views/NativeStackView.native.js b/lib/module/views/NativeStackView.native.js index c342e90bffde9ad5044b6167bdde2e19be219270..4a045490f0650b4a0c821b3e799cf3d18531417f 100644 --- a/lib/module/views/NativeStackView.native.js +++ b/lib/module/views/NativeStackView.native.js @@ -17,8 +17,12 @@ const ANDROID_DEFAULT_HEADER_HEIGHT = 56; function isFabric() { return 'nativeFabricUIManager' in global; } +function SceneNavigationProvider({ presentationEnvelope, ...props }) { + return presentationEnvelope ? props.children : /*#__PURE__*/_jsx(NavigationProvider, props); +} const useNativeDriver = Platform.OS !== 'web'; const SceneView = ({ + presentationEnvelope, index, focused, shouldFreeze, @@ -231,7 +235,8 @@ const SceneView = ({ } } }); - return /*#__PURE__*/_jsx(NavigationProvider, { + return /*#__PURE__*/_jsx(SceneNavigationProvider, { + presentationEnvelope, route: route, navigation: navigation, children: /*#__PURE__*/_jsx(ScreenStackItem, { @@ -353,6 +358,7 @@ const SceneView = ({ }); }; export function NativeStackView({ + presentationEnvelope, state, navigation, descriptors, @@ -370,6 +376,17 @@ export function NativeStackView({ return /*#__PURE__*/_jsx(SafeAreaProviderCompat, { children: /*#__PURE__*/_jsx(ScreenStack, { style: styles.container, + onFinishTransitioning: () => { + // Surface UIKit's transition-completion callback to every route of + // this navigator. Unlike transitionEnd, this also fires when a modal + // finishes dismissing — where the presenting screen below receives no + // appearance callbacks — and for a gesture-driven dismissal it fires + // before the state pop, while the modal route is still the focused + // one, so the event must not be targeted at a single route. + navigation.emit({ + type: 'finishTransitioning' + }); + }, children: state.routes.concat(state.preloadedRoutes).map((route, index) => { const descriptor = descriptors[route.key] ?? preloadedDescriptors[route.key]; const isFocused = state.index === index; @@ -386,6 +403,7 @@ export function NativeStackView({ // due to component being unmounted. To avoid this, we don't freeze the previous screen there const shouldFreeze = isFabric() ? !isPreloaded && !isFocused && !isBelowFocused && !isModalOnIos : !isPreloaded && !isFocused && !isModalOnIos; return /*#__PURE__*/_jsx(SceneView, { + presentationEnvelope, index: index, focused: isFocused, shouldFreeze: shouldFreeze, diff --git a/lib/module/views/useHeaderConfigProps.js b/lib/module/views/useHeaderConfigProps.js index 9c21aa48cb580704aa17e59d9cdadcc612a1e4ff..a1b3a38368c5ef2257570f382e87df5d6f55b11e 100644 --- a/lib/module/views/useHeaderConfigProps.js +++ b/lib/module/views/useHeaderConfigProps.js @@ -19,6 +19,12 @@ const processBarButtonItems = (items, colors, fonts) => { } return item; } + if (item.type === 'mailSearchToolbar' || item.type === 'searchBarPlacement') { + return { + ...item, + index + }; + } if (item.type === 'button' || item.type === 'menu') { if (item.type === 'menu' && item.menu == null) { throw new Error(`Menu item must have a 'menu' property defined: ${JSON.stringify(item)}`); @@ -79,7 +85,7 @@ const processBarButtonItems = (items, colors, fonts) => { } return processedItem; } - throw new Error(`Invalid item type: ${JSON.stringify(item)}. Valid types are 'button', 'menu', 'custom' and 'spacing'.`); + throw new Error(`Invalid item type: ${JSON.stringify(item)}. Valid types are 'button', 'menu', 'custom', 'spacing', 'mailSearchToolbar' and 'searchBarPlacement'.`); }).filter(item => item != null); }; const transformIcon = icon => { @@ -158,8 +164,12 @@ export function useHeaderConfigProps({ headerBack, route, title, + unstable_headerCenterItems: headerCenterItems, unstable_headerLeftItems: headerLeftItems, - unstable_headerRightItems: headerRightItems + unstable_headerRightItems: headerRightItems, + unstable_headerSubtitle: headerSubtitle, + unstable_headerToolbarItems: headerToolbarItems, + unstable_navigationItemStyle: navigationItemStyle }) { const { direction @@ -255,6 +265,10 @@ export function useHeaderConfigProps({ tintColor, canGoBack }); + const centerItems = headerCenterItems?.({ + tintColor, + canGoBack + }); let rightItems = headerRightItems?.({ tintColor, canGoBack @@ -264,6 +278,10 @@ export function useHeaderConfigProps({ // So we need to reverse them here to match the order rightItems = [...rightItems].reverse(); } + const toolbarItems = headerToolbarItems?.({ + tintColor, + canGoBack + }); const children = /*#__PURE__*/_jsxs(_Fragment, { children: [Platform.OS === 'ios' ? /*#__PURE__*/_jsxs(_Fragment, { children: [leftItems ? leftItems.map((item, index) => { @@ -272,13 +290,23 @@ export function useHeaderConfigProps({ // eslint-disable-next-line @eslint-react/no-array-index-key , { hidesSharedBackground: item.hidesSharedBackground, + identifier: item.identifier, children: item.element }, index); } return null; }) : headerLeftElement != null ? /*#__PURE__*/_jsx(ScreenStackHeaderLeftView, { children: headerLeftElement - }) : null, headerTitleElement != null ? /*#__PURE__*/_jsx(ScreenStackHeaderCenterView, { + }) : null, centerItems ? centerItems.map((item, index) => { + if (item.type === 'custom') { + return /*#__PURE__*/_jsx(ScreenStackHeaderCenterView, { + hidesSharedBackground: item.hidesSharedBackground, + identifier: item.identifier, + children: item.element + }, index); + } + return null; + }) : headerTitleElement != null ? /*#__PURE__*/_jsx(ScreenStackHeaderCenterView, { children: headerTitleElement }) : null] }) : /*#__PURE__*/_jsxs(_Fragment, { @@ -321,6 +349,7 @@ export function useHeaderConfigProps({ // eslint-disable-next-line @eslint-react/no-array-index-key , { hidesSharedBackground: item.hidesSharedBackground, + identifier: item.identifier, children: item.element }, index); } @@ -356,6 +385,7 @@ export function useHeaderConfigProps({ largeTitleFontWeight, largeTitleHideShadow: headerLargeTitleShadowVisible === false, title: titleText, + subtitle: headerSubtitle, titleColor, titleFontFamily, titleFontSize, @@ -364,6 +394,9 @@ export function useHeaderConfigProps({ disableTopInsetApplication: !headerTopInsetEnabled, translucent: translucent === true, children, + navigationItemStyle, + headerToolbarItems: processBarButtonItems(toolbarItems, colors, fonts), + headerCenterBarButtonItems: processBarButtonItems(centerItems, colors, fonts), headerLeftBarButtonItems: processBarButtonItems(leftItems, colors, fonts), headerRightBarButtonItems: processBarButtonItems(rightItems, colors, fonts), experimental_userInterfaceStyle: dark ? 'dark' : 'light' diff --git a/lib/typescript/src/types.d.ts b/lib/typescript/src/types.d.ts index 2f1351a89f0f2e67e854dc81e392198326b71834..ccf8556911fa1fa17588f06b56edb2151a712bf0 100644 --- a/lib/typescript/src/types.d.ts +++ b/lib/typescript/src/types.d.ts @@ -1091,6 +1091,13 @@ export type NativeStackHeaderItemSpacing = { */ export type NativeStackHeaderItemCustom = { type: 'custom'; + /** + * An identifier used to match items across transitions. + * Only available from iOS 26.0 and later. + * + * Read more: https://developer.apple.com/documentation/uikit/uibarbuttonitem/identifier + */ + identifier?: string; /** * A React Element to display as the item. */ @@ -864,1 +864,3 @@ sharesBackground?: boolean; + /** Native bar axis preference on iOS 27.1 and later. */ + axisBehavior?: 'automatic' | 'horizontalOnly' | 'verticalPreferred'; diff --git a/src/types.tsx b/src/types.tsx index 7488b1cf20afe36b5c585fbfcd369471fdb6ab8d..f4bd78e48c687024ba84e998fac79e9eb16f1a80 100644 --- a/src/types.tsx +++ b/src/types.tsx @@ -1156,6 +1156,13 @@ export type NativeStackHeaderItemSpacing = { */ export type NativeStackHeaderItemCustom = { type: 'custom'; + /** + * An identifier used to match items across transitions. + * Only available from iOS 26.0 and later. + * + * Read more: https://developer.apple.com/documentation/uikit/uibarbuttonitem/identifier + */ + identifier?: string; /** * A React Element to display as the item. */ @@ -920,1 +920,3 @@ sharesBackground?: boolean; + /** Native bar axis preference on iOS 27.1 and later. */ + axisBehavior?: 'automatic' | 'horizontalOnly' | 'verticalPreferred'; diff --git a/src/views/useHeaderConfigProps.tsx b/src/views/useHeaderConfigProps.tsx index 3f3fff405048b3c2250afbe99dd7f35cecb9a6d5..bb062b898cfa77f8c02f951dc9d81b51672d7d0e 100644 --- a/src/views/useHeaderConfigProps.tsx +++ b/src/views/useHeaderConfigProps.tsx @@ -397,6 +397,7 @@ export function useHeaderConfigProps({ // eslint-disable-next-line @eslint-react/no-array-index-key key={index} hidesSharedBackground={item.hidesSharedBackground} + identifier={item.identifier} > {item.element} @@ -471,6 +472,7 @@ export function useHeaderConfigProps({ // eslint-disable-next-line @eslint-react/no-array-index-key key={index} hidesSharedBackground={item.hidesSharedBackground} + identifier={item.identifier} > {item.element} diff --git a/lib/typescript/src/views/NativeStackView.native.d.ts b/lib/typescript/src/views/NativeStackView.native.d.ts index c0d37db3b4a2a4e9340c76333821f44a87cd624b..eb3db8f511799b335a17edea31a2acd17627f909 100644 --- a/lib/typescript/src/views/NativeStackView.native.d.ts +++ b/lib/typescript/src/views/NativeStackView.native.d.ts @@ -1,11 +1,12 @@ import { type ParamListBase, type RouteProp, type StackNavigationState } from '@react-navigation/native'; import type { NativeStackDescriptor, NativeStackDescriptorMap, NativeStackNavigationHelpers } from '../types.js'; type Props = { + presentationEnvelope?: boolean; state: StackNavigationState; navigation: NativeStackNavigationHelpers; descriptors: NativeStackDescriptorMap; describe: (route: RouteProp, placeholder: boolean) => NativeStackDescriptor; }; -export declare function NativeStackView({ state, navigation, descriptors, describe, }: Props): import("react/jsx-runtime").JSX.Element; +export declare function NativeStackView({ presentationEnvelope, state, navigation, descriptors, describe, }: Props): import("react/jsx-runtime").JSX.Element; export {}; //# sourceMappingURL=NativeStackView.native.d.ts.map \ No newline at end of file diff --git a/src/views/NativeStackView.native.tsx b/src/views/NativeStackView.native.tsx index 416cd90057cea362371a4308dd9985b086c5ccaa..7188a3daf0af2004303b21f89d3c0c7073517ef8 100644 --- a/src/views/NativeStackView.native.tsx +++ b/src/views/NativeStackView.native.tsx @@ -51,7 +51,14 @@ function isFabric() { return 'nativeFabricUIManager' in global; } +// A presentation envelope contains descriptors from its owning navigator. +// Its synthetic route must not override those descriptors' focus state. +function SceneNavigationProvider({ presentationEnvelope, ...props }: React.ComponentProps & { presentationEnvelope?: boolean }) { + return presentationEnvelope ? props.children : ; +} + type SceneViewProps = { + presentationEnvelope?: boolean; index: number; focused: boolean; shouldFreeze: boolean; @@ -74,6 +81,7 @@ type SceneViewProps = { const useNativeDriver = Platform.OS !== 'web'; const SceneView = ({ + presentationEnvelope, index, focused, shouldFreeze, @@ -356,7 +364,7 @@ const SceneView = ({ ); return ( - + - + ); }; type Props = { + presentationEnvelope?: boolean; state: StackNavigationState; navigation: NativeStackNavigationHelpers; descriptors: NativeStackDescriptorMap; @@ -508,6 +517,7 @@ type Props = { }; export function NativeStackView({ + presentationEnvelope, state, navigation, descriptors, @@ -555,6 +565,7 @@ export function NativeStackView({ return ( ; navigation: NativeStackNavigationHelpers; descriptors: NativeStackDescriptorMap; diff --git a/src/views/NativeStackView.tsx b/src/views/NativeStackView.tsx --- a/src/views/NativeStackView.tsx +++ b/src/views/NativeStackView.tsx @@ -24,6 +24,7 @@ import { AnimatedHeaderHeightContext } from '../utils/useAnimatedHeaderHeight'; type Props = { + presentationEnvelope?: boolean; state: StackNavigationState; // This is used for the native implementation of the stack. navigation: NativeStackNavigationHelpers;