From bb0689581c6538900d4ccb8581d35ca3d78ff62a Mon Sep 17 00:00:00 2001 From: Marco Fiorito Date: Thu, 7 Dec 2023 04:44:41 -0300 Subject: [PATCH] task(StatusBar component): show warn when using StatusBar (#49) * task(StatusBar component): show warn when using StatusBar * pr suggestions --- .../Libraries/Components/StatusBar/StatusBar.js | 8 ++++++++ .../react-native/React/CoreModules/RCTStatusBarManager.mm | 2 ++ 2 files changed, 10 insertions(+) diff --git a/packages/react-native/Libraries/Components/StatusBar/StatusBar.js b/packages/react-native/Libraries/Components/StatusBar/StatusBar.js index 2ac3d1f6b09dad..13df2404be85b6 100644 --- a/packages/react-native/Libraries/Components/StatusBar/StatusBar.js +++ b/packages/react-native/Libraries/Components/StatusBar/StatusBar.js @@ -12,6 +12,7 @@ import type {ColorValue} from '../../StyleSheet/StyleSheet'; import processColor from '../../StyleSheet/processColor'; import Platform from '../../Utilities/Platform'; +import warnOnce from '../../Utilities/warnOnce'; import NativeStatusBarManagerAndroid from './NativeStatusBarManagerAndroid'; import NativeStatusBarManagerIOS from './NativeStatusBarManagerIOS'; import invariant from 'invariant'; @@ -393,6 +394,13 @@ class StatusBar extends React.Component { _stackEntry = null; componentDidMount() { + if (Platform.isVisionOS) { + warnOnce( + 'StatusBar-unavailable', + 'StatusBar is not available on visionOS platform.', + ); + return; + } // Every time a StatusBar component is mounted, we push it's prop to a stack // and always update the native status bar with the props from the top of then // stack. This allows having multiple StatusBar components and the one that is diff --git a/packages/react-native/React/CoreModules/RCTStatusBarManager.mm b/packages/react-native/React/CoreModules/RCTStatusBarManager.mm index 4cc09edc54010c..f5f6453967dc63 100644 --- a/packages/react-native/React/CoreModules/RCTStatusBarManager.mm +++ b/packages/react-native/React/CoreModules/RCTStatusBarManager.mm @@ -91,7 +91,9 @@ - (void)startObserving - (void)stopObserving { +#if !TARGET_OS_VISION [[NSNotificationCenter defaultCenter] removeObserver:self]; +#endif } - (void)emitEvent:(NSString *)eventName forNotification:(NSNotification *)notification