TurboModuleWithJSIBindings (#50106)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/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
This commit is contained in:
Zeya Peng
2025-03-20 14:49:29 -07:00
committed by Facebook GitHub Bot
parent ceff2e8c37
commit 1acd45950b
3 changed files with 54 additions and 0 deletions
@@ -20,6 +20,7 @@
#include <ReactCommon/TurboCxxModule.h>
#include <ReactCommon/TurboModuleBinding.h>
#include <ReactCommon/TurboModulePerfLogger.h>
#include <ReactCommon/TurboModuleWithJSIBindings.h>
#include <react/jni/CxxModuleWrapper.h>
namespace facebook::react {
@@ -165,6 +166,7 @@ std::shared_ptr<TurboModule> TurboModuleManager::getTurboModule(
auto cxxModule = cxxDelegate->getTurboModule(name, jsCallInvoker_);
if (cxxModule) {
TurboModuleWithJSIBindings::installJSIBindings(cxxModule, runtime);
turboModuleCache_.insert({name, cxxModule});
return cxxModule;
}
@@ -0,0 +1,23 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "TurboModuleWithJSIBindings.h"
#include <ReactCommon/TurboModule.h>
namespace facebook::react {
/* static */ void TurboModuleWithJSIBindings::installJSIBindings(
const std::shared_ptr<TurboModule>& cxxModule,
jsi::Runtime& runtime) {
if (auto* cxxModuleWithJSIBindings =
dynamic_cast<TurboModuleWithJSIBindings*>(cxxModule.get())) {
cxxModuleWithJSIBindings->installJSIBindingsWithRuntime(runtime);
}
}
} // namespace facebook::react
@@ -0,0 +1,29 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <ReactCommon/CallInvoker.h>
#include <jsi/jsi.h>
namespace facebook::react {
class TurboModule;
class TurboModuleWithJSIBindings {
public:
virtual ~TurboModuleWithJSIBindings() = default;
static void installJSIBindings(
const std::shared_ptr<TurboModule>& cxxModule,
jsi::Runtime& runtime);
private:
virtual void installJSIBindingsWithRuntime(jsi::Runtime& runtime) = 0;
};
} // namespace facebook::react