mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
c63ea4c3a0
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35138 Changelog: [General][Added] - Add a C++ only TurboModule example (for Android/iOS/macOS/Windows) react-native@0.69 introduced a new bridging layer to ease integration for pure C++ TurboModules using C++ std:: types directly instead of the lower level jsi:: types: https://github.com/facebook/react-native/tree/v0.69.0/ReactCommon/react/bridging This bridging layer can be used in JSI functions or more conveniently in C++ TurboModules. Here is a example of an C++ only TurboModule which will work on Android and iOS and macOS/Windows (using microsoft/react-native-macos|windows) only using flow/TypeScript and standard C++ types. C++ only TurboModules are very handy as they do not require to work with JSI APIs - instead std:: or custom C++ can by used. Reviewed By: javache Differential Revision: D39011736 fbshipit-source-id: 84c833d8540671fde8505f1aeb0265074b248730
38 lines
991 B
C++
38 lines
991 B
C++
/*
|
|
* 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 <react/bridging/Bridging.h>
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
namespace facebook::react {
|
|
|
|
struct ConstantsStruct {
|
|
bool const1;
|
|
int32_t const2;
|
|
std::string const3;
|
|
bool operator==(const ConstantsStruct &other) const {
|
|
return const1 == other.const1 && const2 == other.const2 &&
|
|
const3 == other.const3;
|
|
}
|
|
};
|
|
|
|
template <>
|
|
struct Bridging<ConstantsStruct> {
|
|
static jsi::Object toJs(jsi::Runtime &rt, const ConstantsStruct &value) {
|
|
auto result = facebook::jsi::Object(rt);
|
|
result.setProperty(rt, "const1", bridging::toJs(rt, value.const1));
|
|
result.setProperty(rt, "const2", bridging::toJs(rt, value.const2));
|
|
result.setProperty(rt, "const3", bridging::toJs(rt, value.const3));
|
|
return result;
|
|
}
|
|
};
|
|
|
|
} // namespace facebook::react
|