Skip to content

Commit

Permalink
[visionOS] Implement isVision interfaceIdiom (#2077)
Browse files Browse the repository at this point in the history
* iOS: Introduce `vision` interfaceIdiom (facebook#42243)

Summary:
This PR introduces the `vision` interfaceIdiom to check if the app runs on visionOS.

An update to the documentation should follow this change.

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

Pull Request resolved: facebook#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

* fix: isVision return false for Platform.android.js (facebook#42381)

Summary:
This PR is a follow up for facebook#42243 it looks like we need to return `false` for the Platform.android.js to make flow happy.

This is the error we were getting in `react-native-visionos` CI/CD:
![CleanShot 2024-01-19 at 13 01 19@2x](https://github.com/facebook/react-native/assets/52801365/218078b3-44d4-4dc0-bee7-f5d2e08eca50)

[INTERNAL] [FIXED] - Add `isVision` interface idiom for Platform.android.js

Pull Request resolved: facebook#42381

Test Plan: CI Green

Reviewed By: cortinico

Differential Revision: D52905993

Pulled By: NickGerleman

fbshipit-source-id: 125d33b63e9114cb6276b554e426f32e0c406ea8

* Implement isVision for macOS

---------

Co-authored-by: Oskar Kwaśniewski <oskarkwasniewski@icloud.com>
  • Loading branch information
Saadnajmi and okwasniewski authored Feb 17, 2024
1 parent 3d54a1a commit 2a774a0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/react-native/Libraries/Utilities/Platform.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ const Platform: PlatformType = {
// $FlowFixMe[object-this-reference]
return this.constants.uiMode === 'tv';
},
// $FlowFixMe[unsafe-getters-setters]
get isVision(): boolean {
return false;
},
select: <T>(spec: PlatformSelectSpec<T>): T =>
'android' in spec
? // $FlowFixMe[incompatible-return]
Expand Down
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
4 changes: 4 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 Expand Up @@ -78,6 +80,8 @@ type AndroidPlatform = {
// $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
4 changes: 4 additions & 0 deletions packages/react-native/Libraries/Utilities/Platform.macos.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ const Platform = {
return false;
},
// $FlowFixMe[unsafe-getters-setters]
get isVision(): boolean {
return false;
},
// $FlowFixMe[unsafe-getters-setters]
get isTesting(): boolean {
if (__DEV__) {
// $FlowFixMe[object-this-reference]
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 2a774a0

Please sign in to comment.