Skip to content

Commit c7a6935

Browse files
christophpurrermeta-codesync[bot]
authored andcommitted
Default init custom C++ TM struct properties (#54391)
Summary: Pull Request resolved: #54391 Changelog: [Internal][Fixed] Default init custom C++ TM struct properties Right now we don't do it and produce code as: ``` template <typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> struct NativeEditableObjectModulePropertyVal { P0 classOrList; P1 commonFields; P2 desc; P3 isDefault; P4 isSet; P5 scriptValue; P6 value; bool operator==(const NativeEditableObjectModulePropertyVal &other) const { return classOrList == other.classOrList && commonFields == other.commonFields && desc == other.desc && isDefault == other.isDefault && isSet == other.isSet && scriptValue == other.scriptValue && value == other.value; } }; ``` Now we do: ``` template <typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> struct NativeEditableObjectModulePropertyVal { P0 classOrList{}; P1 commonFields{}; P2 desc{}; P3 isDefault{}; P4 isSet{}; P5 scriptValue{}; P6 value{}; bool operator==(const NativeEditableObjectModulePropertyVal &other) const { return classOrList == other.classOrList && commonFields == other.commonFields && desc == other.desc && isDefault == other.isDefault && isSet == other.isSet && scriptValue == other.scriptValue && value == other.value; } }; ``` Reviewed By: sbuggay, lenaic Differential Revision: D86142954 fbshipit-source-id: 989e81c55b1fad7e1e58ea89461f064772143c9d
1 parent 8fa8fb7 commit c7a6935

File tree

3 files changed

+52
-52
lines changed

3 files changed

+52
-52
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ struct NativeEnumTurboModuleStateTypeBridging {
290290

291291
template <typename P0, typename P1, typename P2, typename P3, typename P4>
292292
struct NativeEnumTurboModuleStateTypeWithEnums {
293-
P0 state;
294-
P1 regular;
295-
P2 str;
296-
P3 num;
293+
P0 state{};
294+
P1 regular{};
295+
P2 str{};
296+
P3 num{};
297297
P4 lowerCase;
298298
bool operator==(const NativeEnumTurboModuleStateTypeWithEnums &other) const {
299299
return state == other.state && regular == other.regular && str == other.str && num == other.num && lowerCase == other.lowerCase;
@@ -594,7 +594,7 @@ private:
594594

595595
template <typename P0, typename P1>
596596
struct NativePartialAnnotationTurboModuleSomeObj {
597-
P0 a;
597+
P0 a{};
598598
P1 b;
599599
bool operator==(const NativePartialAnnotationTurboModuleSomeObj &other) const {
600600
return a == other.a && b == other.b;
@@ -1887,10 +1887,10 @@ struct NativeEnumTurboModuleStateTypeBridging {
18871887

18881888
template <typename P0, typename P1, typename P2, typename P3, typename P4>
18891889
struct NativeEnumTurboModuleStateTypeWithEnums {
1890-
P0 state;
1891-
P1 regular;
1892-
P2 str;
1893-
P3 num;
1890+
P0 state{};
1891+
P1 regular{};
1892+
P2 str{};
1893+
P3 num{};
18941894
P4 lowerCase;
18951895
bool operator==(const NativeEnumTurboModuleStateTypeWithEnums &other) const {
18961896
return state == other.state && regular == other.regular && str == other.str && num == other.num && lowerCase == other.lowerCase;
@@ -2191,7 +2191,7 @@ private:
21912191

21922192
template <typename P0, typename P1>
21932193
struct NativePartialAnnotationTurboModuleSomeObj {
2194-
P0 a;
2194+
P0 a{};
21952195
P1 b;
21962196
bool operator==(const NativePartialAnnotationTurboModuleSomeObj &other) const {
21972197
return a == other.a && b == other.b;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ function createStructsString(
374374
375375
template <${templateParameterWithTypename}>
376376
struct ${structName} {
377-
${templateMemberTypes.map(v => ' ' + v).join(';\n')};
377+
${templateMemberTypes.map(v => ' ' + v).join('{};\n')};
378378
bool operator==(const ${structName} &other) const {
379379
return ${value.properties
380380
.map(v => `${v.name} == other.${v.name}`)

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

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ struct Bridging<NativeSampleTurboModuleEnumStr> {
269269

270270
template <typename P0, typename P1, typename P2>
271271
struct NativeSampleTurboModuleConstantsStruct {
272-
P0 const1;
273-
P1 const2;
272+
P0 const1{};
273+
P1 const2{};
274274
P2 const3;
275275
bool operator==(const NativeSampleTurboModuleConstantsStruct &other) const {
276276
return const1 == other.const1 && const2 == other.const2 && const3 == other.const3;
@@ -323,8 +323,8 @@ struct NativeSampleTurboModuleConstantsStructBridging {
323323

324324
template <typename P0>
325325
struct NativeSampleTurboModuleBinaryTreeNode {
326-
std::unique_ptr<NativeSampleTurboModuleBinaryTreeNode<P0>> left;
327-
P0 value;
326+
std::unique_ptr<NativeSampleTurboModuleBinaryTreeNode<P0>> left{};
327+
P0 value{};
328328
std::unique_ptr<NativeSampleTurboModuleBinaryTreeNode<P0>> right;
329329
bool operator==(const NativeSampleTurboModuleBinaryTreeNode &other) const {
330330
return left == other.left && value == other.value && right == other.right;
@@ -380,7 +380,7 @@ struct NativeSampleTurboModuleBinaryTreeNodeBridging {
380380

381381
template <typename P0>
382382
struct NativeSampleTurboModuleGraphNode {
383-
P0 label;
383+
P0 label{};
384384
std::optional<std::vector<NativeSampleTurboModuleGraphNode<P0>>> neighbors;
385385
bool operator==(const NativeSampleTurboModuleGraphNode &other) const {
386386
return label == other.label && neighbors == other.neighbors;
@@ -429,8 +429,8 @@ struct NativeSampleTurboModuleGraphNodeBridging {
429429

430430
template <typename P0, typename P1, typename P2>
431431
struct NativeSampleTurboModuleObjectStruct {
432-
P0 a;
433-
P1 b;
432+
P0 a{};
433+
P1 b{};
434434
P2 c;
435435
bool operator==(const NativeSampleTurboModuleObjectStruct &other) const {
436436
return a == other.a && b == other.b && c == other.c;
@@ -484,8 +484,8 @@ struct NativeSampleTurboModuleObjectStructBridging {
484484

485485
template <typename P0, typename P1, typename P2>
486486
struct NativeSampleTurboModuleValueStruct {
487-
P0 x;
488-
P1 y;
487+
P0 x{};
488+
P1 y{};
489489
P2 z;
490490
bool operator==(const NativeSampleTurboModuleValueStruct &other) const {
491491
return x == other.x && y == other.y && z == other.z;
@@ -537,9 +537,9 @@ struct NativeSampleTurboModuleValueStructBridging {
537537

538538
template <typename P0, typename P1, typename P2>
539539
struct NativeSampleTurboModuleMenuItem {
540-
P0 label;
541-
P1 onPress;
542-
P2 shortcut;
540+
P0 label{};
541+
P1 onPress{};
542+
P2 shortcut{};
543543
std::optional<std::vector<NativeSampleTurboModuleMenuItem<P0, P1, P2>>> items;
544544
bool operator==(const NativeSampleTurboModuleMenuItem &other) const {
545545
return label == other.label && onPress == other.onPress && shortcut == other.shortcut && items == other.items;
@@ -915,8 +915,8 @@ namespace facebook::react {
915915

916916
template <typename P0, typename P1, typename P2>
917917
struct NativeSampleTurboModuleObjectStruct {
918-
P0 a;
919-
P1 b;
918+
P0 a{};
919+
P1 b{};
920920
P2 c;
921921
bool operator==(const NativeSampleTurboModuleObjectStruct &other) const {
922922
return a == other.a && b == other.b && c == other.c;
@@ -1056,10 +1056,10 @@ namespace facebook::react {
10561056

10571057
template <typename P0, typename P1, typename P2, typename P3, typename P4>
10581058
struct AliasTurboModuleOptions {
1059-
P0 offset;
1060-
P1 size;
1061-
P2 displaySize;
1062-
P3 resizeMode;
1059+
P0 offset{};
1060+
P1 size{};
1061+
P2 displaySize{};
1062+
P3 resizeMode{};
10631063
P4 allowExternalStorage;
10641064
bool operator==(const AliasTurboModuleOptions &other) const {
10651065
return offset == other.offset && size == other.size && displaySize == other.displaySize && resizeMode == other.resizeMode && allowExternalStorage == other.allowExternalStorage;
@@ -1178,11 +1178,11 @@ namespace facebook::react {
11781178

11791179
template <typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>
11801180
struct NativeCameraRollManagerPhotoIdentifierImage {
1181-
P0 uri;
1182-
P1 playableDuration;
1183-
P2 width;
1184-
P3 height;
1185-
P4 isStored;
1181+
P0 uri{};
1182+
P1 playableDuration{};
1183+
P2 width{};
1184+
P3 height{};
1185+
P4 isStored{};
11861186
P5 filename;
11871187
bool operator==(const NativeCameraRollManagerPhotoIdentifierImage &other) const {
11881188
return uri == other.uri && playableDuration == other.playableDuration && width == other.width && height == other.height && isStored == other.isStored && filename == other.filename;
@@ -1292,7 +1292,7 @@ struct NativeCameraRollManagerPhotoIdentifierBridging {
12921292

12931293
template <typename P0, typename P1>
12941294
struct NativeCameraRollManagerPhotoIdentifiersPage {
1295-
P0 edges;
1295+
P0 edges{};
12961296
P1 page_info;
12971297
bool operator==(const NativeCameraRollManagerPhotoIdentifiersPage &other) const {
12981298
return edges == other.edges && page_info == other.page_info;
@@ -1339,12 +1339,12 @@ struct NativeCameraRollManagerPhotoIdentifiersPageBridging {
13391339

13401340
template <typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
13411341
struct NativeCameraRollManagerGetPhotosParams {
1342-
P0 first;
1343-
P1 after;
1344-
P2 groupName;
1345-
P3 groupTypes;
1346-
P4 assetType;
1347-
P5 maxSize;
1342+
P0 first{};
1343+
P1 after{};
1344+
P2 groupName{};
1345+
P3 groupTypes{};
1346+
P4 assetType{};
1347+
P5 maxSize{};
13481348
P6 mimeTypes;
13491349
bool operator==(const NativeCameraRollManagerGetPhotosParams &other) const {
13501350
return first == other.first && after == other.after && groupName == other.groupName && groupTypes == other.groupTypes && assetType == other.assetType && maxSize == other.maxSize && mimeTypes == other.mimeTypes;
@@ -1475,10 +1475,10 @@ private:
14751475

14761476
template <typename P0, typename P1, typename P2, typename P3, typename P4>
14771477
struct NativeExceptionsManagerStackFrame {
1478-
P0 column;
1479-
P1 file;
1480-
P2 lineNumber;
1481-
P3 methodName;
1478+
P0 column{};
1479+
P1 file{};
1480+
P2 lineNumber{};
1481+
P3 methodName{};
14821482
P4 collapse;
14831483
bool operator==(const NativeExceptionsManagerStackFrame &other) const {
14841484
return column == other.column && file == other.file && lineNumber == other.lineNumber && methodName == other.methodName && collapse == other.collapse;
@@ -1546,13 +1546,13 @@ struct NativeExceptionsManagerStackFrameBridging {
15461546

15471547
template <typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
15481548
struct NativeExceptionsManagerExceptionData {
1549-
P0 message;
1550-
P1 originalMessage;
1551-
P2 name;
1552-
P3 componentStack;
1553-
P4 stack;
1554-
P5 id;
1555-
P6 isFatal;
1549+
P0 message{};
1550+
P1 originalMessage{};
1551+
P2 name{};
1552+
P3 componentStack{};
1553+
P4 stack{};
1554+
P5 id{};
1555+
P6 isFatal{};
15561556
P7 extraData;
15571557
bool operator==(const NativeExceptionsManagerExceptionData &other) const {
15581558
return message == other.message && originalMessage == other.originalMessage && name == other.name && componentStack == other.componentStack && stack == other.stack && id == other.id && isFatal == other.isFatal && extraData == other.extraData;

0 commit comments

Comments
 (0)