mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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:
committed by
Facebook GitHub Bot
parent
a909ba20db
commit
bfead74e69
@@ -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)
|
||||
|
||||
@@ -257,6 +257,11 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init)
|
||||
});
|
||||
}
|
||||
|
||||
- (RCTModuleRegistry *)moduleRegistry
|
||||
{
|
||||
return self.batchedBridge.moduleRegistry;
|
||||
}
|
||||
|
||||
- (NSArray<Class> *)moduleClasses
|
||||
{
|
||||
return self.batchedBridge.moduleClasses;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user