diff --git a/React/CoreModules/RCTLogBox.mm b/React/CoreModules/RCTLogBox.mm index 5f1b8a62efe48f..78a30635dc5b9c 100644 --- a/React/CoreModules/RCTLogBox.mm +++ b/React/CoreModules/RCTLogBox.mm @@ -51,7 +51,7 @@ + (BOOL)requiresMainQueueSetup if (strongSelf->_bridge) { if (strongSelf->_bridge.valid) { - strongSelf->_view = [[RCTLogBoxView alloc] initWithFrame:RCTKeyWindow().frame bridge:strongSelf->_bridge]; + strongSelf->_view = [[RCTLogBoxView alloc] initWithWindow:RCTKeyWindow() bridge:strongSelf->_bridge]; [strongSelf->_view show]; } } else { diff --git a/React/CoreModules/RCTLogBoxView.h b/React/CoreModules/RCTLogBoxView.h index 30de9fda88896a..1495fbaed8c715 100644 --- a/React/CoreModules/RCTLogBoxView.h +++ b/React/CoreModules/RCTLogBoxView.h @@ -15,7 +15,7 @@ - (void)createRootViewController:(UIView *)view; -- (instancetype)initWithFrame:(CGRect)frame bridge:(RCTBridge *)bridge; +- (instancetype)initWithWindow:(UIWindow *)window bridge:(RCTBridge *)bridge; - (void)show; diff --git a/React/CoreModules/RCTLogBoxView.mm b/React/CoreModules/RCTLogBoxView.mm index 41ff2d56bc07e6..8cf4f4e7e6eddf 100644 --- a/React/CoreModules/RCTLogBoxView.mm +++ b/React/CoreModules/RCTLogBoxView.mm @@ -32,22 +32,25 @@ - (void)createRootViewController:(UIView *)view self.rootViewController = _rootViewController; } -- (instancetype)initWithFrame:(CGRect)frame bridge:(RCTBridge *)bridge +- (instancetype)initWithWindow:(UIWindow *)window bridge:(RCTBridge *)bridge { - if ((self = [super initWithFrame:frame])) { - self.windowLevel = UIWindowLevelStatusBar - 1; - self.backgroundColor = [UIColor clearColor]; + if (@available(iOS 13.0, *)) { + self = [super initWithWindowScene:window.windowScene]; + } else { + self = [super initWithFrame:window.frame]; + } - _surface = [[RCTSurface alloc] initWithBridge:bridge moduleName:@"LogBox" initialProperties:@{}]; - [_surface setSize:frame.size]; - [_surface start]; + self.windowLevel = UIWindowLevelStatusBar - 1; + self.backgroundColor = [UIColor clearColor]; - if (![_surface synchronouslyWaitForStage:RCTSurfaceStageSurfaceDidInitialMounting timeout:1]) { - RCTLogInfo(@"Failed to mount LogBox within 1s"); - } + _surface = [[RCTSurface alloc] initWithBridge:bridge moduleName:@"LogBox" initialProperties:@{}]; + [_surface start]; - [self createRootViewController:(UIView *)_surface.view]; + if (![_surface synchronouslyWaitForStage:RCTSurfaceStageSurfaceDidInitialMounting timeout:1]) { + RCTLogInfo(@"Failed to mount LogBox within 1s"); } + [self createRootViewController:(UIView *)_surface.view]; + return self; }