mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Refactor: Migrate Logbox surface initialization to Fabric when available, in Bridge and Bridgeless modes
Summary: Changelog: [iOS][Internal] Refactor: Migrate Logbox surface initialization to Fabric when available, in Bridge and Bridgeless modes # Why This diff main purpose is to add `RCTErrorNewArchitectureValidation(RCTNotAllowedInAppWideFabric)` in `RCTSurface`, to ensure Paper surfaces are never created in FBiOS. # The Situation Before this diff, in Bridged Fabric, `[RCTLogbox show]` initializes a Paper `RCTSurface`, [using `[RCTLogBoxView initWithWindow]`](https://github.com/facebook/react-native/blob/main/React/CoreModules/RCTLogBoxView.mm#L46)) In this diff, in Bridged and Bridgeless Fabric, `[RCTLogbox show]` initializes a Fabric `RCTFabricSurface`. Before this diff, in Bridgeless Fabric, RCTLogBox posts a "CreateLogBoxSurface" notification to RCTInstance. In this diff, the notification hack is replaced by the same `RCTFabricSurface` initialization above. Behavior is the same. Reviewed By: RSNara Differential Revision: D35177311 fbshipit-source-id: 6de418af8a01f914c9a806bb8d74915015f9087a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a3bccdacc0
commit
37e5fa3a6c
@@ -64,6 +64,7 @@
|
||||
moduleName:(NSString *)moduleName
|
||||
initialProperties:(NSDictionary *)initialProperties
|
||||
{
|
||||
RCTErrorNewArchitectureValidation(RCTNotAllowedInAppWideFabric, @"RCTSurface", nil);
|
||||
RCTAssert(bridge.valid, @"Valid bridge is required to instantiate `RCTSurface`.");
|
||||
|
||||
if (self = [super init]) {
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#import "RCTSurfaceHostingView.h"
|
||||
|
||||
#import "RCTConstants.h"
|
||||
#import "RCTDefines.h"
|
||||
#import "RCTSurface.h"
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#import <React/RCTLog.h>
|
||||
#import <React/RCTRedBoxSetEnabled.h>
|
||||
#import <React/RCTSurface.h>
|
||||
|
||||
#import "CoreModulesPlugins.h"
|
||||
|
||||
#if RCT_DEV_MENU
|
||||
@@ -23,6 +22,7 @@
|
||||
|
||||
@implementation RCTLogBox {
|
||||
RCTLogBoxView *_view;
|
||||
__weak id<RCTSurfacePresenterStub> _bridgelessSurfacePresenter;
|
||||
}
|
||||
|
||||
@synthesize bridge = _bridge;
|
||||
@@ -34,6 +34,11 @@ RCT_EXPORT_MODULE()
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)setSurfacePresenter:(id<RCTSurfacePresenterStub>)surfacePresenter
|
||||
{
|
||||
_bridgelessSurfacePresenter = surfacePresenter;
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(show)
|
||||
{
|
||||
if (RCTRedBoxGetEnabled()) {
|
||||
@@ -49,15 +54,19 @@ RCT_EXPORT_METHOD(show)
|
||||
return;
|
||||
}
|
||||
|
||||
if (strongSelf->_bridge) {
|
||||
if (strongSelf->_bridge.valid) {
|
||||
if (strongSelf->_bridgelessSurfacePresenter) {
|
||||
strongSelf->_view = [[RCTLogBoxView alloc] initWithFrame:RCTKeyWindow().frame
|
||||
surfacePresenter:strongSelf->_bridgelessSurfacePresenter];
|
||||
} else if (strongSelf->_bridge && strongSelf->_bridge.valid) {
|
||||
if (strongSelf->_bridge.surfacePresenter) {
|
||||
strongSelf->_view = [[RCTLogBoxView alloc] initWithFrame:RCTKeyWindow().frame
|
||||
surfacePresenter:strongSelf->_bridge.surfacePresenter];
|
||||
} else {
|
||||
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];
|
||||
}
|
||||
|
||||
[strongSelf->_view show];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#import <React/RCTBridge.h>
|
||||
#import <React/RCTSurfacePresenterStub.h>
|
||||
#import <React/RCTSurfaceView.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@@ -15,6 +16,8 @@
|
||||
|
||||
- (void)createRootViewController:(UIView *)view;
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame surfacePresenter:(id<RCTSurfacePresenterStub>)surfacePresenter;
|
||||
|
||||
- (instancetype)initWithWindow:(UIWindow *)window bridge:(RCTBridge *)bridge;
|
||||
|
||||
- (void)show;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#import <React/RCTLog.h>
|
||||
#import <React/RCTSurface.h>
|
||||
#import <React/RCTSurfaceHostingView.h>
|
||||
|
||||
@implementation RCTLogBoxView {
|
||||
RCTSurface *_surface;
|
||||
@@ -32,8 +33,25 @@
|
||||
self.rootViewController = _rootViewController;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame surfacePresenter:(id<RCTSurfacePresenterStub>)surfacePresenter
|
||||
{
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
id<RCTSurfaceProtocol> surface = [surfacePresenter createFabricSurfaceForModuleName:@"LogBox"
|
||||
initialProperties:@{}];
|
||||
[surface start];
|
||||
RCTSurfaceHostingView *rootView = [[RCTSurfaceHostingView alloc]
|
||||
initWithSurface:surface
|
||||
sizeMeasureMode:RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact];
|
||||
|
||||
[self createRootViewController:rootView];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithWindow:(UIWindow *)window bridge:(RCTBridge *)bridge
|
||||
{
|
||||
RCTErrorNewArchitectureValidation(RCTNotAllowedInAppWideFabric, @"RCTLogBoxView", nil);
|
||||
|
||||
if (@available(iOS 13.0, *)) {
|
||||
self = [super initWithWindowScene:window.windowScene];
|
||||
} else {
|
||||
|
||||
@@ -54,6 +54,12 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@property (readonly) RCTMountingManager *mountingManager;
|
||||
|
||||
/*
|
||||
* Allow callers to initialize a new fabric surface without adding Fabric as a Buck dependency.
|
||||
*/
|
||||
- (id<RCTSurfaceProtocol>)createFabricSurfaceForModuleName:(NSString *)moduleName
|
||||
initialProperties:(NSDictionary *)initialProperties;
|
||||
|
||||
- (nullable RCTFabricSurface *)surfaceForRootTag:(ReactTag)rootTag;
|
||||
|
||||
- (BOOL)synchronouslyUpdateViewOnUIThread:(NSNumber *)reactTag props:(NSDictionary *)props;
|
||||
|
||||
@@ -173,6 +173,14 @@ static BackgroundExecutor RCTGetBackgroundExecutor()
|
||||
return [_surfaceRegistry surfaceForRootTag:rootTag];
|
||||
}
|
||||
|
||||
- (id<RCTSurfaceProtocol>)createFabricSurfaceForModuleName:(NSString *)moduleName
|
||||
initialProperties:(NSDictionary *)initialProperties
|
||||
{
|
||||
return [[RCTFabricSurface alloc] initWithSurfacePresenter:self
|
||||
moduleName:moduleName
|
||||
initialProperties:initialProperties];
|
||||
}
|
||||
|
||||
- (UIView *)findComponentViewWithTag_DO_NOT_USE_DEPRECATED:(NSInteger)tag
|
||||
{
|
||||
UIView<RCTComponentViewProtocol> *componentView =
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
#import <React/RCTBridge.h>
|
||||
|
||||
@protocol RCTSurfaceProtocol;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// TODO: Eventually this should go away and files should just include RCTSurfacePresenter.h, but
|
||||
@@ -26,6 +28,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol RCTSurfacePresenterStub <NSObject>
|
||||
|
||||
- (id<RCTSurfaceProtocol>)createFabricSurfaceForModuleName:(NSString *)moduleName
|
||||
initialProperties:(NSDictionary *)initialProperties;
|
||||
- (nullable UIView *)findComponentViewWithTag_DO_NOT_USE_DEPRECATED:(NSInteger)tag;
|
||||
- (BOOL)synchronouslyUpdateViewOnUIThread:(NSNumber *)reactTag props:(NSDictionary *)props;
|
||||
- (void)addObserver:(id<RCTSurfacePresenterObserver>)observer;
|
||||
|
||||
Reference in New Issue
Block a user