From 258d8e51b451b221e557dad4647cbd210fe37392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwas=CC=81niewski?= Date: Tue, 16 Jan 2024 10:41:03 -0800 Subject: [PATCH] iOS: Introduce `vision` interfaceIdiom (#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. ## Changelog: [IOS] [ADDED] - Introduce `vision` interfaceIdiom Pull Request resolved: https://github.com/facebook/react-native/pull/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 --- packages/react-native/Libraries/Utilities/Platform.d.ts | 1 + packages/react-native/Libraries/Utilities/Platform.flow.js | 2 ++ packages/react-native/Libraries/Utilities/Platform.ios.js | 5 +++++ .../__tests__/__snapshots__/public-api-test.js.snap | 1 + packages/react-native/React/CoreModules/RCTPlatform.mm | 4 ++++ 5 files changed, 13 insertions(+) diff --git a/packages/react-native/Libraries/Utilities/Platform.d.ts b/packages/react-native/Libraries/Utilities/Platform.d.ts index e80241e807d934..82246df0ffb4b0 100644 --- a/packages/react-native/Libraries/Utilities/Platform.d.ts +++ b/packages/react-native/Libraries/Utilities/Platform.d.ts @@ -55,6 +55,7 @@ interface PlatformIOSStatic extends PlatformStatic { OS: 'ios'; isPad: boolean; isTV: boolean; + isVision: boolean; isMacCatalyst?: boolean | undefined; Version: string; } diff --git a/packages/react-native/Libraries/Utilities/Platform.flow.js b/packages/react-native/Libraries/Utilities/Platform.flow.js index b0c23b4fe77cc5..cb5e56871aad2f 100644 --- a/packages/react-native/Libraries/Utilities/Platform.flow.js +++ b/packages/react-native/Libraries/Utilities/Platform.flow.js @@ -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, diff --git a/packages/react-native/Libraries/Utilities/Platform.ios.js b/packages/react-native/Libraries/Utilities/Platform.ios.js index 4c5377395c0b3b..1fa1b83ab44cc0 100644 --- a/packages/react-native/Libraries/Utilities/Platform.ios.js +++ b/packages/react-native/Libraries/Utilities/Platform.ios.js @@ -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] diff --git a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap index 7bd8f7b59eb40a..5a52f701e3bf0d 100644 --- a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap +++ b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap @@ -9910,6 +9910,7 @@ type IOSPlatform = { |}, get isPad(): boolean, get isTV(): boolean, + get isVision(): boolean, get isTesting(): boolean, get isDisableAnimations(): boolean, get isMacCatalyst(): boolean, diff --git a/packages/react-native/React/CoreModules/RCTPlatform.mm b/packages/react-native/React/CoreModules/RCTPlatform.mm index d6ceed27dfa320..a908677a3c66c3 100644 --- a/packages/react-native/React/CoreModules/RCTPlatform.mm +++ b/packages/react-native/React/CoreModules/RCTPlatform.mm @@ -30,6 +30,10 @@ return @"tv"; case UIUserInterfaceIdiomCarPlay: return @"carplay"; +#if TARGET_OS_VISION + case UIUserInterfaceIdiomVision: + return @"vision"; +#endif default: return @"unknown"; }