mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
d31d83f410
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
75 lines
1.8 KiB
Plaintext
75 lines
1.8 KiB
Plaintext
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import "RCTLogBoxView.h"
|
|
|
|
#import <React/RCTLog.h>
|
|
#import <React/RCTSurface.h>
|
|
|
|
@implementation RCTLogBoxView {
|
|
RCTSurface *_surface;
|
|
}
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
{
|
|
if ((self = [super initWithFrame:frame])) {
|
|
self.windowLevel = UIWindowLevelStatusBar - 1;
|
|
self.backgroundColor = [UIColor clearColor];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)createRootViewController:(UIView *)view
|
|
{
|
|
UIViewController *_rootViewController = [UIViewController new];
|
|
_rootViewController.view = view;
|
|
_rootViewController.view.backgroundColor = [UIColor clearColor];
|
|
_rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
self.rootViewController = _rootViewController;
|
|
}
|
|
|
|
- (instancetype)initWithWindow:(UIWindow *)window bridge:(RCTBridge *)bridge
|
|
{
|
|
if (@available(iOS 13.0, *)) {
|
|
self = [super initWithWindowScene:window.windowScene];
|
|
} else {
|
|
self = [super initWithFrame:window.frame];
|
|
}
|
|
|
|
self.windowLevel = UIWindowLevelStatusBar - 1;
|
|
self.backgroundColor = [UIColor clearColor];
|
|
|
|
_surface = [[RCTSurface alloc] initWithBridge:bridge moduleName:@"LogBox" initialProperties:@{}];
|
|
[_surface start];
|
|
|
|
if (![_surface synchronouslyWaitForStage:RCTSurfaceStageSurfaceDidInitialMounting timeout:1]) {
|
|
RCTLogInfo(@"Failed to mount LogBox within 1s");
|
|
}
|
|
[self createRootViewController:(UIView *)_surface.view];
|
|
|
|
return self;
|
|
}
|
|
|
|
- (void)layoutSubviews
|
|
{
|
|
[super layoutSubviews];
|
|
[_surface setSize:self.frame.size];
|
|
}
|
|
|
|
- (void)dealloc
|
|
{
|
|
[RCTSharedApplication().delegate.window makeKeyWindow];
|
|
}
|
|
|
|
- (void)show
|
|
{
|
|
[self becomeFirstResponder];
|
|
[self makeKeyAndVisible];
|
|
}
|
|
|
|
@end
|