From ad0ea17ae9f76678df20ea4493d255db18e5e410 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Tue, 27 May 2025 17:55:11 -0700 Subject: [PATCH] Add support to diff Point props (#51650) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51650 This diff adds support to diff props with Point type changelog: [internal] internal Reviewed By: mlord93 Differential Revision: D75469451 fbshipit-source-id: a6844b691d8e32326d04c2bd51e6509980feb611 --- .../__snapshots__/GeneratePropsCpp-test.js.snap | 12 ++++++++++++ .../__snapshots__/GeneratePropsCpp-test.js.snap | 12 ++++++++++++ .../src/generators/components/GeneratePropsCpp.js | 10 +++++++++- .../__snapshots__/GeneratePropsCpp-test.js.snap | 12 ++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/packages/react-native-codegen/e2e/deep_imports/__tests__/components/__snapshots__/GeneratePropsCpp-test.js.snap b/packages/react-native-codegen/e2e/deep_imports/__tests__/components/__snapshots__/GeneratePropsCpp-test.js.snap index 6130366ba5c..7612c98f9c0 100644 --- a/packages/react-native-codegen/e2e/deep_imports/__tests__/components/__snapshots__/GeneratePropsCpp-test.js.snap +++ b/packages/react-native-codegen/e2e/deep_imports/__tests__/components/__snapshots__/GeneratePropsCpp-test.js.snap @@ -745,6 +745,12 @@ folly::dynamic MultiNativePropNativeComponentViewProps::getDiffProps( result[\\"thumbTintColor\\"] = *thumbTintColor; } + if (point != oldProps->point) { + folly::dynamic pointResult = folly::dynamic::object(); + pointResult[\\"x\\"] = point.x; + pointResult[\\"y\\"] = point.y; + result[\\"point\\"] = pointResult; + } return result; } #endif @@ -888,6 +894,12 @@ folly::dynamic PointPropNativeComponentViewProps::getDiffProps( } folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps); + if (startPoint != oldProps->startPoint) { + folly::dynamic pointResult = folly::dynamic::object(); + pointResult[\\"x\\"] = startPoint.x; + pointResult[\\"y\\"] = startPoint.y; + result[\\"startPoint\\"] = pointResult; + } return result; } #endif diff --git a/packages/react-native-codegen/e2e/namespaced/__tests__/components/__snapshots__/GeneratePropsCpp-test.js.snap b/packages/react-native-codegen/e2e/namespaced/__tests__/components/__snapshots__/GeneratePropsCpp-test.js.snap index 87eda91a5b9..d7065240bd4 100644 --- a/packages/react-native-codegen/e2e/namespaced/__tests__/components/__snapshots__/GeneratePropsCpp-test.js.snap +++ b/packages/react-native-codegen/e2e/namespaced/__tests__/components/__snapshots__/GeneratePropsCpp-test.js.snap @@ -745,6 +745,12 @@ folly::dynamic MultiNativePropNativeComponentViewProps::getDiffProps( result[\\"thumbTintColor\\"] = *thumbTintColor; } + if (point != oldProps->point) { + folly::dynamic pointResult = folly::dynamic::object(); + pointResult[\\"x\\"] = point.x; + pointResult[\\"y\\"] = point.y; + result[\\"point\\"] = pointResult; + } return result; } #endif @@ -888,6 +894,12 @@ folly::dynamic PointPropNativeComponentViewProps::getDiffProps( } folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps); + if (startPoint != oldProps->startPoint) { + folly::dynamic pointResult = folly::dynamic::object(); + pointResult[\\"x\\"] = startPoint.x; + pointResult[\\"y\\"] = startPoint.y; + result[\\"startPoint\\"] = pointResult; + } return result; } #endif diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js b/packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js index 9dc95ad6eb2..37c0aca020e 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js @@ -102,13 +102,21 @@ function generatePropsDiffString( if (${prop.name} != oldProps->${prop.name}) { result["${prop.name}"] = *${prop.name}; }`; + case 'ImageSourcePrimitive': + return ''; case 'ImageRequestPrimitive': // Shouldn't be used in props throw new Error( 'ImageRequestPrimitive should not be used in Props', ); - case 'ImageSourcePrimitive': case 'PointPrimitive': + return ` + if (${prop.name} != oldProps->${prop.name}) { + folly::dynamic pointResult = folly::dynamic::object(); + pointResult["x"] = ${prop.name}.x; + pointResult["y"] = ${prop.name}.y; + result["${prop.name}"] = pointResult; + }`; case 'EdgeInsetsPrimitive': case 'DimensionPrimitive': // TODO: Implement diffProps for complex types diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsCpp-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsCpp-test.js.snap index 58e74ab5386..f419d20424d 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsCpp-test.js.snap @@ -1157,6 +1157,12 @@ folly::dynamic ImageColorPropNativeComponentProps::getDiffProps( result[\\"thumbTintColor\\"] = *thumbTintColor; } + if (point != oldProps->point) { + folly::dynamic pointResult = folly::dynamic::object(); + pointResult[\\"x\\"] = point.x; + pointResult[\\"y\\"] = point.y; + result[\\"point\\"] = pointResult; + } return result; } #endif @@ -1296,6 +1302,12 @@ folly::dynamic PointPropNativeComponentProps::getDiffProps( } folly::dynamic result = HostPlatformViewProps::getDiffProps(prevProps); + if (startPoint != oldProps->startPoint) { + folly::dynamic pointResult = folly::dynamic::object(); + pointResult[\\"x\\"] = startPoint.x; + pointResult[\\"y\\"] = startPoint.y; + result[\\"startPoint\\"] = pointResult; + } return result; } #endif