iOS: allow getting an instance of a js-bound module via the bridge

Reviewed By: sebmarkbage

Differential Revision: D6982785

fbshipit-source-id: 7bbcc5416e1d1a3a577328349a7c18af5c0f8577
This commit is contained in:
Kevin Gozali 2018-02-13 22:26:43 -08:00 committed by Facebook Github Bot
parent 1aeb9250bd
commit 5f48bd84aa
6 changed files with 42 additions and 0 deletions

View File

@ -168,6 +168,11 @@ RCT_EXTERN NSString *RCTBridgeModuleNameForClass(Class bridgeModuleClass);
*/
- (BOOL)moduleIsInitialized:(Class)moduleClass;
/**
* Retrieve an extra module that gets bound to the JS context, if any.
*/
- (id)jsBoundExtraModuleForClass:(Class)moduleClass;
/**
* All registered bridge module classes.
*/

View File

@ -251,6 +251,11 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
return [self.batchedBridge moduleIsInitialized:moduleClass];
}
- (id)jsBoundExtraModuleForClass:(Class)moduleClass
{
return [self.batchedBridge jsBoundExtraModuleForClass:moduleClass];
}
- (void)reload
{
#if RCT_ENABLE_INSPECTOR

View File

@ -454,6 +454,18 @@ struct RCTInstanceCallback : public InstanceCallback {
return _moduleDataByName[RCTBridgeModuleNameForClass(moduleClass)].hasInstance;
}
- (id)jsBoundExtraModuleForClass:(Class)moduleClass
{
if ([self.delegate conformsToProtocol:@protocol(RCTCxxBridgeDelegate)]) {
id<RCTCxxBridgeDelegate> cxxDelegate = (id<RCTCxxBridgeDelegate>) self.delegate;
if ([cxxDelegate respondsToSelector:@selector(jsBoundExtraModuleForClass:)]) {
return [cxxDelegate jsBoundExtraModuleForClass:moduleClass];
}
}
return nil;
}
- (std::shared_ptr<ModuleRegistry>)_buildModuleRegistry
{
if (!self.valid) {

View File

@ -40,4 +40,9 @@ class JSExecutorFactory;
*/
- (void)installExtraJSBinding:(JSGlobalContextRef)jsContextRef;
/**
* Experimental: Get the instance of the extra module/class which gets bound via `installExtraJSBinding:`
*/
- (id)jsBoundExtraModuleForClass:(Class)moduleClass;
@end

View File

@ -42,3 +42,9 @@
childSet:(NSArray<RCTShadowView *> *)childSet;
@end
@interface RCTBridge (RCTFabricUIManager)
@property (nonatomic, readonly) RCTFabricUIManager *fabricUIManager;
@end

View File

@ -72,3 +72,12 @@
}
@end
@implementation RCTBridge (RCTFabricUIManager)
- (RCTFabricUIManager *)fabricUIManager
{
return [self jsBoundExtraModuleForClass:[RCTFabricUIManager class]];
}
@end