From 268d9edad69a22710711be055100680817b28791 Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Tue, 29 Aug 2023 14:23:01 -0700 Subject: [PATCH] decouple root views from native modules (#38872) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38872 ## Changelog: [iOS][Breaking] - RCTTurboModuleRegistry is unavailable in RCTRootView and RCTSurfaceHostingProxyRootView now after all the diffs in this stack, we can finally decouple the root views from the module registry, and remove the dependency from fabric root views on bridge. for what i'm breaking, i only found this module library: https://github.com/flyskywhy/react-native-blob-util/blob/3d5155e11426fa458a9e2dbf7fe691cf9863ff01/ios/ReactNativeBlobUtil/ReactNativeBlobUtil.mm#L45. they can replace this with synthesize moduleRegistry API to get access. for eventDispatcher, i didn't see anyone using this. Reviewed By: mdvacca, cipolleschi Differential Revision: D48179428 fbshipit-source-id: d08fbd0adf6177d56e32a0ce4b21b6acb0682a2d --- .../Libraries/AppDelegate/RCTAppDelegate.mm | 3 +- .../react-native/React/Base/RCTRootView.h | 8 ----- .../react-native/React/Base/RCTRootView.m | 10 ------- .../RCTSurfaceHostingProxyRootView.h | 11 +------ .../RCTSurfaceHostingProxyRootView.mm | 30 +------------------ 5 files changed, 3 insertions(+), 59 deletions(-) diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm index 7752feffbad..94ace4e996c 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm @@ -93,8 +93,7 @@ static NSString *const kRNConcurrentRoot = @"concurrentRoot"; RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = [[RCTSurfaceHostingProxyRootView alloc] initWithSurface:surface - sizeMeasureMode:RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact - moduleRegistry:[_reactHost getModuleRegistry]]; + sizeMeasureMode:RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact]; rootView = (RCTRootView *)surfaceHostingProxyRootView; #endif diff --git a/packages/react-native/React/Base/RCTRootView.h b/packages/react-native/React/Base/RCTRootView.h index 08113e91d34..2903273639d 100644 --- a/packages/react-native/React/Base/RCTRootView.h +++ b/packages/react-native/React/Base/RCTRootView.h @@ -77,14 +77,6 @@ extern initialProperties:(nullable NSDictionary *)initialProperties launchOptions:(nullable NSDictionary *)launchOptions; -/** - * This API allows users of RCTRootView to access other NativeModules, without - * directly accessing the bridge. - */ -@property (nonatomic, strong, readonly) RCTModuleRegistry *moduleRegistry; - -@property (nonatomic, strong, readonly) id eventDispatcher; - /** * The name of the JavaScript module to execute within the * specified scriptURL (required). Setting this will not have diff --git a/packages/react-native/React/Base/RCTRootView.m b/packages/react-native/React/Base/RCTRootView.m index 113f44dc27e..c7c142075bb 100644 --- a/packages/react-native/React/Base/RCTRootView.m +++ b/packages/react-native/React/Base/RCTRootView.m @@ -121,16 +121,6 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)aDecoder) return self; } -- (RCTModuleRegistry *)moduleRegistry -{ - return _bridge.moduleRegistry; -} - -- (id)eventDispatcher -{ - return [self.moduleRegistry moduleForName:"EventDispatcher"]; -} - #pragma mark - passThroughTouches - (BOOL)passThroughTouches diff --git a/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.h b/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.h index c11084908cc..02092dd0449 100644 --- a/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.h +++ b/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.h @@ -27,8 +27,6 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSString *moduleName; @property (nonatomic, strong, readonly) RCTBridge *bridge; -@property (nonatomic, strong, readonly) RCTModuleRegistry *moduleRegistry; -@property (nonatomic, strong, readonly) id eventDispatcher; @property (nonatomic, copy, readwrite) NSDictionary *appProperties; @property (nonatomic, assign) RCTRootViewSizeFlexibility sizeFlexibility; @property (nonatomic, weak) id delegate; @@ -41,14 +39,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign) NSTimeInterval loadingViewFadeDuration; @property (nonatomic, assign) CGSize minimumSize; -/** - * Bridgeless mode initializer - */ -- (instancetype)initWithSurface:(id)surface - sizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode - moduleRegistry:(RCTModuleRegistry *)moduleRegistry; - -- (instancetype)initWithSurface:(id)surface; +- (instancetype)initWithSurface:(id)surface NS_DESIGNATED_INITIALIZER; - (void)cancelTouches; diff --git a/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.mm b/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.mm index c5b7ed27770..670c0229960 100644 --- a/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.mm +++ b/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.mm @@ -49,20 +49,7 @@ static RCTRootViewSizeFlexibility convertToRootViewSizeFlexibility(RCTSurfaceSiz } } -@implementation RCTSurfaceHostingProxyRootView { - RCTModuleRegistry *_moduleRegistry; -} - -- (instancetype)initWithSurface:(id)surface - sizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode - moduleRegistry:(RCTModuleRegistry *)moduleRegistry -{ - if (self = [super initWithSurface:surface sizeMeasureMode:sizeMeasureMode]) { - _moduleRegistry = moduleRegistry; - } - - return self; -} +@implementation RCTSurfaceHostingProxyRootView - (instancetype)initWithSurface:(id)surface { @@ -73,21 +60,6 @@ static RCTRootViewSizeFlexibility convertToRootViewSizeFlexibility(RCTSurfaceSiz return self; } -- (RCTModuleRegistry *)moduleRegistry -{ - // In bridgeless mode, RCTSurfaceHostingProxyRootView is created with an RCTModuleRegistry - if (_moduleRegistry) { - return _moduleRegistry; - } - - return _bridge.moduleRegistry; -} - -- (id)eventDispatcher -{ - return [self.moduleRegistry moduleForName:"EventDispatcher"]; -} - RCT_NOT_IMPLEMENTED(-(instancetype)initWithFrame : (CGRect)frame) RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)aDecoder)