mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0144798e25
commit
6b8bc5a1d0
-24
@@ -491,30 +491,6 @@ inline static void updateAccessibilityStateProp(
|
||||
result["accessibilityState"] = resultState;
|
||||
}
|
||||
|
||||
static folly::dynamic toDynamic(const std::vector<FilterFunction>& 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<Float>(filterFunction.parameters)) {
|
||||
filterFunctionResult[typeKey] =
|
||||
std::get<Float>(filterFunction.parameters);
|
||||
} else if (std::holds_alternative<DropShadowParams>(
|
||||
filterFunction.parameters)) {
|
||||
const auto& parameters =
|
||||
std::get<DropShadowParams>(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";
|
||||
}
|
||||
|
||||
@@ -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<Float, DropShadowParams> 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<Float, DropShadowParams> parameters{};
|
||||
|
||||
#ifdef RN_SERIALIZABLE_STATE
|
||||
folly::dynamic toDynamic() const {
|
||||
folly::dynamic result = folly::dynamic::object();
|
||||
std::string typeKey = toString(type);
|
||||
if (std::holds_alternative<Float>(parameters)) {
|
||||
result[typeKey] = std::get<Float>(parameters);
|
||||
} else if (std::holds_alternative<DropShadowParams>(parameters)) {
|
||||
const auto& dropShadowParams = std::get<DropShadowParams>(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
|
||||
|
||||
Reference in New Issue
Block a user