From 6b8bc5a1d02cb9bdbefaa07515f90270f1828073 Mon Sep 17 00:00:00 2001 From: Nick Lefever Date: Thu, 10 Jul 2025 12:35:18 -0700 Subject: [PATCH] Move toDynamic conversion for FilterFunction (#52537) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/52537 See title Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D78088447 fbshipit-source-id: 3f3a1e82e527cfe83de7a798b8b9ea2996dc8de1 --- .../components/view/HostPlatformViewProps.cpp | 24 ------- .../react/renderer/graphics/Filter.h | 63 ++++++++++++++----- 2 files changed, 47 insertions(+), 40 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp index d13bedd4fe4..297ace7f9c0 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp @@ -491,30 +491,6 @@ inline static void updateAccessibilityStateProp( result["accessibilityState"] = resultState; } -static folly::dynamic toDynamic(const std::vector& filter) { - folly::dynamic filterResult = folly::dynamic::array(); - for (const auto& filterFunction : filter) { - folly::dynamic filterFunctionResult = folly::dynamic::object(); - std::string typeKey = toString(filterFunction.type); - if (std::holds_alternative(filterFunction.parameters)) { - filterFunctionResult[typeKey] = - std::get(filterFunction.parameters); - } else if (std::holds_alternative( - filterFunction.parameters)) { - const auto& parameters = - std::get(filterFunction.parameters); - folly::dynamic parametersResult = folly::dynamic::object(); - parametersResult["offsetX"] = parameters.offsetX; - parametersResult["offsetY"] = parameters.offsetY; - parametersResult["standardDeviation"] = parameters.standardDeviation; - parametersResult["color"] = *parameters.color; - filterFunctionResult[typeKey] = parametersResult; - } - filterResult.push_back(filterFunctionResult); - } - return filterResult; -} - ComponentName HostPlatformViewProps::getDiffPropsImplementationTarget() const { return "View"; } diff --git a/packages/react-native/ReactCommon/react/renderer/graphics/Filter.h b/packages/react-native/ReactCommon/react/renderer/graphics/Filter.h index 029536c8d4f..176d0e54475 100644 --- a/packages/react-native/ReactCommon/react/renderer/graphics/Filter.h +++ b/packages/react-native/ReactCommon/react/renderer/graphics/Filter.h @@ -29,22 +29,6 @@ enum class FilterType { DropShadow }; -struct DropShadowParams { - bool operator==(const DropShadowParams& other) const = default; - - Float offsetX{}; - Float offsetY{}; - Float standardDeviation{}; - SharedColor color{}; -}; - -struct FilterFunction { - bool operator==(const FilterFunction& other) const = default; - - FilterType type{}; - std::variant parameters{}; -}; - inline FilterType filterTypeFromString(std::string_view filterName) { if (filterName == "blur") { return FilterType::Blur; @@ -96,4 +80,51 @@ inline std::string toString(const FilterType& filterType) { } } +struct DropShadowParams { + bool operator==(const DropShadowParams& other) const = default; + + Float offsetX{}; + Float offsetY{}; + Float standardDeviation{}; + SharedColor color{}; + +#ifdef RN_SERIALIZABLE_STATE + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + result["offsetX"] = offsetX; + result["offsetY"] = offsetY; + result["standardDeviation"] = standardDeviation; + result["color"] = *color; + return result; + } +#endif +}; + +struct FilterFunction { + bool operator==(const FilterFunction& other) const = default; + + FilterType type{}; + std::variant parameters{}; + +#ifdef RN_SERIALIZABLE_STATE + folly::dynamic toDynamic() const { + folly::dynamic result = folly::dynamic::object(); + std::string typeKey = toString(type); + if (std::holds_alternative(parameters)) { + result[typeKey] = std::get(parameters); + } else if (std::holds_alternative(parameters)) { + const auto& dropShadowParams = std::get(parameters); + result[typeKey] = dropShadowParams.toDynamic(); + } + return result; + } +#endif +}; + +#ifdef RN_SERIALIZABLE_STATE +inline folly::dynamic toDynamic(const FilterFunction& filterFunction) { + return filterFunction.toDynamic(); +} +#endif + } // namespace facebook::react