Skip to content

Commit 1acd459

Browse files
zeyapfacebook-github-bot
authored andcommitted
TurboModuleWithJSIBindings (#50106)
Summary: Pull Request resolved: #50106 ## Changelog: [General] [Added] - Create TurboModuleWithJSIBindings interface So c++ TurboModules can initialize some private members with reference to `jsi::Runtime` Reviewed By: lenaic Differential Revision: D71396842 fbshipit-source-id: 59d32e4cbf2c5081912a4c828acc66ceb8702855
1 parent ceff2e8 commit 1acd459

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

packages/react-native/ReactAndroid/src/main/jni/react/turbomodule/ReactCommon/TurboModuleManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <ReactCommon/TurboCxxModule.h>
2121
#include <ReactCommon/TurboModuleBinding.h>
2222
#include <ReactCommon/TurboModulePerfLogger.h>
23+
#include <ReactCommon/TurboModuleWithJSIBindings.h>
2324
#include <react/jni/CxxModuleWrapper.h>
2425

2526
namespace facebook::react {
@@ -165,6 +166,7 @@ std::shared_ptr<TurboModule> TurboModuleManager::getTurboModule(
165166

166167
auto cxxModule = cxxDelegate->getTurboModule(name, jsCallInvoker_);
167168
if (cxxModule) {
169+
TurboModuleWithJSIBindings::installJSIBindings(cxxModule, runtime);
168170
turboModuleCache_.insert({name, cxxModule});
169171
return cxxModule;
170172
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include "TurboModuleWithJSIBindings.h"
9+
10+
#include <ReactCommon/TurboModule.h>
11+
12+
namespace facebook::react {
13+
14+
/* static */ void TurboModuleWithJSIBindings::installJSIBindings(
15+
const std::shared_ptr<TurboModule>& cxxModule,
16+
jsi::Runtime& runtime) {
17+
if (auto* cxxModuleWithJSIBindings =
18+
dynamic_cast<TurboModuleWithJSIBindings*>(cxxModule.get())) {
19+
cxxModuleWithJSIBindings->installJSIBindingsWithRuntime(runtime);
20+
}
21+
}
22+
23+
} // namespace facebook::react
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <ReactCommon/CallInvoker.h>
11+
#include <jsi/jsi.h>
12+
13+
namespace facebook::react {
14+
15+
class TurboModule;
16+
17+
class TurboModuleWithJSIBindings {
18+
public:
19+
virtual ~TurboModuleWithJSIBindings() = default;
20+
21+
static void installJSIBindings(
22+
const std::shared_ptr<TurboModule>& cxxModule,
23+
jsi::Runtime& runtime);
24+
25+
private:
26+
virtual void installJSIBindingsWithRuntime(jsi::Runtime& runtime) = 0;
27+
};
28+
29+
} // namespace facebook::react

0 commit comments

Comments
 (0)