Skip to content

Commit 4eb0534

Browse files
cipolleschicortinico
authored andcommitted
Fix Orientation listener in bridgeless mode (#43971)
Summary: Pull Request resolved: #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
1 parent c2317bf commit 4eb0534

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

packages/react-native/React/CoreModules/RCTDeviceInfo.mm

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ - (void)initialize
5454

5555
_currentInterfaceOrientation = [RCTSharedApplication() statusBarOrientation];
5656

57-
[[NSNotificationCenter defaultCenter] addObserver:self
58-
selector:@selector(interfaceOrientationDidChange)
59-
name:UIApplicationDidChangeStatusBarOrientationNotification
60-
object:nil];
61-
6257
_currentInterfaceDimensions = [self _exportedDimensions];
6358

6459
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -75,6 +70,10 @@ - (void)initialize
7570
selector:@selector(interfaceFrameDidChange)
7671
name:RCTWindowFrameDidChangeNotification
7772
object:nil];
73+
[[NSNotificationCenter defaultCenter] addObserver:self
74+
selector:@selector(interfaceFrameDidChange)
75+
name:UIDeviceOrientationDidChangeNotification
76+
object:nil];
7877

7978
// TODO T175901725 - Registering the RCTDeviceInfo module to the notification is a short-term fix to unblock 0.73
8079
// The actual behavior should be that the module is properly registered in the TurboModule/Bridge infrastructure
@@ -102,17 +101,15 @@ - (void)_cleanupObservers
102101
name:RCTAccessibilityManagerDidUpdateMultiplierNotification
103102
object:[_moduleRegistry moduleForName:"AccessibilityManager"]];
104103

105-
[[NSNotificationCenter defaultCenter] removeObserver:self
106-
name:UIApplicationDidChangeStatusBarOrientationNotification
107-
object:nil];
108-
109104
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
110105

111106
[[NSNotificationCenter defaultCenter] removeObserver:self name:RCTUserInterfaceStyleDidChangeNotification object:nil];
112107

113108
[[NSNotificationCenter defaultCenter] removeObserver:self name:RCTWindowFrameDidChangeNotification object:nil];
114109

115110
[[NSNotificationCenter defaultCenter] removeObserver:self name:RCTBridgeWillInvalidateModulesNotification object:nil];
111+
112+
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
116113
}
117114

118115
static BOOL RCTIsIPhoneNotched()

0 commit comments

Comments
 (0)