Skip to content

Commit 878eac2

Browse files
christophpurrerkosmydel
authored andcommitted
Use hasteModuleName for C++ Turbo Module structs (facebook#44630)
Summary: Pull Request resolved: facebook#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
1 parent 9292cf9 commit 878eac2

7 files changed

Lines changed: 121 additions & 124 deletions

File tree

packages/react-native-codegen/e2e/__tests__/modules/__snapshots__/GenerateModuleH-test.js.snap

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -923,18 +923,18 @@ private:
923923

924924

925925

926-
#pragma mark - SampleTurboModuleAnimal
926+
#pragma mark - NativeSampleTurboModuleAnimal
927927

928928
template <typename P0>
929-
struct SampleTurboModuleAnimal {
929+
struct NativeSampleTurboModuleAnimal {
930930
P0 name;
931-
bool operator==(const SampleTurboModuleAnimal &other) const {
931+
bool operator==(const NativeSampleTurboModuleAnimal &other) const {
932932
return name == other.name;
933933
}
934934
};
935935

936936
template <typename T>
937-
struct SampleTurboModuleAnimalBridging {
937+
struct NativeSampleTurboModuleAnimalBridging {
938938
static T types;
939939

940940
static T fromJs(
@@ -1117,18 +1117,18 @@ private:
11171117

11181118

11191119

1120-
#pragma mark - SampleTurboModuleArraysAnimal
1120+
#pragma mark - NativeSampleTurboModuleArraysAnimal
11211121

11221122
template <typename P0>
1123-
struct SampleTurboModuleArraysAnimal {
1123+
struct NativeSampleTurboModuleArraysAnimal {
11241124
P0 name;
1125-
bool operator==(const SampleTurboModuleArraysAnimal &other) const {
1125+
bool operator==(const NativeSampleTurboModuleArraysAnimal &other) const {
11261126
return name == other.name;
11271127
}
11281128
};
11291129

11301130
template <typename T>
1131-
struct SampleTurboModuleArraysAnimalBridging {
1131+
struct NativeSampleTurboModuleArraysAnimalBridging {
11321132
static T types;
11331133

11341134
static T fromJs(
@@ -1311,18 +1311,18 @@ private:
13111311

13121312

13131313

1314-
#pragma mark - SampleTurboModuleNullableAnimal
1314+
#pragma mark - NativeSampleTurboModuleNullableAnimal
13151315

13161316
template <typename P0>
1317-
struct SampleTurboModuleNullableAnimal {
1317+
struct NativeSampleTurboModuleNullableAnimal {
13181318
P0 name;
1319-
bool operator==(const SampleTurboModuleNullableAnimal &other) const {
1319+
bool operator==(const NativeSampleTurboModuleNullableAnimal &other) const {
13201320
return name == other.name;
13211321
}
13221322
};
13231323

13241324
template <typename T>
1325-
struct SampleTurboModuleNullableAnimalBridging {
1325+
struct NativeSampleTurboModuleNullableAnimalBridging {
13261326
static T types;
13271327

13281328
static T fromJs(
@@ -1505,18 +1505,18 @@ private:
15051505

15061506

15071507

1508-
#pragma mark - SampleTurboModuleNullableAndOptionalAnimal
1508+
#pragma mark - NativeSampleTurboModuleNullableAndOptionalAnimal
15091509

15101510
template <typename P0>
1511-
struct SampleTurboModuleNullableAndOptionalAnimal {
1511+
struct NativeSampleTurboModuleNullableAndOptionalAnimal {
15121512
P0 name;
1513-
bool operator==(const SampleTurboModuleNullableAndOptionalAnimal &other) const {
1513+
bool operator==(const NativeSampleTurboModuleNullableAndOptionalAnimal &other) const {
15141514
return name == other.name;
15151515
}
15161516
};
15171517

15181518
template <typename T>
1519-
struct SampleTurboModuleNullableAndOptionalAnimalBridging {
1519+
struct NativeSampleTurboModuleNullableAndOptionalAnimalBridging {
15201520
static T types;
15211521

15221522
static T fromJs(
@@ -1701,18 +1701,18 @@ private:
17011701

17021702

17031703

1704-
#pragma mark - SampleTurboModuleOptionalAnimal
1704+
#pragma mark - NativeSampleTurboModuleOptionalAnimal
17051705

17061706
template <typename P0>
1707-
struct SampleTurboModuleOptionalAnimal {
1707+
struct NativeSampleTurboModuleOptionalAnimal {
17081708
P0 name;
1709-
bool operator==(const SampleTurboModuleOptionalAnimal &other) const {
1709+
bool operator==(const NativeSampleTurboModuleOptionalAnimal &other) const {
17101710
return name == other.name;
17111711
}
17121712
};
17131713

17141714
template <typename T>
1715-
struct SampleTurboModuleOptionalAnimalBridging {
1715+
struct NativeSampleTurboModuleOptionalAnimalBridging {
17161716
static T types;
17171717

17181718
static T fromJs(
@@ -2877,18 +2877,18 @@ private:
28772877

28782878

28792879

2880-
#pragma mark - SampleTurboModuleAnimal
2880+
#pragma mark - NativeSampleTurboModuleAnimal
28812881

28822882
template <typename P0>
2883-
struct SampleTurboModuleAnimal {
2883+
struct NativeSampleTurboModuleAnimal {
28842884
P0 name;
2885-
bool operator==(const SampleTurboModuleAnimal &other) const {
2885+
bool operator==(const NativeSampleTurboModuleAnimal &other) const {
28862886
return name == other.name;
28872887
}
28882888
};
28892889

28902890
template <typename T>
2891-
struct SampleTurboModuleAnimalBridging {
2891+
struct NativeSampleTurboModuleAnimalBridging {
28922892
static T types;
28932893

28942894
static T fromJs(
@@ -3071,18 +3071,18 @@ private:
30713071

30723072

30733073

3074-
#pragma mark - SampleTurboModuleArraysAnimal
3074+
#pragma mark - NativeSampleTurboModuleArraysAnimal
30753075

30763076
template <typename P0>
3077-
struct SampleTurboModuleArraysAnimal {
3077+
struct NativeSampleTurboModuleArraysAnimal {
30783078
P0 name;
3079-
bool operator==(const SampleTurboModuleArraysAnimal &other) const {
3079+
bool operator==(const NativeSampleTurboModuleArraysAnimal &other) const {
30803080
return name == other.name;
30813081
}
30823082
};
30833083

30843084
template <typename T>
3085-
struct SampleTurboModuleArraysAnimalBridging {
3085+
struct NativeSampleTurboModuleArraysAnimalBridging {
30863086
static T types;
30873087

30883088
static T fromJs(
@@ -3265,18 +3265,18 @@ private:
32653265

32663266

32673267

3268-
#pragma mark - SampleTurboModuleNullableAnimal
3268+
#pragma mark - NativeSampleTurboModuleNullableAnimal
32693269

32703270
template <typename P0>
3271-
struct SampleTurboModuleNullableAnimal {
3271+
struct NativeSampleTurboModuleNullableAnimal {
32723272
P0 name;
3273-
bool operator==(const SampleTurboModuleNullableAnimal &other) const {
3273+
bool operator==(const NativeSampleTurboModuleNullableAnimal &other) const {
32743274
return name == other.name;
32753275
}
32763276
};
32773277

32783278
template <typename T>
3279-
struct SampleTurboModuleNullableAnimalBridging {
3279+
struct NativeSampleTurboModuleNullableAnimalBridging {
32803280
static T types;
32813281

32823282
static T fromJs(
@@ -3459,18 +3459,18 @@ private:
34593459

34603460

34613461

3462-
#pragma mark - SampleTurboModuleNullableAndOptionalAnimal
3462+
#pragma mark - NativeSampleTurboModuleNullableAndOptionalAnimal
34633463

34643464
template <typename P0>
3465-
struct SampleTurboModuleNullableAndOptionalAnimal {
3465+
struct NativeSampleTurboModuleNullableAndOptionalAnimal {
34663466
P0 name;
3467-
bool operator==(const SampleTurboModuleNullableAndOptionalAnimal &other) const {
3467+
bool operator==(const NativeSampleTurboModuleNullableAndOptionalAnimal &other) const {
34683468
return name == other.name;
34693469
}
34703470
};
34713471

34723472
template <typename T>
3473-
struct SampleTurboModuleNullableAndOptionalAnimalBridging {
3473+
struct NativeSampleTurboModuleNullableAndOptionalAnimalBridging {
34743474
static T types;
34753475

34763476
static T fromJs(
@@ -3655,18 +3655,18 @@ private:
36553655

36563656

36573657

3658-
#pragma mark - SampleTurboModuleOptionalAnimal
3658+
#pragma mark - NativeSampleTurboModuleOptionalAnimal
36593659

36603660
template <typename P0>
3661-
struct SampleTurboModuleOptionalAnimal {
3661+
struct NativeSampleTurboModuleOptionalAnimal {
36623662
P0 name;
3663-
bool operator==(const SampleTurboModuleOptionalAnimal &other) const {
3663+
bool operator==(const NativeSampleTurboModuleOptionalAnimal &other) const {
36643664
return name == other.name;
36653665
}
36663666
};
36673667

36683668
template <typename T>
3669-
struct SampleTurboModuleOptionalAnimalBridging {
3669+
struct NativeSampleTurboModuleOptionalAnimalBridging {
36703670
static T types;
36713671

36723672
static T fromJs(

packages/react-native-codegen/src/generators/modules/GenerateModuleH.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ function translatePrimitiveJSTypeToCpp(
211211
}
212212

213213
function createStructsString(
214-
moduleName: string,
214+
hasteModuleName: string,
215215
aliasMap: NativeModuleAliasMap,
216216
resolveAlias: AliasResolver,
217217
enumMap: NativeModuleEnumMap,
@@ -221,7 +221,7 @@ function createStructsString(
221221
v: NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>,
222222
) =>
223223
translatePrimitiveJSTypeToCpp(
224-
moduleName,
224+
hasteModuleName,
225225
parentObjectAlias,
226226
v.typeAnnotation,
227227
false,
@@ -236,7 +236,7 @@ function createStructsString(
236236
if (value.properties.length === 0) {
237237
return '';
238238
}
239-
const structName = `${moduleName}${alias}`;
239+
const structName = `${hasteModuleName}${alias}`;
240240
const templateParameter = value.properties.filter(
241241
v =>
242242
!isDirectRecursiveMember(alias, v.typeAnnotation) &&
@@ -530,7 +530,7 @@ module.exports = {
530530
} = nativeModules[hasteModuleName];
531531
const resolveAlias = createAliasResolver(aliasMap);
532532
const structs = createStructsString(
533-
moduleName,
533+
hasteModuleName,
534534
aliasMap,
535535
resolveAlias,
536536
enumMap,

0 commit comments

Comments
 (0)