diff --git a/packages/react-native/React/CoreModules/RCTDeviceInfo.mm b/packages/react-native/React/CoreModules/RCTDeviceInfo.mm index 117ccf29f77717..b62b332b89cc47 100644 --- a/packages/react-native/React/CoreModules/RCTDeviceInfo.mm +++ b/packages/react-native/React/CoreModules/RCTDeviceInfo.mm @@ -29,7 +29,6 @@ @implementation RCTDeviceInfo { BOOL _isFullscreen; } -@synthesize bridge = _bridge; @synthesize moduleRegistry = _moduleRegistry; RCT_EXPORT_MODULE() @@ -58,7 +57,7 @@ - (void)initialize name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; - _currentInterfaceDimensions = RCTExportedDimensions(_moduleRegistry, _bridge); + _currentInterfaceDimensions = [self _exportedDimensions]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(interfaceOrientationDidChange) @@ -86,17 +85,10 @@ static BOOL RCTIsIPhoneNotched() return isIPhoneNotched; } -static NSDictionary *RCTExportedDimensions(RCTModuleRegistry *moduleRegistry, RCTBridge *bridge) +static NSDictionary *RCTExportedDimensions(CGFloat fontScale) { RCTAssertMainQueue(); - RCTDimensions dimensions; - if (moduleRegistry) { - RCTAccessibilityManager *accessibilityManager = - (RCTAccessibilityManager *)[moduleRegistry moduleForName:"AccessibilityManager"]; - dimensions = RCTGetDimensions(accessibilityManager ? accessibilityManager.multiplier : 1.0); - } else { - RCTAssert(false, @"ModuleRegistry must be set to properly init dimensions. Bridge exists: %d", bridge != nil); - } + RCTDimensions dimensions = RCTGetDimensions(fontScale); __typeof(dimensions.window) window = dimensions.window; NSDictionary *dimsWindow = @{ @"width" : @(window.width), @@ -114,6 +106,15 @@ static BOOL RCTIsIPhoneNotched() return @{@"window" : dimsWindow, @"screen" : dimsScreen}; } +- (NSDictionary *)_exportedDimensions +{ + RCTAssert(_moduleRegistry, @"ModuleRegistry must be set to properly init dimensions"); + RCTAccessibilityManager *accessibilityManager = + (RCTAccessibilityManager *)[_moduleRegistry moduleForName:"AccessibilityManager"]; + CGFloat fontScale = accessibilityManager ? accessibilityManager.multiplier : 1.0; + return RCTExportedDimensions(fontScale); +} + - (NSDictionary *)constantsToExport { return [self getConstants]; @@ -122,11 +123,10 @@ static BOOL RCTIsIPhoneNotched() - (NSDictionary *)getConstants { __block NSDictionary *constants; - RCTModuleRegistry *moduleRegistry = _moduleRegistry; - RCTBridge *bridge = _bridge; + __weak __typeof(self) weakSelf = self; RCTUnsafeExecuteOnMainQueueSync(^{ constants = @{ - @"Dimensions" : RCTExportedDimensions(moduleRegistry, bridge), + @"Dimensions" : [weakSelf _exportedDimensions], // Note: // This prop is deprecated and will be removed in a future release. // Please use this only for a quick and temporary solution. @@ -140,15 +140,14 @@ static BOOL RCTIsIPhoneNotched() - (void)didReceiveNewContentSizeMultiplier { + __weak __typeof(self) weakSelf = self; RCTModuleRegistry *moduleRegistry = _moduleRegistry; - RCTBridge *bridge = _bridge; RCTExecuteOnMainQueue(^{ // Report the event across the bridge. #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - [[moduleRegistry moduleForName:"EventDispatcher"] - sendDeviceEventWithName:@"didUpdateDimensions" - body:RCTExportedDimensions(moduleRegistry, bridge)]; + [[moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"didUpdateDimensions" + body:[weakSelf _exportedDimensions]]; #pragma clang diagnostic pop }); } @@ -184,9 +183,8 @@ - (void)_interfaceOrientationDidChange if ((isOrientationChanging || isResizingOrChangingToFullscreen) && RCTIsAppActive()) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - [[_moduleRegistry moduleForName:"EventDispatcher"] - sendDeviceEventWithName:@"didUpdateDimensions" - body:RCTExportedDimensions(_moduleRegistry, _bridge)]; + [[_moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"didUpdateDimensions" + body:[self _exportedDimensions]]; // We only want to track the current _currentInterfaceOrientation and _isFullscreen only // when it happens and only when it is published. _currentInterfaceOrientation = nextOrientation; @@ -205,7 +203,7 @@ - (void)interfaceFrameDidChange - (void)_interfaceFrameDidChange { - NSDictionary *nextInterfaceDimensions = RCTExportedDimensions(_moduleRegistry, _bridge); + NSDictionary *nextInterfaceDimensions = [self _exportedDimensions]; // update and publish the even only when the app is in active state if (!([nextInterfaceDimensions isEqual:_currentInterfaceDimensions]) && RCTIsAppActive()) {