Skip to content

Commit

Permalink
fix: ignore changing header title color on visionOS
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski committed Feb 14, 2024
1 parent 7374a89 commit 0081858
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ios/RNSScreenStackHeaderConfig.mm
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ + (void)setAnimatedConfig:(UIViewController *)vc withConfig:(RNSScreenStackHeade
[navbar setTitleTextAttributes:attrs];
}

#if !TARGET_OS_TV
#if !TARGET_OS_T && !TARGET_OS_VISIONV
if (@available(iOS 11.0, *)) {
if (config.largeTitle &&
(config.largeTitleFontFamily || config.largeTitleFontSize || config.largeTitleFontWeight ||
Expand Down Expand Up @@ -397,9 +397,12 @@ + (UINavigationBarAppearance *)buildAppearance:(UIViewController *)vc
if (config.titleFontFamily || config.titleFontSize || config.titleFontWeight || config.titleColor) {
NSMutableDictionary *attrs = [NSMutableDictionary new];

// Ignore changing header title color on visionOS
#if !TARGET_OS_VISION
if (config.titleColor) {
attrs[NSForegroundColorAttributeName] = config.titleColor;
}
#endif

NSString *family = config.titleFontFamily ?: nil;
NSNumber *size = config.titleFontSize ?: @17;
Expand All @@ -422,9 +425,12 @@ + (UINavigationBarAppearance *)buildAppearance:(UIViewController *)vc
config.largeTitleColor || config.titleColor) {
NSMutableDictionary *largeAttrs = [NSMutableDictionary new];

// Ignore changing header title color on visionOS
#if !TARGET_OS_VISION
if (config.largeTitleColor || config.titleColor) {
largeAttrs[NSForegroundColorAttributeName] = config.largeTitleColor ? config.largeTitleColor : config.titleColor;
}
#endif

NSString *largeFamily = config.largeTitleFontFamily ?: nil;
NSNumber *largeSize = config.largeTitleFontSize ?: @34;
Expand Down
10 changes: 10 additions & 0 deletions src/native-stack/views/HeaderConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { NativeStackNavigationOptions } from '../types';
import { useBackPressSubscription } from '../utils/useBackPressSubscription';
import { processFonts } from './FontProcessor';
import warnOnce from 'warn-once';

type Props = NativeStackNavigationOptions & {
route: Route<string>;
Expand Down Expand Up @@ -96,6 +97,15 @@ export default function HeaderConfig({
return searchBar;
}, [searchBar, createSubscription, clearSubscription]);

// @ts-ignore isVision is not yet in the type definitions (RN 0.74+)
const isVisionOS = Platform?.isVision;

warnOnce(
isVisionOS &&
(headerTitleStyle.color !== undefined || headerTintColor === undefined),
'headerTitleStyle.color and headerTintColor are not supported on visionOS.'
);

return (
<ScreenStackHeaderConfig
backButtonInCustomView={backButtonInCustomView}
Expand Down

0 comments on commit 0081858

Please sign in to comment.