Skip to content

Commit ad0ea17

Browse files
mdvaccafacebook-github-bot
authored andcommitted
Add support to diff Point props (#51650)
Summary: Pull Request resolved: #51650 This diff adds support to diff props with Point type changelog: [internal] internal Reviewed By: mlord93 Differential Revision: D75469451 fbshipit-source-id: a6844b691d8e32326d04c2bd51e6509980feb611
1 parent 5086108 commit ad0ea17

4 files changed

Lines changed: 45 additions & 1 deletion

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,12 @@ folly::dynamic MultiNativePropNativeComponentViewProps::getDiffProps(
745745
result[\\"thumbTintColor\\"] = *thumbTintColor;
746746
}
747747
748+
if (point != oldProps->point) {
749+
folly::dynamic pointResult = folly::dynamic::object();
750+
pointResult[\\"x\\"] = point.x;
751+
pointResult[\\"y\\"] = point.y;
752+
result[\\"point\\"] = pointResult;
753+
}
748754
return result;
749755
}
750756
#endif
@@ -888,6 +894,12 @@ folly::dynamic PointPropNativeComponentViewProps::getDiffProps(
888894
}
889895
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
890896
897+
if (startPoint != oldProps->startPoint) {
898+
folly::dynamic pointResult = folly::dynamic::object();
899+
pointResult[\\"x\\"] = startPoint.x;
900+
pointResult[\\"y\\"] = startPoint.y;
901+
result[\\"startPoint\\"] = pointResult;
902+
}
891903
return result;
892904
}
893905
#endif

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,12 @@ folly::dynamic MultiNativePropNativeComponentViewProps::getDiffProps(
745745
result[\\"thumbTintColor\\"] = *thumbTintColor;
746746
}
747747
748+
if (point != oldProps->point) {
749+
folly::dynamic pointResult = folly::dynamic::object();
750+
pointResult[\\"x\\"] = point.x;
751+
pointResult[\\"y\\"] = point.y;
752+
result[\\"point\\"] = pointResult;
753+
}
748754
return result;
749755
}
750756
#endif
@@ -888,6 +894,12 @@ folly::dynamic PointPropNativeComponentViewProps::getDiffProps(
888894
}
889895
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
890896
897+
if (startPoint != oldProps->startPoint) {
898+
folly::dynamic pointResult = folly::dynamic::object();
899+
pointResult[\\"x\\"] = startPoint.x;
900+
pointResult[\\"y\\"] = startPoint.y;
901+
result[\\"startPoint\\"] = pointResult;
902+
}
891903
return result;
892904
}
893905
#endif

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,21 @@ function generatePropsDiffString(
102102
if (${prop.name} != oldProps->${prop.name}) {
103103
result["${prop.name}"] = *${prop.name};
104104
}`;
105+
case 'ImageSourcePrimitive':
106+
return '';
105107
case 'ImageRequestPrimitive':
106108
// Shouldn't be used in props
107109
throw new Error(
108110
'ImageRequestPrimitive should not be used in Props',
109111
);
110-
case 'ImageSourcePrimitive':
111112
case 'PointPrimitive':
113+
return `
114+
if (${prop.name} != oldProps->${prop.name}) {
115+
folly::dynamic pointResult = folly::dynamic::object();
116+
pointResult["x"] = ${prop.name}.x;
117+
pointResult["y"] = ${prop.name}.y;
118+
result["${prop.name}"] = pointResult;
119+
}`;
112120
case 'EdgeInsetsPrimitive':
113121
case 'DimensionPrimitive':
114122
// TODO: Implement diffProps for complex types

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,12 @@ folly::dynamic ImageColorPropNativeComponentProps::getDiffProps(
11571157
result[\\"thumbTintColor\\"] = *thumbTintColor;
11581158
}
11591159
1160+
if (point != oldProps->point) {
1161+
folly::dynamic pointResult = folly::dynamic::object();
1162+
pointResult[\\"x\\"] = point.x;
1163+
pointResult[\\"y\\"] = point.y;
1164+
result[\\"point\\"] = pointResult;
1165+
}
11601166
return result;
11611167
}
11621168
#endif
@@ -1296,6 +1302,12 @@ folly::dynamic PointPropNativeComponentProps::getDiffProps(
12961302
}
12971303
folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps);
12981304
1305+
if (startPoint != oldProps->startPoint) {
1306+
folly::dynamic pointResult = folly::dynamic::object();
1307+
pointResult[\\"x\\"] = startPoint.x;
1308+
pointResult[\\"y\\"] = startPoint.y;
1309+
result[\\"startPoint\\"] = pointResult;
1310+
}
12991311
return result;
13001312
}
13011313
#endif

0 commit comments

Comments
 (0)