1 /*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 #pragma once
9
10 #include <folly/dynamic.h>
11 #include <ABI49_0_0React/ABI49_0_0renderer/components/scrollview/primitives.h>
12 #include <ABI49_0_0React/renderer/core/ABI49_0_0PropsParserContext.h>
13 #include <ABI49_0_0React/renderer/core/ABI49_0_0propsConversions.h>
14
15 namespace ABI49_0_0facebook {
16 namespace ABI49_0_0React {
17
fromRawValue(const PropsParserContext & context,const RawValue & value,ScrollViewSnapToAlignment & result)18 inline void fromRawValue(
19 const PropsParserContext &context,
20 const RawValue &value,
21 ScrollViewSnapToAlignment &result) {
22 auto string = (std::string)value;
23 if (string == "start") {
24 result = ScrollViewSnapToAlignment::Start;
25 return;
26 }
27 if (string == "center") {
28 result = ScrollViewSnapToAlignment::Center;
29 return;
30 }
31 if (string == "end") {
32 result = ScrollViewSnapToAlignment::End;
33 return;
34 }
35 abort();
36 }
37
fromRawValue(const PropsParserContext & context,const RawValue & value,ScrollViewIndicatorStyle & result)38 inline void fromRawValue(
39 const PropsParserContext &context,
40 const RawValue &value,
41 ScrollViewIndicatorStyle &result) {
42 auto string = (std::string)value;
43 if (string == "default") {
44 result = ScrollViewIndicatorStyle::Default;
45 return;
46 }
47 if (string == "black") {
48 result = ScrollViewIndicatorStyle::Black;
49 return;
50 }
51 if (string == "white") {
52 result = ScrollViewIndicatorStyle::White;
53 return;
54 }
55 abort();
56 }
57
fromRawValue(const PropsParserContext & context,const RawValue & value,ScrollViewKeyboardDismissMode & result)58 inline void fromRawValue(
59 const PropsParserContext &context,
60 const RawValue &value,
61 ScrollViewKeyboardDismissMode &result) {
62 auto string = (std::string)value;
63 if (string == "none") {
64 result = ScrollViewKeyboardDismissMode::None;
65 return;
66 }
67 if (string == "on-drag") {
68 result = ScrollViewKeyboardDismissMode::OnDrag;
69 return;
70 }
71 if (string == "interactive") {
72 result = ScrollViewKeyboardDismissMode::Interactive;
73 return;
74 }
75 abort();
76 }
77
fromRawValue(const PropsParserContext & context,const RawValue & value,ContentInsetAdjustmentBehavior & result)78 inline void fromRawValue(
79 const PropsParserContext &context,
80 const RawValue &value,
81 ContentInsetAdjustmentBehavior &result) {
82 auto string = (std::string)value;
83 if (string == "never") {
84 result = ContentInsetAdjustmentBehavior::Never;
85 return;
86 }
87 if (string == "automatic") {
88 result = ContentInsetAdjustmentBehavior::Automatic;
89 return;
90 }
91 if (string == "scrollableAxes") {
92 result = ContentInsetAdjustmentBehavior::ScrollableAxes;
93 return;
94 }
95 if (string == "always") {
96 result = ContentInsetAdjustmentBehavior::Always;
97 return;
98 }
99 abort();
100 }
101
fromRawValue(const PropsParserContext & context,const RawValue & value,ScrollViewMaintainVisibleContentPosition & result)102 inline void fromRawValue(
103 const PropsParserContext &context,
104 const RawValue &value,
105 ScrollViewMaintainVisibleContentPosition &result) {
106 auto map = (butter::map<std::string, RawValue>)value;
107
108 auto minIndexForVisible = map.find("minIndexForVisible");
109 if (minIndexForVisible != map.end()) {
110 fromRawValue(
111 context, minIndexForVisible->second, result.minIndexForVisible);
112 }
113 auto autoscrollToTopThreshold = map.find("autoscrollToTopThreshold");
114 if (autoscrollToTopThreshold != map.end()) {
115 fromRawValue(
116 context,
117 autoscrollToTopThreshold->second,
118 result.autoscrollToTopThreshold);
119 }
120 }
121
toString(const ScrollViewSnapToAlignment & value)122 inline std::string toString(const ScrollViewSnapToAlignment &value) {
123 switch (value) {
124 case ScrollViewSnapToAlignment::Start:
125 return "start";
126 case ScrollViewSnapToAlignment::Center:
127 return "center";
128 case ScrollViewSnapToAlignment::End:
129 return "end";
130 }
131 }
132
133 #if ABI49_0_0RN_DEBUG_STRING_CONVERTIBLE
134
toString(const ScrollViewIndicatorStyle & value)135 inline std::string toString(const ScrollViewIndicatorStyle &value) {
136 switch (value) {
137 case ScrollViewIndicatorStyle::Default:
138 return "default";
139 case ScrollViewIndicatorStyle::Black:
140 return "black";
141 case ScrollViewIndicatorStyle::White:
142 return "white";
143 }
144 }
145
toString(const ScrollViewKeyboardDismissMode & value)146 inline std::string toString(const ScrollViewKeyboardDismissMode &value) {
147 switch (value) {
148 case ScrollViewKeyboardDismissMode::None:
149 return "none";
150 case ScrollViewKeyboardDismissMode::OnDrag:
151 return "on-drag";
152 case ScrollViewKeyboardDismissMode::Interactive:
153 return "interactive";
154 }
155 }
156
toString(const ContentInsetAdjustmentBehavior & value)157 inline std::string toString(const ContentInsetAdjustmentBehavior &value) {
158 switch (value) {
159 case ContentInsetAdjustmentBehavior::Never:
160 return "never";
161 case ContentInsetAdjustmentBehavior::Automatic:
162 return "automatic";
163 case ContentInsetAdjustmentBehavior::ScrollableAxes:
164 return "scrollableAxes";
165 case ContentInsetAdjustmentBehavior::Always:
166 return "always";
167 }
168 }
169
toString(const std::optional<ScrollViewMaintainVisibleContentPosition> & value)170 inline std::string toString(
171 const std::optional<ScrollViewMaintainVisibleContentPosition> &value) {
172 if (!value) {
173 return "null";
174 }
175 return "{minIndexForVisible: " + toString(value.value().minIndexForVisible) +
176 ", autoscrollToTopThreshold: " +
177 toString(value.value().autoscrollToTopThreshold) + "}";
178 }
179
180 #endif
181
182 } // namespace ABI49_0_0React
183 } // namespace ABI49_0_0facebook
184