mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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:
committed by
Facebook GitHub Bot
parent
ceff2e8c37
commit
1acd45950b
+2
@@ -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;
|
||||
}
|
||||
|
||||
+23
@@ -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
|
||||
+29
@@ -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
|
||||
Reference in New Issue
Block a user