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:
parent
1aeb9250bd
commit
5f48bd84aa
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -42,3 +42,9 @@
|
|||
childSet:(NSArray<RCTShadowView *> *)childSet;
|
||||
|
||||
@end
|
||||
|
||||
@interface RCTBridge (RCTFabricUIManager)
|
||||
|
||||
@property (nonatomic, readonly) RCTFabricUIManager *fabricUIManager;
|
||||
|
||||
@end
|
||||
|
|
|
@ -72,3 +72,12 @@
|
|||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTBridge (RCTFabricUIManager)
|
||||
|
||||
- (RCTFabricUIManager *)fabricUIManager
|
||||
{
|
||||
return [self jsBoundExtraModuleForClass:[RCTFabricUIManager class]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue