Skip to content

Commit d31d83f

Browse files
vincentriemerfacebook-github-bot
authored andcommitted
Update iOS LogBox to render its UIWindow with the key window's UIWindowScene
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
1 parent 96c611b commit d31d83f

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

React/CoreModules/RCTLogBox.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ + (BOOL)requiresMainQueueSetup
5151

5252
if (strongSelf->_bridge) {
5353
if (strongSelf->_bridge.valid) {
54-
strongSelf->_view = [[RCTLogBoxView alloc] initWithFrame:RCTKeyWindow().frame bridge:strongSelf->_bridge];
54+
strongSelf->_view = [[RCTLogBoxView alloc] initWithWindow:RCTKeyWindow() bridge:strongSelf->_bridge];
5555
[strongSelf->_view show];
5656
}
5757
} else {

React/CoreModules/RCTLogBoxView.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

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

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

2020
- (void)show;
2121

React/CoreModules/RCTLogBoxView.mm

+14-11
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,25 @@ - (void)createRootViewController:(UIView *)view
3232
self.rootViewController = _rootViewController;
3333
}
3434

35-
- (instancetype)initWithFrame:(CGRect)frame bridge:(RCTBridge *)bridge
35+
- (instancetype)initWithWindow:(UIWindow *)window bridge:(RCTBridge *)bridge
3636
{
37-
if ((self = [super initWithFrame:frame])) {
38-
self.windowLevel = UIWindowLevelStatusBar - 1;
39-
self.backgroundColor = [UIColor clearColor];
37+
if (@available(iOS 13.0, *)) {
38+
self = [super initWithWindowScene:window.windowScene];
39+
} else {
40+
self = [super initWithFrame:window.frame];
41+
}
4042

41-
_surface = [[RCTSurface alloc] initWithBridge:bridge moduleName:@"LogBox" initialProperties:@{}];
42-
[_surface setSize:frame.size];
43-
[_surface start];
43+
self.windowLevel = UIWindowLevelStatusBar - 1;
44+
self.backgroundColor = [UIColor clearColor];
4445

45-
if (![_surface synchronouslyWaitForStage:RCTSurfaceStageSurfaceDidInitialMounting timeout:1]) {
46-
RCTLogInfo(@"Failed to mount LogBox within 1s");
47-
}
46+
_surface = [[RCTSurface alloc] initWithBridge:bridge moduleName:@"LogBox" initialProperties:@{}];
47+
[_surface start];
4848

49-
[self createRootViewController:(UIView *)_surface.view];
49+
if (![_surface synchronouslyWaitForStage:RCTSurfaceStageSurfaceDidInitialMounting timeout:1]) {
50+
RCTLogInfo(@"Failed to mount LogBox within 1s");
5051
}
52+
[self createRootViewController:(UIView *)_surface.view];
53+
5154
return self;
5255
}
5356

0 commit comments

Comments
 (0)