Skip to content

Commit

Permalink
check if bridge exists when we access the module registry
Browse files Browse the repository at this point in the history
Summary:
Changelog: [internal]

we have an issue where the moduleRegistry that the TM uses is released, adding this log to check if it's bc the bridge was released

Reviewed By: RSNara

Differential Revision: D35420922

fbshipit-source-id: 93c206b5afefeac3121df148940d9658736cb9d2
  • Loading branch information
philIip authored and facebook-github-bot committed Apr 14, 2022
1 parent 8c5fc4f commit e500e89
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions React/CoreModules/RCTDeviceInfo.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ @implementation RCTDeviceInfo {
NSDictionary *_currentInterfaceDimensions;
}

@synthesize bridge = _bridge;
@synthesize moduleRegistry = _moduleRegistry;

RCT_EXPORT_MODULE()
Expand Down Expand Up @@ -56,7 +57,7 @@ - (void)initialize
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];

_currentInterfaceDimensions = RCTExportedDimensions(_moduleRegistry);
_currentInterfaceDimensions = RCTExportedDimensions(_moduleRegistry, _bridge);

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(interfaceFrameDidChange)
Expand Down Expand Up @@ -95,7 +96,7 @@ static BOOL RCTIsIPhoneX()
return isIPhoneX;
}

static NSDictionary *RCTExportedDimensions(RCTModuleRegistry *moduleRegistry)
static NSDictionary *RCTExportedDimensions(RCTModuleRegistry *moduleRegistry, RCTBridge *bridge)
{
RCTAssertMainQueue();
RCTDimensions dimensions;
Expand All @@ -104,7 +105,7 @@ static BOOL RCTIsIPhoneX()
(RCTAccessibilityManager *)[moduleRegistry moduleForName:"AccessibilityManager"];
dimensions = RCTGetDimensions(accessibilityManager ? accessibilityManager.multiplier : 1.0);
} else {
RCTAssert(false, @"ModuleRegistry must be set to properly init dimensions.");
RCTAssert(false, @"ModuleRegistry must be set to properly init dimensions. Bridge exists: %d", bridge != nil);
}
__typeof(dimensions.window) window = dimensions.window;
NSDictionary<NSString *, NSNumber *> *dimsWindow = @{
Expand Down Expand Up @@ -132,9 +133,10 @@ static BOOL RCTIsIPhoneX()
{
__block NSDictionary<NSString *, id> *constants;
RCTModuleRegistry *moduleRegistry = _moduleRegistry;
RCTBridge *bridge = _bridge;
RCTUnsafeExecuteOnMainQueueSync(^{
constants = @{
@"Dimensions" : RCTExportedDimensions(moduleRegistry),
@"Dimensions" : RCTExportedDimensions(moduleRegistry, bridge),
// Note:
// This prop is deprecated and will be removed in a future release.
// Please use this only for a quick and temporary solution.
Expand All @@ -149,12 +151,14 @@ static BOOL RCTIsIPhoneX()
- (void)didReceiveNewContentSizeMultiplier
{
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)];
[[moduleRegistry moduleForName:"EventDispatcher"]
sendDeviceEventWithName:@"didUpdateDimensions"
body:RCTExportedDimensions(moduleRegistry, bridge)];
#pragma clang diagnostic pop
});
}
Expand All @@ -178,8 +182,9 @@ - (void)_interfaceOrientationDidChange
!UIInterfaceOrientationIsLandscape(nextOrientation))) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[[_moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"didUpdateDimensions"
body:RCTExportedDimensions(_moduleRegistry)];
[[_moduleRegistry moduleForName:"EventDispatcher"]
sendDeviceEventWithName:@"didUpdateDimensions"
body:RCTExportedDimensions(_moduleRegistry, _bridge)];
#pragma clang diagnostic pop
}

Expand All @@ -196,7 +201,7 @@ - (void)interfaceFrameDidChange

- (void)_interfaceFrameDidChange
{
NSDictionary *nextInterfaceDimensions = RCTExportedDimensions(_moduleRegistry);
NSDictionary *nextInterfaceDimensions = RCTExportedDimensions(_moduleRegistry, _bridge);

if (!([nextInterfaceDimensions isEqual:_currentInterfaceDimensions])) {
#pragma clang diagnostic push
Expand Down

0 comments on commit e500e89

Please sign in to comment.