Skip to content

Commit

Permalink
Ensure LogBoxView is sized based on the "window" size instead of the …
Browse files Browse the repository at this point in the history
…"screen" size

Summary:
In iOS, the native LogBox that gets rendered for JS errors/warnings is statically sized once and bases that size off of the entire screen's size. This causes issues when being run in a Mac Catalyst app since 1) the sizing is not static since we can resize the window and 2) the size of the LogBox's root should fill the *window* and not the screen. This diff fixes both of these issues.

Changelog:
[iOS][Fixed] - Ensure LogBoxView is sized relative to the key window instead of the full screen

Reviewed By: appden

Differential Revision: D34697076

fbshipit-source-id: 9665fd51bc86ed29837672cec882bac97904b0c8
  • Loading branch information
vincentriemer authored and facebook-github-bot committed Mar 9, 2022
1 parent 5386364 commit 84f8c9a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 1 addition & 2 deletions React/CoreModules/RCTLogBox.mm
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ + (BOOL)requiresMainQueueSetup

if (strongSelf->_bridge) {
if (strongSelf->_bridge.valid) {
strongSelf->_view = [[RCTLogBoxView alloc] initWithFrame:[UIScreen mainScreen].bounds
bridge:strongSelf->_bridge];
strongSelf->_view = [[RCTLogBoxView alloc] initWithFrame:RCTKeyWindow().frame bridge:strongSelf->_bridge];
[strongSelf->_view show];
}
} else {
Expand Down
9 changes: 7 additions & 2 deletions React/CoreModules/RCTLogBoxView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ - (instancetype)initWithFrame:(CGRect)frame bridge:(RCTBridge *)bridge
self.backgroundColor = [UIColor clearColor];

_surface = [[RCTSurface alloc] initWithBridge:bridge moduleName:@"LogBox" initialProperties:@{}];

[_surface start];
[_surface setSize:frame.size];
[_surface start];

if (![_surface synchronouslyWaitForStage:RCTSurfaceStageSurfaceDidInitialMounting timeout:1]) {
RCTLogInfo(@"Failed to mount LogBox within 1s");
Expand All @@ -52,6 +51,12 @@ - (instancetype)initWithFrame:(CGRect)frame bridge:(RCTBridge *)bridge
return self;
}

- (void)layoutSubviews
{
[super layoutSubviews];
[_surface setSize:self.frame.size];
}

- (void)dealloc
{
[RCTSharedApplication().delegate.window makeKeyWindow];
Expand Down

0 comments on commit 84f8c9a

Please sign in to comment.