From e85372298109abf258d5154e2a28bc6496fb9529 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Thu, 1 Oct 2020 13:17:50 -0700 Subject: [PATCH] A couple of checks for corner cases in RCTGetDimensions and RCTExportedDimensions Summary: We need this checks to make the results of those function more reliable. Reviewed By: sammy-SC Differential Revision: D24038911 fbshipit-source-id: 3b54fe3056c9508cde84ea157beebea57e7e49b6 --- React/CoreModules/RCTDeviceInfo.mm | 3 ++- React/UIUtils/RCTUIUtils.m | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/React/CoreModules/RCTDeviceInfo.mm b/React/CoreModules/RCTDeviceInfo.mm index e3ac4339915..1f0bd576a4b 100644 --- a/React/CoreModules/RCTDeviceInfo.mm +++ b/React/CoreModules/RCTDeviceInfo.mm @@ -93,7 +93,8 @@ static BOOL RCTIsIPhoneX() static NSDictionary *RCTExportedDimensions(RCTBridge *bridge) { RCTAssertMainQueue(); - RCTDimensions dimensions = RCTGetDimensions(bridge.accessibilityManager.multiplier); + RCTAssert(bridge, @"Bridge must not be `nil`."); + RCTDimensions dimensions = RCTGetDimensions(bridge.accessibilityManager.multiplier ?: 1.0); __typeof(dimensions.window) window = dimensions.window; NSDictionary *dimsWindow = @{ @"width" : @(window.width), diff --git a/React/UIUtils/RCTUIUtils.m b/React/UIUtils/RCTUIUtils.m index 2d3243c5783..ba9443e298a 100644 --- a/React/UIUtils/RCTUIUtils.m +++ b/React/UIUtils/RCTUIUtils.m @@ -16,7 +16,8 @@ RCTDimensions RCTGetDimensions(CGFloat fontScale) UIView *mainWindow; mainWindow = RCTKeyWindow(); - CGSize windowSize = mainWindow.bounds.size; + // We fallback to screen size if a key window is not found. + CGSize windowSize = mainWindow ? mainWindow.bounds.size : screenSize; RCTDimensions result; typeof(result.screen) dimsScreen = {