From 8751b32202165ecfe9fa159861fdef487ee4860b Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Mon, 8 Apr 2024 06:57:07 -0700 Subject: [PATCH] Fix Orientation listener in bridgeless mode (#43971) Summary: It turns out that we forgot to add a listener for the orientation change event in Bridgeless. We used to have `UIApplicationDidChangeStatusBarOrientationNotification` but this is slightly unreliable because there might be use cases where the status bar has been hidden and, therefore, the event is not triggered. This should fix an issue reported by OSS. ## Changelog: [iOS][Fixed] - Make sure that the New Architecture listens to orientation change events. Differential Revision: D55871599 --- packages/react-native/React/CoreModules/RCTDeviceInfo.mm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/react-native/React/CoreModules/RCTDeviceInfo.mm b/packages/react-native/React/CoreModules/RCTDeviceInfo.mm index f4c664014609c4..86b5689d5f3b70 100644 --- a/packages/react-native/React/CoreModules/RCTDeviceInfo.mm +++ b/packages/react-native/React/CoreModules/RCTDeviceInfo.mm @@ -75,6 +75,10 @@ - (void)initialize selector:@selector(interfaceFrameDidChange) name:RCTWindowFrameDidChangeNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(interfaceFrameDidChange) + name:UIDeviceOrientationDidChangeNotification + object:nil]; // TODO T175901725 - Registering the RCTDeviceInfo module to the notification is a short-term fix to unblock 0.73 // The actual behavior should be that the module is properly registered in the TurboModule/Bridge infrastructure @@ -113,6 +117,8 @@ - (void)_cleanupObservers [[NSNotificationCenter defaultCenter] removeObserver:self name:RCTWindowFrameDidChangeNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:RCTBridgeWillInvalidateModulesNotification object:nil]; + + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; } static BOOL RCTIsIPhoneNotched()