Skip to content

Commit

Permalink
decouple root views from native modules (#38872)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
philIip authored and facebook-github-bot committed Aug 29, 2023
1 parent f60c5dd commit 268d9ed
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = [[RCTSurfaceHostingProxyRootView alloc]
initWithSurface:surface
sizeMeasureMode:RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact
moduleRegistry:[_reactHost getModuleRegistry]];
sizeMeasureMode:RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact];

rootView = (RCTRootView *)surfaceHostingProxyRootView;
#endif
Expand Down
8 changes: 0 additions & 8 deletions packages/react-native/React/Base/RCTRootView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<RCTEventDispatcherProtocol> eventDispatcher;

/**
* The name of the JavaScript module to execute within the
* specified scriptURL (required). Setting this will not have
Expand Down
10 changes: 0 additions & 10 deletions packages/react-native/React/Base/RCTRootView.m
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,6 @@ - (UIView *)view
return self;
}

- (RCTModuleRegistry *)moduleRegistry
{
return _bridge.moduleRegistry;
}

- (id<RCTEventDispatcherProtocol>)eventDispatcher
{
return [self.moduleRegistry moduleForName:"EventDispatcher"];
}

#pragma mark - passThroughTouches

- (BOOL)passThroughTouches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RCTEventDispatcherProtocol> eventDispatcher;
@property (nonatomic, copy, readwrite) NSDictionary *appProperties;
@property (nonatomic, assign) RCTRootViewSizeFlexibility sizeFlexibility;
@property (nonatomic, weak) id<RCTRootViewDelegate> delegate;
Expand All @@ -41,14 +39,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign) NSTimeInterval loadingViewFadeDuration;
@property (nonatomic, assign) CGSize minimumSize;

/**
* Bridgeless mode initializer
*/
- (instancetype)initWithSurface:(id<RCTSurfaceProtocol>)surface
sizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode
moduleRegistry:(RCTModuleRegistry *)moduleRegistry;

- (instancetype)initWithSurface:(id<RCTSurfaceProtocol>)surface;
- (instancetype)initWithSurface:(id<RCTSurfaceProtocol>)surface NS_DESIGNATED_INITIALIZER;

- (void)cancelTouches;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,7 @@ static RCTRootViewSizeFlexibility convertToRootViewSizeFlexibility(RCTSurfaceSiz
}
}

@implementation RCTSurfaceHostingProxyRootView {
RCTModuleRegistry *_moduleRegistry;
}

- (instancetype)initWithSurface:(id<RCTSurfaceProtocol>)surface
sizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
{
if (self = [super initWithSurface:surface sizeMeasureMode:sizeMeasureMode]) {
_moduleRegistry = moduleRegistry;
}

return self;
}
@implementation RCTSurfaceHostingProxyRootView

- (instancetype)initWithSurface:(id<RCTSurfaceProtocol>)surface
{
Expand All @@ -73,21 +60,6 @@ - (instancetype)initWithSurface:(id<RCTSurfaceProtocol>)surface
return self;
}

- (RCTModuleRegistry *)moduleRegistry
{
// In bridgeless mode, RCTSurfaceHostingProxyRootView is created with an RCTModuleRegistry
if (_moduleRegistry) {
return _moduleRegistry;
}

return _bridge.moduleRegistry;
}

- (id<RCTEventDispatcherProtocol>)eventDispatcher
{
return [self.moduleRegistry moduleForName:"EventDispatcher"];
}

RCT_NOT_IMPLEMENTED(-(instancetype)initWithFrame : (CGRect)frame)
RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)aDecoder)

Expand Down

0 comments on commit 268d9ed

Please sign in to comment.