Skip to content

Commit 6b8bc5a

Browse files
Nick Lefeverfacebook-github-bot
authored andcommitted
Move toDynamic conversion for FilterFunction (#52537)
Summary: Pull Request resolved: #52537 See title Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D78088447 fbshipit-source-id: 3f3a1e82e527cfe83de7a798b8b9ea2996dc8de1
1 parent 0144798 commit 6b8bc5a

File tree

2 files changed

+47
-40
lines changed

2 files changed

+47
-40
lines changed

packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -491,30 +491,6 @@ inline static void updateAccessibilityStateProp(
491491
result["accessibilityState"] = resultState;
492492
}
493493

494-
static folly::dynamic toDynamic(const std::vector<FilterFunction>& filter) {
495-
folly::dynamic filterResult = folly::dynamic::array();
496-
for (const auto& filterFunction : filter) {
497-
folly::dynamic filterFunctionResult = folly::dynamic::object();
498-
std::string typeKey = toString(filterFunction.type);
499-
if (std::holds_alternative<Float>(filterFunction.parameters)) {
500-
filterFunctionResult[typeKey] =
501-
std::get<Float>(filterFunction.parameters);
502-
} else if (std::holds_alternative<DropShadowParams>(
503-
filterFunction.parameters)) {
504-
const auto& parameters =
505-
std::get<DropShadowParams>(filterFunction.parameters);
506-
folly::dynamic parametersResult = folly::dynamic::object();
507-
parametersResult["offsetX"] = parameters.offsetX;
508-
parametersResult["offsetY"] = parameters.offsetY;
509-
parametersResult["standardDeviation"] = parameters.standardDeviation;
510-
parametersResult["color"] = *parameters.color;
511-
filterFunctionResult[typeKey] = parametersResult;
512-
}
513-
filterResult.push_back(filterFunctionResult);
514-
}
515-
return filterResult;
516-
}
517-
518494
ComponentName HostPlatformViewProps::getDiffPropsImplementationTarget() const {
519495
return "View";
520496
}

packages/react-native/ReactCommon/react/renderer/graphics/Filter.h

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,6 @@ enum class FilterType {
2929
DropShadow
3030
};
3131

32-
struct DropShadowParams {
33-
bool operator==(const DropShadowParams& other) const = default;
34-
35-
Float offsetX{};
36-
Float offsetY{};
37-
Float standardDeviation{};
38-
SharedColor color{};
39-
};
40-
41-
struct FilterFunction {
42-
bool operator==(const FilterFunction& other) const = default;
43-
44-
FilterType type{};
45-
std::variant<Float, DropShadowParams> parameters{};
46-
};
47-
4832
inline FilterType filterTypeFromString(std::string_view filterName) {
4933
if (filterName == "blur") {
5034
return FilterType::Blur;
@@ -96,4 +80,51 @@ inline std::string toString(const FilterType& filterType) {
9680
}
9781
}
9882

83+
struct DropShadowParams {
84+
bool operator==(const DropShadowParams& other) const = default;
85+
86+
Float offsetX{};
87+
Float offsetY{};
88+
Float standardDeviation{};
89+
SharedColor color{};
90+
91+
#ifdef RN_SERIALIZABLE_STATE
92+
folly::dynamic toDynamic() const {
93+
folly::dynamic result = folly::dynamic::object();
94+
result["offsetX"] = offsetX;
95+
result["offsetY"] = offsetY;
96+
result["standardDeviation"] = standardDeviation;
97+
result["color"] = *color;
98+
return result;
99+
}
100+
#endif
101+
};
102+
103+
struct FilterFunction {
104+
bool operator==(const FilterFunction& other) const = default;
105+
106+
FilterType type{};
107+
std::variant<Float, DropShadowParams> parameters{};
108+
109+
#ifdef RN_SERIALIZABLE_STATE
110+
folly::dynamic toDynamic() const {
111+
folly::dynamic result = folly::dynamic::object();
112+
std::string typeKey = toString(type);
113+
if (std::holds_alternative<Float>(parameters)) {
114+
result[typeKey] = std::get<Float>(parameters);
115+
} else if (std::holds_alternative<DropShadowParams>(parameters)) {
116+
const auto& dropShadowParams = std::get<DropShadowParams>(parameters);
117+
result[typeKey] = dropShadowParams.toDynamic();
118+
}
119+
return result;
120+
}
121+
#endif
122+
};
123+
124+
#ifdef RN_SERIALIZABLE_STATE
125+
inline folly::dynamic toDynamic(const FilterFunction& filterFunction) {
126+
return filterFunction.toDynamic();
127+
}
128+
#endif
129+
99130
} // namespace facebook::react

0 commit comments

Comments
 (0)