Skip to content

Commit 8a50bc3

Browse files
fkgozalifacebook-github-bot
authored andcommitted
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
1 parent bbcb97a commit 8a50bc3

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

React/Base/RCTBridgeModule.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ RCT_EXTERN void RCTRegisterModule(Class); \
326326
* Experimental.
327327
* A protocol to declare that a class supports TurboModule.
328328
* This may be removed in the future.
329+
* See RCTTurboModule.h for actual signature.
329330
*/
330-
@protocol RCTTurboModule <NSObject>
331-
332-
@end
331+
@protocol RCTTurboModule;

ReactCommon/turbomodule/core/platform/ios/RCTTurboModule.h

+8-9
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,18 @@ class JSI_EXPORT ObjCTurboModule : public TurboModule {
3838
} // namespace react
3939
} // namespace facebook
4040

41-
// TODO: Consolidate this extension with the one in RCTSurfacePresenter.
42-
@interface RCTBridge ()
41+
@protocol RCTTurboModule <NSObject>
4342

44-
- (std::shared_ptr<facebook::react::MessageQueueThread>)jsMessageThread;
43+
@optional
44+
45+
// This should be required, after migration is done.
46+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::JSCallInvoker>)jsInvoker;
4547

4648
@end
4749

48-
/**
49-
* A backward-compatible protocol to be adopted by an existing RCTCxxModule-based class
50-
* so that it can support the TurboModule system.
51-
*/
52-
@protocol RCTTurboCxxModule <RCTTurboModule>
50+
// TODO: Consolidate this extension with the one in RCTSurfacePresenter.
51+
@interface RCTBridge ()
5352

54-
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::JSCallInvoker>)jsInvoker;
53+
- (std::shared_ptr<facebook::react::MessageQueueThread>)jsMessageThread;
5554

5655
@end

ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm

+5-4
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,18 @@ - (instancetype)initWithRuntime:(jsi::Runtime *)runtime
111111
}
112112
}
113113

114+
if ([module respondsToSelector:@selector(getTurboModuleWithJsInvoker:)]) {
115+
return [module getTurboModuleWithJsInvoker:strongSelf->_jsInvoker];
116+
}
117+
114118
// RCTCxxModule compatibility layer.
115119
if ([moduleClass isSubclassOfClass:RCTCxxModule.class]) {
116-
if ([module respondsToSelector:@selector(getTurboModuleWithJsInvoker:)]) {
117-
return [((id<RCTTurboCxxModule>)module) getTurboModuleWithJsInvoker:strongSelf->_jsInvoker];
118-
}
119-
120120
// Use TurboCxxModule compat class to wrap the CxxModule instance.
121121
// This is only for migration convenience, despite less performant.
122122
return std::make_shared<react::TurboCxxModule>([((RCTCxxModule *)module) createModule], strongSelf->_jsInvoker);
123123
}
124124

125+
// This may be needed for migration purpose in case the module class doesn't provide the static getter.
125126
return [strongSelf->_delegate getTurboModule:name instance:module jsInvoker:strongSelf->_jsInvoker];
126127
};
127128

0 commit comments

Comments
 (0)