Skip to content

Commit

Permalink
iOS: Introduce vision interfaceIdiom (#42243)
Browse files Browse the repository at this point in the history
Summary:
This PR introduces the `vision` interfaceIdiom to check if the app runs on visionOS.

An update to the documentation should follow this change.

## Changelog:

[IOS] [ADDED] - Introduce `vision` interfaceIdiom

Pull Request resolved: #42243

Test Plan: This change has been used in `react-native-visionos` and the interfaceIdiom changes **only** when running in the non-compatibility mode. But it's still useful to have this upstream if at some point React native would compile to visionOS natively

Reviewed By: cortinico

Differential Revision: D52730028

Pulled By: cipolleschi

fbshipit-source-id: 711c5c2c6c7fe05b3ff8da7383b5e63e9e04acfa
  • Loading branch information
okwasniewski authored and facebook-github-bot committed Jan 16, 2024
1 parent 8211cb8 commit 258d8e5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/react-native/Libraries/Utilities/Platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface PlatformIOSStatic extends PlatformStatic {
OS: 'ios';
isPad: boolean;
isTV: boolean;
isVision: boolean;
isMacCatalyst?: boolean | undefined;
Version: string;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/Libraries/Utilities/Platform.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type IOSPlatform = {
// $FlowFixMe[unsafe-getters-setters]
get isTV(): boolean,
// $FlowFixMe[unsafe-getters-setters]
get isVision(): boolean,
// $FlowFixMe[unsafe-getters-setters]
get isTesting(): boolean,
// $FlowFixMe[unsafe-getters-setters]
get isDisableAnimations(): boolean,
Expand Down
5 changes: 5 additions & 0 deletions packages/react-native/Libraries/Utilities/Platform.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ const Platform: PlatformType = {
return this.constants.interfaceIdiom === 'tv';
},
// $FlowFixMe[unsafe-getters-setters]
get isVision(): boolean {
// $FlowFixMe[object-this-reference]
return this.constants.interfaceIdiom === 'vision';
},
// $FlowFixMe[unsafe-getters-setters]
get isTesting(): boolean {
if (__DEV__) {
// $FlowFixMe[object-this-reference]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9910,6 +9910,7 @@ type IOSPlatform = {
|},
get isPad(): boolean,
get isTV(): boolean,
get isVision(): boolean,
get isTesting(): boolean,
get isDisableAnimations(): boolean,
get isMacCatalyst(): boolean,
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native/React/CoreModules/RCTPlatform.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
return @"tv";
case UIUserInterfaceIdiomCarPlay:
return @"carplay";
#if TARGET_OS_VISION
case UIUserInterfaceIdiomVision:
return @"vision";
#endif
default:
return @"unknown";
}
Expand Down

0 comments on commit 258d8e5

Please sign in to comment.