Skip to content

Commit e441954

Browse files
Nick Lefeverfacebook-github-bot
authored andcommitted
Add codegen for ArrayType diffing (#52244)
Summary: Pull Request resolved: #52244 The ArrayType props converts to std::vector. This prompted the need for `toDynamic(const T&)` conversion functions as this breaks to potential reliance on all type instances having a `toDynamic()` function available. This includes: - array of arrays types - array of objects types - object with arrays The ArrayType conversion uses the availability of the `toDynamic` conversion methods for all supported types to convert the values stored by the `std::vector` to `folly::dynamic` values to be stored on a `folly::dynamic::array`. The diff removes unnecessary conversion methods implemented previously for the core components prop diffing. These are now handled by the generic `toDynamic(const std::vector<T>&)` conversion method. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D77234065 fbshipit-source-id: 97a3b175ff07fe4a6de3adb14ee6cb42db1a2cfe
1 parent b50ad49 commit e441954

12 files changed

Lines changed: 179 additions & 23 deletions

File tree

packages/react-native-codegen/e2e/deep_imports/__tests__/components/__snapshots__/GeneratePropsCpp-test.js.snap

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,57 @@ folly::dynamic ArrayPropsNativeComponentViewProps::getDiffProps(
5151
}
5252
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
5353
54+
if (names != oldProps->names) {
55+
result[\\"names\\"] = toDynamic(names);
56+
}
5457
58+
if (disableds != oldProps->disableds) {
59+
result[\\"disableds\\"] = toDynamic(disableds);
60+
}
5561
62+
if (progress != oldProps->progress) {
63+
result[\\"progress\\"] = toDynamic(progress);
64+
}
5665
66+
if (radii != oldProps->radii) {
67+
result[\\"radii\\"] = toDynamic(radii);
68+
}
5769
70+
if (colors != oldProps->colors) {
71+
result[\\"colors\\"] = toDynamic(colors);
72+
}
5873
74+
if (srcs != oldProps->srcs) {
75+
result[\\"srcs\\"] = toDynamic(srcs);
76+
}
5977
78+
if (points != oldProps->points) {
79+
result[\\"points\\"] = toDynamic(points);
80+
}
6081
82+
if (edgeInsets != oldProps->edgeInsets) {
83+
result[\\"edgeInsets\\"] = toDynamic(edgeInsets);
84+
}
6185
86+
if (dimensions != oldProps->dimensions) {
87+
result[\\"dimensions\\"] = toDynamic(dimensions);
88+
}
6289
90+
if (sizes != oldProps->sizes) {
91+
result[\\"sizes\\"] = toDynamic(sizes);
92+
}
6393
94+
if (object != oldProps->object) {
95+
result[\\"object\\"] = toDynamic(object);
96+
}
6497
98+
if (arrayOfObjects != oldProps->arrayOfObjects) {
99+
result[\\"arrayOfObjects\\"] = toDynamic(arrayOfObjects);
100+
}
65101
102+
if (arrayOfMixed != oldProps->arrayOfMixed) {
103+
result[\\"arrayOfMixed\\"] = toDynamic(arrayOfMixed);
104+
}
66105
return result;
67106
}
68107
#endif

packages/react-native-codegen/e2e/deep_imports/__tests__/components/__snapshots__/GeneratePropsH-test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ struct ObjectPropsNativeComponentObjectArrayPropStruct {
958958
959959
folly::dynamic toDynamic() const {
960960
folly::dynamic result = folly::dynamic::object();
961-
961+
result[\\"array\\"] = ::facebook::react::toDynamic(array);
962962
return result;
963963
}
964964
#endif

packages/react-native-codegen/e2e/namespaced/__tests__/components/__snapshots__/GeneratePropsCpp-test.js.snap

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,57 @@ folly::dynamic ArrayPropsNativeComponentViewProps::getDiffProps(
5151
}
5252
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
5353
54+
if (names != oldProps->names) {
55+
result[\\"names\\"] = toDynamic(names);
56+
}
5457
58+
if (disableds != oldProps->disableds) {
59+
result[\\"disableds\\"] = toDynamic(disableds);
60+
}
5561
62+
if (progress != oldProps->progress) {
63+
result[\\"progress\\"] = toDynamic(progress);
64+
}
5665
66+
if (radii != oldProps->radii) {
67+
result[\\"radii\\"] = toDynamic(radii);
68+
}
5769
70+
if (colors != oldProps->colors) {
71+
result[\\"colors\\"] = toDynamic(colors);
72+
}
5873
74+
if (srcs != oldProps->srcs) {
75+
result[\\"srcs\\"] = toDynamic(srcs);
76+
}
5977
78+
if (points != oldProps->points) {
79+
result[\\"points\\"] = toDynamic(points);
80+
}
6081
82+
if (edgeInsets != oldProps->edgeInsets) {
83+
result[\\"edgeInsets\\"] = toDynamic(edgeInsets);
84+
}
6185
86+
if (dimensions != oldProps->dimensions) {
87+
result[\\"dimensions\\"] = toDynamic(dimensions);
88+
}
6289
90+
if (sizes != oldProps->sizes) {
91+
result[\\"sizes\\"] = toDynamic(sizes);
92+
}
6393
94+
if (object != oldProps->object) {
95+
result[\\"object\\"] = toDynamic(object);
96+
}
6497
98+
if (arrayOfObjects != oldProps->arrayOfObjects) {
99+
result[\\"arrayOfObjects\\"] = toDynamic(arrayOfObjects);
100+
}
65101
102+
if (arrayOfMixed != oldProps->arrayOfMixed) {
103+
result[\\"arrayOfMixed\\"] = toDynamic(arrayOfMixed);
104+
}
66105
return result;
67106
}
68107
#endif

packages/react-native-codegen/e2e/namespaced/__tests__/components/__snapshots__/GeneratePropsH-test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ struct ObjectPropsNativeComponentObjectArrayPropStruct {
958958
959959
folly::dynamic toDynamic() const {
960960
folly::dynamic result = folly::dynamic::object();
961-
961+
result[\\"array\\"] = ::facebook::react::toDynamic(array);
962962
return result;
963963
}
964964
#endif

packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ function generatePropsDiffString(
132132
throw new Error('Received unknown ReservedPropTypeAnnotation');
133133
}
134134
case 'ArrayTypeAnnotation':
135-
return '';
135+
return `
136+
if (${prop.name} != oldProps->${prop.name}) {
137+
result["${prop.name}"] = toDynamic(${prop.name});
138+
}`;
136139
case 'ObjectTypeAnnotation':
137140
return `
138141
if (${prop.name} != oldProps->${prop.name}) {

packages/react-native-codegen/src/generators/components/GeneratePropsH.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,6 @@ function generateStruct(
756756
case 'DoubleTypeAnnotation':
757757
case 'FloatTypeAnnotation':
758758
return `result["${name}"] = ${name};`;
759-
case 'ArrayTypeAnnotation':
760-
return '';
761759
case 'MixedTypeAnnotation':
762760
// MixedTypeAnnotation does not support prop diffing codegen
763761
return '';

packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsCpp-test.js.snap

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,57 @@ folly::dynamic ArrayPropsNativeComponentProps::getDiffProps(
5151
}
5252
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
5353
54+
if (names != oldProps->names) {
55+
result[\\"names\\"] = toDynamic(names);
56+
}
5457
58+
if (disableds != oldProps->disableds) {
59+
result[\\"disableds\\"] = toDynamic(disableds);
60+
}
5561
62+
if (progress != oldProps->progress) {
63+
result[\\"progress\\"] = toDynamic(progress);
64+
}
5665
66+
if (radii != oldProps->radii) {
67+
result[\\"radii\\"] = toDynamic(radii);
68+
}
5769
70+
if (colors != oldProps->colors) {
71+
result[\\"colors\\"] = toDynamic(colors);
72+
}
5873
74+
if (srcs != oldProps->srcs) {
75+
result[\\"srcs\\"] = toDynamic(srcs);
76+
}
5977
78+
if (points != oldProps->points) {
79+
result[\\"points\\"] = toDynamic(points);
80+
}
6081
82+
if (dimensions != oldProps->dimensions) {
83+
result[\\"dimensions\\"] = toDynamic(dimensions);
84+
}
6185
86+
if (sizes != oldProps->sizes) {
87+
result[\\"sizes\\"] = toDynamic(sizes);
88+
}
6289
90+
if (object != oldProps->object) {
91+
result[\\"object\\"] = toDynamic(object);
92+
}
6393
94+
if (array != oldProps->array) {
95+
result[\\"array\\"] = toDynamic(array);
96+
}
6497
98+
if (arrayOfArrayOfObject != oldProps->arrayOfArrayOfObject) {
99+
result[\\"arrayOfArrayOfObject\\"] = toDynamic(arrayOfArrayOfObject);
100+
}
65101
102+
if (arrayOfMixed != oldProps->arrayOfMixed) {
103+
result[\\"arrayOfMixed\\"] = toDynamic(arrayOfMixed);
104+
}
66105
return result;
67106
}
68107
#endif
@@ -109,6 +148,9 @@ folly::dynamic ArrayPropsNativeComponentProps::getDiffProps(
109148
}
110149
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
111150
151+
if (nativePrimitives != oldProps->nativePrimitives) {
152+
result[\\"nativePrimitives\\"] = toDynamic(nativePrimitives);
153+
}
112154
return result;
113155
}
114156
#endif

packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsH-test.js.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ struct ArrayPropsNativeComponentArrayStruct {
179179
180180
folly::dynamic toDynamic() const {
181181
folly::dynamic result = folly::dynamic::object();
182-
182+
result[\\"object\\"] = ::facebook::react::toDynamic(object);
183183
return result;
184184
}
185185
#endif
@@ -325,9 +325,9 @@ struct ArrayPropsNativeComponentNativePrimitivesStruct {
325325
326326
folly::dynamic toDynamic() const {
327327
folly::dynamic result = folly::dynamic::object();
328-
329-
330-
328+
result[\\"colors\\"] = ::facebook::react::toDynamic(colors);
329+
result[\\"srcs\\"] = ::facebook::react::toDynamic(srcs);
330+
result[\\"points\\"] = ::facebook::react::toDynamic(points);
331331
return result;
332332
}
333333
#endif
@@ -1316,7 +1316,7 @@ struct ObjectPropsObjectPropObjectArrayPropStruct {
13161316
13171317
folly::dynamic toDynamic() const {
13181318
folly::dynamic result = folly::dynamic::object();
1319-
1319+
result[\\"array\\"] = ::facebook::react::toDynamic(array);
13201320
return result;
13211321
}
13221322
#endif
@@ -1503,7 +1503,7 @@ struct ObjectPropsObjectPropNestedArrayAsPropertyStruct {
15031503
15041504
folly::dynamic toDynamic() const {
15051505
folly::dynamic result = folly::dynamic::object();
1506-
1506+
result[\\"arrayProp\\"] = ::facebook::react::toDynamic(arrayProp);
15071507
return result;
15081508
}
15091509
#endif

packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,6 @@ SharedDebugStringConvertibleList AndroidTextInputProps::getDebugProps() const {
357357
}
358358
#endif
359359

360-
static folly::dynamic toDynamic(
361-
const std::vector<std::string>& acceptDragAndDropTypes) {
362-
folly::dynamic acceptDragAndDropTypesArray = folly::dynamic::array();
363-
for (const auto& acceptDragAndDropType : acceptDragAndDropTypes) {
364-
acceptDragAndDropTypesArray.push_back(acceptDragAndDropType);
365-
}
366-
return acceptDragAndDropTypesArray;
367-
}
368-
369360
ComponentName AndroidTextInputProps::getDiffPropsImplementationTarget() const {
370361
return "TextInput";
371362
}

packages/react-native/ReactCommon/react/renderer/core/graphicsConversions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ inline void fromRawValue(
4343
inline int toAndroidRepr(const SharedColor& color) {
4444
return *color;
4545
}
46-
inline folly::dynamic toDynamic(const SharedColor& color) {
47-
return *color;
48-
}
4946
#endif
5047

5148
inline std::string toString(const SharedColor& value) {

0 commit comments

Comments
 (0)