iOS: Make each module implement getTurboModuleWithJsInvoker: instead of having centralized provider
Summary: For better modularity, each module conforming to RCTTurboModule should provide a getter for the specific TurboModule instance for itself. This is a bit more extra work for devs, but simplify tooling and allow better modularity vs having a central function that provides the correct instance based on name. Note: Android may or may not follow this new pattern -- TBD. Reviewed By: RSNara Differential Revision: D13882073 fbshipit-source-id: 6d5f82af67278c39c43c4f7970995690d4a82a98
This commit is contained in:
parent
bbcb97a29a
commit
8a50bc3ab3
|
@ -326,7 +326,6 @@ RCT_EXTERN void RCTRegisterModule(Class); \
|
|||
* Experimental.
|
||||
* A protocol to declare that a class supports TurboModule.
|
||||
* This may be removed in the future.
|
||||
* See RCTTurboModule.h for actual signature.
|
||||
*/
|
||||
@protocol RCTTurboModule <NSObject>
|
||||
|
||||
@end
|
||||
@protocol RCTTurboModule;
|
||||
|
|
|
@ -38,19 +38,18 @@ public:
|
|||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
@protocol RCTTurboModule <NSObject>
|
||||
|
||||
@optional
|
||||
|
||||
// This should be required, after migration is done.
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::JSCallInvoker>)jsInvoker;
|
||||
|
||||
@end
|
||||
|
||||
// TODO: Consolidate this extension with the one in RCTSurfacePresenter.
|
||||
@interface RCTBridge ()
|
||||
|
||||
- (std::shared_ptr<facebook::react::MessageQueueThread>)jsMessageThread;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
* A backward-compatible protocol to be adopted by an existing RCTCxxModule-based class
|
||||
* so that it can support the TurboModule system.
|
||||
*/
|
||||
@protocol RCTTurboCxxModule <RCTTurboModule>
|
||||
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::JSCallInvoker>)jsInvoker;
|
||||
|
||||
@end
|
||||
|
|
|
@ -111,17 +111,18 @@ static Class getFallbackClassFromName(const char *name) {
|
|||
}
|
||||
}
|
||||
|
||||
if ([module respondsToSelector:@selector(getTurboModuleWithJsInvoker:)]) {
|
||||
return [module getTurboModuleWithJsInvoker:strongSelf->_jsInvoker];
|
||||
}
|
||||
|
||||
// RCTCxxModule compatibility layer.
|
||||
if ([moduleClass isSubclassOfClass:RCTCxxModule.class]) {
|
||||
if ([module respondsToSelector:@selector(getTurboModuleWithJsInvoker:)]) {
|
||||
return [((id<RCTTurboCxxModule>)module) getTurboModuleWithJsInvoker:strongSelf->_jsInvoker];
|
||||
}
|
||||
|
||||
// Use TurboCxxModule compat class to wrap the CxxModule instance.
|
||||
// This is only for migration convenience, despite less performant.
|
||||
return std::make_shared<react::TurboCxxModule>([((RCTCxxModule *)module) createModule], strongSelf->_jsInvoker);
|
||||
}
|
||||
|
||||
// This may be needed for migration purpose in case the module class doesn't provide the static getter.
|
||||
return [strongSelf->_delegate getTurboModule:name instance:module jsInvoker:strongSelf->_jsInvoker];
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue