@@ -18,20 +18,61 @@ namespace facebook::react {
18
18
19
19
enum class GradientDirectionType { Angle, Keyword };
20
20
21
+ inline std::string toString (
22
+ const GradientDirectionType& gradientDirectionType) {
23
+ switch (gradientDirectionType) {
24
+ case GradientDirectionType::Angle:
25
+ return " angle" ;
26
+ case GradientDirectionType::Keyword:
27
+ return " keyword" ;
28
+ }
29
+
30
+ return " " ;
31
+ }
32
+
21
33
enum class GradientKeyword {
22
34
ToTopRight,
23
35
ToBottomRight,
24
36
ToTopLeft,
25
37
ToBottomLeft,
26
38
};
27
39
40
+ inline std::string toString (const GradientKeyword& gradientKeyword) {
41
+ switch (gradientKeyword) {
42
+ case GradientKeyword::ToTopRight:
43
+ return " to top right" ;
44
+ case GradientKeyword::ToBottomRight:
45
+ return " to bottom right" ;
46
+ case GradientKeyword::ToTopLeft:
47
+ return " to top left" ;
48
+ case GradientKeyword::ToBottomLeft:
49
+ return " to bottom left" ;
50
+ }
51
+
52
+ return " " ;
53
+ }
54
+
28
55
struct GradientDirection {
29
56
GradientDirectionType type;
30
57
std::variant<Float, GradientKeyword> value;
31
58
32
59
bool operator ==(const GradientDirection& other) const {
33
60
return type == other.type && value == other.value ;
34
61
}
62
+
63
+ #ifdef RN_SERIALIZABLE_STATE
64
+ folly::dynamic toDynamic () const {
65
+ folly::dynamic result = folly::dynamic::object ();
66
+ result[" type" ] = toString (type);
67
+
68
+ if (std::holds_alternative<Float>(value)) {
69
+ result[" value" ] = std::get<Float>(value);
70
+ } else if (std::holds_alternative<GradientKeyword>(value)) {
71
+ result[" value" ] = toString (std::get<GradientKeyword>(value));
72
+ }
73
+ return result;
74
+ }
75
+ #endif
35
76
};
36
77
37
78
struct LinearGradient {
@@ -41,6 +82,21 @@ struct LinearGradient {
41
82
bool operator ==(const LinearGradient& other) const {
42
83
return direction == other.direction && colorStops == other.colorStops ;
43
84
}
85
+
86
+ #ifdef RN_SERIALIZABLE_STATE
87
+ folly::dynamic toDynamic () const {
88
+ folly::dynamic result = folly::dynamic::object ();
89
+ result[" type" ] = " linear-gradient" ;
90
+ result[" direction" ] = direction.toDynamic ();
91
+
92
+ folly::dynamic colorStopsArray = folly::dynamic::array ();
93
+ for (const auto & colorStop : colorStops) {
94
+ colorStopsArray.push_back (colorStop.toDynamic ());
95
+ }
96
+ result[" colorStops" ] = colorStopsArray;
97
+ return result;
98
+ }
99
+ #endif
44
100
};
45
101
46
102
inline GradientKeyword parseGradientKeyword (const std::string& keyword) {
0 commit comments