mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
128 lines
2.5 KiB
Plaintext
128 lines
2.5 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 "RCTLogBox.h"
|
|
|
|
#import <FBReactNativeSpec/FBReactNativeSpec.h>
|
|
#import <React/RCTBridge.h>
|
|
#import <React/RCTBridgeModule.h>
|
|
#import <React/RCTLog.h>
|
|
#import <React/RCTRedBoxSetEnabled.h>
|
|
#import <React/RCTSurface.h>
|
|
|
|
#import "CoreModulesPlugins.h"
|
|
|
|
#if RCT_DEV_MENU
|
|
|
|
@interface RCTLogBox () <NativeLogBoxSpec, RCTBridgeModule>
|
|
@end
|
|
|
|
@implementation RCTLogBox {
|
|
RCTLogBoxView *_view;
|
|
}
|
|
|
|
@synthesize bridge = _bridge;
|
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
+ (BOOL)requiresMainQueueSetup
|
|
{
|
|
return YES;
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(show)
|
|
{
|
|
if (RCTRedBoxGetEnabled()) {
|
|
__weak RCTLogBox *weakSelf = self;
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
__strong RCTLogBox *strongSelf = weakSelf;
|
|
if (!strongSelf) {
|
|
return;
|
|
}
|
|
|
|
if (strongSelf->_view) {
|
|
[strongSelf->_view show];
|
|
return;
|
|
}
|
|
|
|
if (strongSelf->_bridge) {
|
|
if (strongSelf->_bridge.valid) {
|
|
strongSelf->_view = [[RCTLogBoxView alloc] initWithWindow:RCTKeyWindow() bridge:strongSelf->_bridge];
|
|
[strongSelf->_view show];
|
|
}
|
|
} else {
|
|
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:strongSelf, @"logbox", nil];
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"CreateLogBoxSurface" object:nil userInfo:userInfo];
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(hide)
|
|
{
|
|
if (RCTRedBoxGetEnabled()) {
|
|
__weak RCTLogBox *weakSelf = self;
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
__strong RCTLogBox *strongSelf = weakSelf;
|
|
if (!strongSelf) {
|
|
return;
|
|
}
|
|
[strongSelf->_view setHidden:YES];
|
|
strongSelf->_view = nil;
|
|
});
|
|
}
|
|
}
|
|
|
|
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
{
|
|
return std::make_shared<facebook::react::NativeLogBoxSpecJSI>(params);
|
|
}
|
|
|
|
- (void)setRCTLogBoxView:(RCTLogBoxView *)view
|
|
{
|
|
self->_view = view;
|
|
}
|
|
|
|
@end
|
|
|
|
#else // Disabled
|
|
|
|
@interface RCTLogBox () <NativeLogBoxSpec>
|
|
@end
|
|
|
|
@implementation RCTLogBox
|
|
|
|
+ (NSString *)moduleName
|
|
{
|
|
return nil;
|
|
}
|
|
|
|
- (void)show
|
|
{
|
|
// noop
|
|
}
|
|
|
|
- (void)hide
|
|
{
|
|
// noop
|
|
}
|
|
|
|
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
{
|
|
return std::make_shared<facebook::react::NativeLogBoxSpecJSI>(params);
|
|
}
|
|
@end
|
|
|
|
#endif
|
|
|
|
Class RCTLogBoxCls(void)
|
|
{
|
|
return RCTLogBox.class;
|
|
}
|