File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed
ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/ReactCommon
ReactCommon/turbomodule/core/platform/ios Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -56,20 +56,30 @@ void TurboModuleManager::installJSIBindings() {
5656 }
5757 TurboModuleBinding::install (*runtime_, std::make_shared<TurboModuleBinding>(
5858 [this ](const std::string &name) -> std::shared_ptr<TurboModule> {
59+ auto turboModuleLookup = turboModuleCache_.find (name);
60+ if (turboModuleLookup != turboModuleCache_.end ()) {
61+ return turboModuleLookup->second ;
62+ }
63+
5964 auto cxxModule = turboModuleManagerDelegate_->cthis ()->getTurboModule (name, jsCallInvoker_);
6065 if (cxxModule) {
66+ turboModuleCache_.insert ({name, cxxModule});
6167 return cxxModule;
6268 }
6369
6470 auto legacyCxxModule = getLegacyCxxJavaModule (name);
6571 if (legacyCxxModule) {
66- return std::make_shared<react::TurboCxxModule>(legacyCxxModule->cthis ()->getModule (), jsCallInvoker_);
72+ auto turboModule = std::make_shared<react::TurboCxxModule>(legacyCxxModule->cthis ()->getModule (), jsCallInvoker_);
73+ turboModuleCache_.insert ({name, turboModule});
74+ return turboModule;
6775 }
6876
6977 auto moduleInstance = getJavaModule (name);
7078
7179 if (moduleInstance) {
72- return turboModuleManagerDelegate_->cthis ()->getTurboModule (name, moduleInstance, jsCallInvoker_);
80+ auto turboModule = turboModuleManagerDelegate_->cthis ()->getTurboModule (name, moduleInstance, jsCallInvoker_);
81+ turboModuleCache_.insert ({name, turboModule});
82+ return turboModule;
7383 }
7484
7585 return std::shared_ptr<TurboModule>(nullptr );
Original file line number Diff line number Diff line change 88#pragma once
99
1010#include < memory>
11+ #include < unordered_map>
1112#include < fb/fbjni.h>
1213#include < jsi/jsi.h>
1314#include < ReactCommon/TurboModule.h>
@@ -37,6 +38,14 @@ class TurboModuleManager : public jni::HybridClass<TurboModuleManager> {
3738 std::shared_ptr<JSCallInvoker> jsCallInvoker_;
3839 jni::global_ref<TurboModuleManagerDelegate::javaobject> turboModuleManagerDelegate_;
3940
41+ /* *
42+ * TODO(T48018690):
43+ * All modules are currently long-lived.
44+ * We need to come up with a mechanism to allow modules to specify whether
45+ * they want to be long-lived or short-lived.
46+ */
47+ std::unordered_map<std::string, std::shared_ptr<react::TurboModule>> turboModuleCache_;
48+
4049 jni::global_ref<JTurboModule> getJavaModule (std::string name);
4150 jni::global_ref<CxxModuleWrapper::javaobject> getLegacyCxxJavaModule (std::string name);
4251 void installJSIBindings ();
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ @implementation RCTTurboModuleManager {
4040 __weak id <RCTTurboModuleManagerDelegate> _delegate;
4141 __weak RCTBridge *_bridge;
4242 /* *
43- * TODO(rsnara ):
43+ * TODO(T48018690 ):
4444 * All modules are currently long-lived.
4545 * We need to come up with a mechanism to allow modules to specify whether
4646 * they want to be long-lived or short-lived.
You can’t perform that action at this time.
0 commit comments