Allow RCTRootView users to require NativeModules without the bridge

Summary:
RCTRootVeiw exports the bridge. One reason why is to allow users of RCTRootView users to access NativeModules.

## Changes
- RCTBridge now exports the RCTModuleRegistry
- RCTRootView now exports the RCTModuleRegistry exported by the bridge
- Users of RCTRootView use the RCTModuleRegistry exported by RCTRootView to access NativeModules

## Benefits
Down the line, we'll change how RCTRootView gets the RCTModuleRegistry (i.e: it won't use the bridge in bridgeless mode).

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D30434886

fbshipit-source-id: 875fce24d2fd9ee6350f128c8612e613e61e390e
This commit is contained in:
Ramanpreet Nara
2021-09-02 16:50:08 -07:00
committed by Facebook GitHub Bot
parent a909ba20db
commit bfead74e69
7 changed files with 38 additions and 0 deletions
+8
View File
@@ -7,6 +7,7 @@
#import <React/RCTBridge.h>
@class RCTModuleRegistry;
@class RCTModuleData;
@protocol RCTJavaScriptExecutor;
@@ -62,6 +63,13 @@ RCT_EXTERN void RCTRegisterModule(Class);
*/
@property (nonatomic, strong, readwrite) NSURL *bundleURL;
/**
* An object that allows one to require NativeModules/TurboModules.
* RCTModuleRegistry is implemented in bridgeless mode and bridge mode.
* Used by RCTRootView.
*/
@property (nonatomic, strong, readonly) RCTModuleRegistry *moduleRegistry;
@end
@interface RCTBridge (RCTCxxBridge)
+5
View File
@@ -257,6 +257,11 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init)
});
}
- (RCTModuleRegistry *)moduleRegistry
{
return self.batchedBridge.moduleRegistry;
}
- (NSArray<Class> *)moduleClasses
{
return self.batchedBridge.moduleClasses;
+8
View File
@@ -8,6 +8,8 @@
#import <UIKit/UIKit.h>
#import <React/RCTBridge.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTEventDispatcherProtocol.h>
@protocol RCTRootViewDelegate;
@@ -80,6 +82,12 @@ extern
*/
@property (nonatomic, readonly) BOOL hasBridge;
/**
* This API allows users of RCTRootView to access other NativeModules, without
* directly accessing the bridge.
*/
@property (nonatomic, strong, readonly) RCTModuleRegistry *moduleRegistry;
/**
* The name of the JavaScript module to execute within the
* specified scriptURL (required). Setting this will not have
+5
View File
@@ -121,6 +121,11 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)aDecoder)
return _bridge != nil;
}
- (RCTModuleRegistry *)moduleRegistry
{
return _bridge.moduleRegistry;
}
#pragma mark - passThroughTouches
- (BOOL)passThroughTouches
@@ -27,6 +27,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy, readonly) NSString *moduleName;
@property (nonatomic, strong, readonly) RCTBridge *bridge;
@property (nonatomic, readonly) BOOL hasBridge;
@property (nonatomic, strong, readonly) RCTModuleRegistry *moduleRegistry;
@property (nonatomic, copy, readwrite) NSDictionary *appProperties;
@property (nonatomic, assign) RCTRootViewSizeFlexibility sizeFlexibility;
@property (nonatomic, weak) id<RCTRootViewDelegate> delegate;
@@ -10,6 +10,7 @@
#import <objc/runtime.h>
#import "RCTAssert.h"
#import "RCTBridge+Private.h"
#import "RCTBridge.h"
#import "RCTLog.h"
#import "RCTPerformanceLogger.h"
@@ -98,6 +99,11 @@ static RCTRootViewSizeFlexibility convertToRootViewSizeFlexibility(RCTSurfaceSiz
return _bridge != nil;
}
- (RCTModuleRegistry *)moduleRegistry
{
return _bridge.moduleRegistry;
}
RCT_NOT_IMPLEMENTED(-(instancetype)initWithFrame : (CGRect)frame)
RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)aDecoder)
+5
View File
@@ -244,6 +244,11 @@ struct RCTInstanceCallback : public InstanceCallback {
@synthesize performanceLogger = _performanceLogger;
@synthesize valid = _valid;
- (RCTModuleRegistry *)moduleRegistry
{
return _objCModuleRegistry;
}
- (void)setRCTTurboModuleRegistry:(id<RCTTurboModuleRegistry>)turboModuleRegistry
{
_turboModuleRegistry = turboModuleRegistry;