Skip to content

Commit

Permalink
Update iOS LogBox to render its UIWindow with the key window's UIWind…
Browse files Browse the repository at this point in the history
…owScene

Summary:
If an RN app is embedded in a Mac Catalyst app that uses the UIWindowScene API to manage multiple windows, LogBox would fail to render because it didn't know which UIWindowScene to render to. This diff fixes that situation by ensuring that the LogBox window gets rendered in the key window's scene.

Changelog:
[iOS][Fixed] - Update iOS LogBox to render its UIWindow with the key window's UIWindowScene

Reviewed By: appden

Differential Revision: D35027831

fbshipit-source-id: e0df5865f95323b03d08d6b1fb3ec912aa9a9167
  • Loading branch information
vincentriemer authored and facebook-github-bot committed Mar 25, 2022
1 parent 96c611b commit d31d83f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion React/CoreModules/RCTLogBox.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion React/CoreModules/RCTLogBoxView.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

- (void)createRootViewController:(UIView *)view;

- (instancetype)initWithFrame:(CGRect)frame bridge:(RCTBridge *)bridge;
- (instancetype)initWithWindow:(UIWindow *)window bridge:(RCTBridge *)bridge;

- (void)show;

Expand Down
25 changes: 14 additions & 11 deletions React/CoreModules/RCTLogBoxView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit d31d83f

Please sign in to comment.