mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Use hasteModuleName for C++ Turbo Module structs (#44630)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44630 Changelog: [General][Breaking] Use hasteModuleName for C++ Turbo Module structs This changes the names of C++ Turbo Modules structs to use the `hasteModuleName`. Example: `NativeMyAbcModule.js` with this spec: ``` export type ValueStruct = { x: number, y: string, z: ObjectStruct, }; export interface Spec extends TurboModule { +getValueStruct: () => ValueStruct } export default (TurboModuleRegistry.get<Spec>('MyAbcModuleCxx'): ?Spec); ``` Before now we generated a base C++ struct with the name: ``` MyAbcModuleCxxValueStruct ^^^ ``` Now the generate name is: ``` NativeMyAbcModuleValueStruct ^^^^^^ ``` ## Changes: - No `Cxx` injected anymore - Ensure base struct is `Native` prefixed (all RN JS TM specs start with it) ## Why? - The `Cxx` extension is a temporary hint to react-native-codegen to enable extra capabilities and might disappear eventually - The C++ base struct name should be 'stable' - The name of the exported TM JS spec `TurboModuleRegistry.get<Spec>(...)` is abritrary, the hasteName is not - The name of the RN JS TM spec must start with `Native` which better guarantees a consistent naming scheme for these generated base class - The C++ Turbo Module base class has now the same prefix as the generated structs - `NativeMyAbcModule` for the example above Reviewed By: cipolleschi Differential Revision: D57599257 fbshipit-source-id: 4fafe6c7e920737fa766bd7e8e68e521f608e775
This commit is contained in:
committed by
Facebook GitHub Bot
parent
95de14dc53
commit
07261d0408
@@ -24,27 +24,27 @@ namespace facebook::react {
|
||||
|
||||
#pragma mark - Structs
|
||||
using ConstantsStruct =
|
||||
NativeCxxModuleExampleCxxConstantsStruct<bool, int32_t, std::string>;
|
||||
NativeCxxModuleExampleConstantsStruct<bool, int32_t, std::string>;
|
||||
|
||||
template <>
|
||||
struct Bridging<ConstantsStruct>
|
||||
: NativeCxxModuleExampleCxxConstantsStructBridging<ConstantsStruct> {};
|
||||
: NativeCxxModuleExampleConstantsStructBridging<ConstantsStruct> {};
|
||||
|
||||
using ObjectStruct = NativeCxxModuleExampleCxxObjectStruct<
|
||||
using ObjectStruct = NativeCxxModuleExampleObjectStruct<
|
||||
int32_t,
|
||||
std::string,
|
||||
std::optional<std::string>>;
|
||||
|
||||
template <>
|
||||
struct Bridging<ObjectStruct>
|
||||
: NativeCxxModuleExampleCxxObjectStructBridging<ObjectStruct> {};
|
||||
: NativeCxxModuleExampleObjectStructBridging<ObjectStruct> {};
|
||||
|
||||
using ValueStruct =
|
||||
NativeCxxModuleExampleCxxValueStruct<double, std::string, ObjectStruct>;
|
||||
NativeCxxModuleExampleValueStruct<double, std::string, ObjectStruct>;
|
||||
|
||||
template <>
|
||||
struct Bridging<ValueStruct>
|
||||
: NativeCxxModuleExampleCxxValueStructBridging<ValueStruct> {};
|
||||
: NativeCxxModuleExampleValueStructBridging<ValueStruct> {};
|
||||
|
||||
#pragma mark - enums
|
||||
enum class CustomEnumInt : int32_t { A = 23, B = 42 };
|
||||
@@ -93,39 +93,38 @@ using CustomHostObject = HostObjectWrapper<CustomHostObjectRef>;
|
||||
|
||||
#pragma mark - recursive objects
|
||||
|
||||
using BinaryTreeNode = NativeCxxModuleExampleCxxBinaryTreeNode<int32_t>;
|
||||
using BinaryTreeNode = NativeCxxModuleExampleBinaryTreeNode<int32_t>;
|
||||
|
||||
template <>
|
||||
struct Bridging<BinaryTreeNode>
|
||||
: NativeCxxModuleExampleCxxBinaryTreeNodeBridging<BinaryTreeNode> {};
|
||||
: NativeCxxModuleExampleBinaryTreeNodeBridging<BinaryTreeNode> {};
|
||||
|
||||
using GraphNode = NativeCxxModuleExampleCxxGraphNode<std::string>;
|
||||
using GraphNode = NativeCxxModuleExampleGraphNode<std::string>;
|
||||
|
||||
template <>
|
||||
struct Bridging<GraphNode>
|
||||
: NativeCxxModuleExampleCxxGraphNodeBridging<GraphNode> {};
|
||||
: NativeCxxModuleExampleGraphNodeBridging<GraphNode> {};
|
||||
|
||||
#pragma mark - functional object properties
|
||||
|
||||
using MenuItem = NativeCxxModuleExampleCxxMenuItem<
|
||||
using MenuItem = NativeCxxModuleExampleMenuItem<
|
||||
std::string,
|
||||
AsyncCallback<std::string, bool>,
|
||||
std::optional<std::string>>;
|
||||
|
||||
template <>
|
||||
struct Bridging<MenuItem>
|
||||
: NativeCxxModuleExampleCxxMenuItemBridging<MenuItem> {};
|
||||
struct Bridging<MenuItem> : NativeCxxModuleExampleMenuItemBridging<MenuItem> {};
|
||||
|
||||
#pragma mark - RCTDeviceEventEmitter events
|
||||
|
||||
using CustomDeviceEvent = NativeCxxModuleExampleCxxCustomDeviceEvent<
|
||||
using CustomDeviceEvent = NativeCxxModuleExampleCustomDeviceEvent<
|
||||
std::string,
|
||||
int32_t,
|
||||
std::optional<float>>;
|
||||
|
||||
template <>
|
||||
struct Bridging<CustomDeviceEvent>
|
||||
: NativeCxxModuleExampleCxxCustomDeviceEventBridging<CustomDeviceEvent> {};
|
||||
: NativeCxxModuleExampleCustomDeviceEventBridging<CustomDeviceEvent> {};
|
||||
|
||||
#pragma mark - implementation
|
||||
class NativeCxxModuleExample
|
||||
|
||||
Reference in New Issue
Block a user