Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add visionOS support #2025

Merged
merged 6 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
okwasniewski marked this conversation as resolved.
Show resolved Hide resolved
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
Loading