From 49b0d26d45096227767bca90a528d5bb031d80e7 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Tue, 9 Apr 2024 07:57:54 -0700 Subject: [PATCH] Fix Orientation listener in bridgeless mode (#43971) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43971 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. Reviewed By: cortinico Differential Revision: D55871599 fbshipit-source-id: c9b0634ec2126aa7a6488c2c56c87a9610fa1adf --- .../React/CoreModules/RCTDeviceInfo.mm | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/react-native/React/CoreModules/RCTDeviceInfo.mm b/packages/react-native/React/CoreModules/RCTDeviceInfo.mm index f4c664014609c4..573c0c320a0c6e 100644 --- a/packages/react-native/React/CoreModules/RCTDeviceInfo.mm +++ b/packages/react-native/React/CoreModules/RCTDeviceInfo.mm @@ -54,11 +54,6 @@ - (void)initialize _currentInterfaceOrientation = [RCTSharedApplication() statusBarOrientation]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(interfaceOrientationDidChange) - name:UIApplicationDidChangeStatusBarOrientationNotification - object:nil]; - _currentInterfaceDimensions = [self _exportedDimensions]; [[NSNotificationCenter defaultCenter] addObserver:self @@ -75,6 +70,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 @@ -102,10 +101,6 @@ - (void)_cleanupObservers name:RCTAccessibilityManagerDidUpdateMultiplierNotification object:[_moduleRegistry moduleForName:"AccessibilityManager"]]; - [[NSNotificationCenter defaultCenter] removeObserver:self - name:UIApplicationDidChangeStatusBarOrientationNotification - object:nil]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:RCTUserInterfaceStyleDidChangeNotification object:nil]; @@ -113,6 +108,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()