Skip to content

Commit e970e36

Browse files
mdvaccafacebook-github-bot
authored andcommitted
[skip ci] Implement prop diffing for border props in <View> (facebook#48831)
Summary: This diff implements the diffing for border props of <View> changelog: [internal] internal Reviewed By: sammy-SC Differential Revision: D59972037
1 parent 9d962b9 commit e970e36

File tree

1 file changed

+206
-0
lines changed
  • packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view

1 file changed

+206
-0
lines changed

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

+206
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,192 @@ inline static void updateEventProp(
147147
}
148148
}
149149

150+
static void updateBorderWidthPropValue(
151+
folly::dynamic& result,
152+
const std::string& propName,
153+
const std::optional<float>& newValue,
154+
const std::optional<float>& oldValue) {
155+
if (newValue != oldValue) {
156+
if (newValue.has_value()) {
157+
result[propName] = newValue.value();
158+
} else {
159+
result[propName] = NULL;
160+
}
161+
}
162+
}
163+
164+
static void updateBorderWidthProps(
165+
folly::dynamic& result,
166+
const CascadedBorderWidths& newBorderWidths,
167+
const CascadedBorderWidths& oldBorderWidths) {
168+
updateBorderWidthPropValue(
169+
result, "borderWidth", newBorderWidths.all, oldBorderWidths.all);
170+
updateBorderWidthPropValue(
171+
result, "borderTopWidth", newBorderWidths.top, oldBorderWidths.top);
172+
updateBorderWidthPropValue(
173+
result, "borderLeftWidth", newBorderWidths.left, oldBorderWidths.left);
174+
updateBorderWidthPropValue(
175+
result, "borderStartWidth", newBorderWidths.start, oldBorderWidths.start);
176+
updateBorderWidthPropValue(
177+
result, "borderEndWidth", newBorderWidths.end, oldBorderWidths.end);
178+
updateBorderWidthPropValue(
179+
result, "borderRightWidth", newBorderWidths.right, oldBorderWidths.right);
180+
updateBorderWidthPropValue(
181+
result,
182+
"borderBottomWidth",
183+
newBorderWidths.bottom,
184+
oldBorderWidths.bottom);
185+
}
186+
187+
static void updateBorderRadiusPropValue(
188+
folly::dynamic& result,
189+
const std::string& propName,
190+
const std::optional<ValueUnit>& newValue,
191+
const std::optional<ValueUnit>& oldValue) {
192+
if (newValue != oldValue) {
193+
if (newValue.has_value()) {
194+
if (newValue.value().unit == UnitType::Percent) {
195+
result[propName] = std::to_string(newValue.value().value) + "%";
196+
} else {
197+
result[propName] = newValue.value().value;
198+
}
199+
} else {
200+
result[propName] = -1;
201+
}
202+
}
203+
}
204+
205+
static void updateBorderRadiusProps(
206+
folly::dynamic& result,
207+
const CascadedBorderRadii& newBorderRadii,
208+
const CascadedBorderRadii& oldBorderRadii) {
209+
updateBorderRadiusPropValue(
210+
result, "borderRadius", newBorderRadii.all, oldBorderRadii.all);
211+
updateBorderRadiusPropValue(
212+
result,
213+
"borderTopLeftRadius",
214+
newBorderRadii.topLeft,
215+
oldBorderRadii.topLeft);
216+
updateBorderRadiusPropValue(
217+
result,
218+
"borderTopRightRadius",
219+
newBorderRadii.topRight,
220+
oldBorderRadii.topRight);
221+
updateBorderRadiusPropValue(
222+
result,
223+
"borderBottomRightRadius",
224+
newBorderRadii.bottomRight,
225+
oldBorderRadii.bottomRight);
226+
updateBorderRadiusPropValue(
227+
result,
228+
"borderBottomLeftRadius",
229+
newBorderRadii.bottomLeft,
230+
oldBorderRadii.bottomLeft);
231+
updateBorderRadiusPropValue(
232+
result,
233+
"borderTopStartRadius",
234+
newBorderRadii.topStart,
235+
oldBorderRadii.topStart);
236+
updateBorderRadiusPropValue(
237+
result,
238+
"borderTopEndRadius",
239+
newBorderRadii.topEnd,
240+
oldBorderRadii.topEnd);
241+
updateBorderRadiusPropValue(
242+
result,
243+
"borderBottomStartRadius",
244+
newBorderRadii.bottomStart,
245+
oldBorderRadii.bottomStart);
246+
updateBorderRadiusPropValue(
247+
result,
248+
"borderBottomEndRadius",
249+
newBorderRadii.bottomEnd,
250+
oldBorderRadii.bottomEnd);
251+
updateBorderRadiusPropValue(
252+
result,
253+
"borderEndEndRadius",
254+
newBorderRadii.endEnd,
255+
oldBorderRadii.endEnd);
256+
updateBorderRadiusPropValue(
257+
result, "borderEndStartRadius", newBorderRadii.all, oldBorderRadii.all);
258+
updateBorderRadiusPropValue(
259+
result,
260+
"borderStartEndRadius",
261+
newBorderRadii.startEnd,
262+
oldBorderRadii.startEnd);
263+
updateBorderRadiusPropValue(
264+
result,
265+
"borderStartStartRadius",
266+
newBorderRadii.startStart,
267+
oldBorderRadii.startStart);
268+
}
269+
270+
static void updateBorderStyleProps(
271+
folly::dynamic& result,
272+
const CascadedBorderStyles& newBorderStyle,
273+
const CascadedBorderStyles& oldBorderStyle) {
274+
if (newBorderStyle.all != oldBorderStyle.all) {
275+
if (newBorderStyle.all.has_value()) {
276+
switch (newBorderStyle.all.value()) {
277+
case BorderStyle::Solid:
278+
result["borderStyle"] = "solid";
279+
break;
280+
case BorderStyle::Dotted:
281+
result["borderStyle"] = "dotted";
282+
break;
283+
case BorderStyle::Dashed:
284+
result["borderStyle"] = "dashed";
285+
break;
286+
}
287+
} else {
288+
result["borderStyle"] = NULL;
289+
}
290+
}
291+
}
292+
293+
static void updateBorderColorPropValue(
294+
folly::dynamic& result,
295+
const std::string& propName,
296+
const std::optional<SharedColor>& newColor,
297+
const std::optional<SharedColor>& oldColor) {
298+
if (newColor != oldColor) {
299+
result[propName] = newColor.has_value() ? *newColor.value() : NULL;
300+
}
301+
}
302+
303+
static void updateBorderColorsProps(
304+
folly::dynamic& result,
305+
const CascadedBorderColors& newBorderColor,
306+
const CascadedBorderColors& oldBorderColor) {
307+
updateBorderColorPropValue(
308+
result, "borderColor", newBorderColor.all, oldBorderColor.all);
309+
updateBorderColorPropValue(
310+
result, "borderLeftColor", newBorderColor.left, oldBorderColor.left);
311+
updateBorderColorPropValue(
312+
result, "borderRightColor", newBorderColor.right, oldBorderColor.right);
313+
updateBorderColorPropValue(
314+
result, "borderTopColor", newBorderColor.top, oldBorderColor.top);
315+
updateBorderColorPropValue(
316+
result,
317+
"borderBottomColor",
318+
newBorderColor.bottom,
319+
oldBorderColor.bottom);
320+
updateBorderColorPropValue(
321+
result, "borderStartColor", newBorderColor.start, oldBorderColor.start);
322+
updateBorderColorPropValue(
323+
result, "borderBlockColor", newBorderColor.block, oldBorderColor.block);
324+
updateBorderColorPropValue(
325+
result,
326+
"borderBlockEndColor",
327+
newBorderColor.blockEnd,
328+
oldBorderColor.blockEnd);
329+
updateBorderColorPropValue(
330+
result,
331+
"borderBlockStartColor",
332+
newBorderColor.blockStart,
333+
oldBorderColor.blockStart);
334+
}
335+
150336
folly::dynamic HostPlatformViewProps::getDiffProps(
151337
const Props* prevProps) const {
152338
folly::dynamic result = folly::dynamic::object();
@@ -268,6 +454,7 @@ folly::dynamic HostPlatformViewProps::getDiffProps(
268454
}
269455

270456
// TODO T212662692: pass events as std::bitset<64> to java
457+
// Events
271458
if (events != oldProps->events) {
272459
updateEventProp(
273460
result,
@@ -423,6 +610,25 @@ folly::dynamic HostPlatformViewProps::getDiffProps(
423610
"onTouchCancel");
424611
}
425612

613+
// Borders
614+
auto borderWidths = getBorderWidths();
615+
auto oldBorderWidths = oldProps->getBorderWidths();
616+
if (borderWidths != oldBorderWidths) {
617+
updateBorderWidthProps(result, borderWidths, oldBorderWidths);
618+
}
619+
620+
if (borderStyles != oldProps->borderStyles) {
621+
updateBorderStyleProps(result, borderStyles, oldProps->borderStyles);
622+
}
623+
624+
if (borderColors != oldProps->borderColors) {
625+
updateBorderColorsProps(result, borderColors, oldProps->borderColors);
626+
}
627+
628+
if (borderRadii != oldProps->borderRadii) {
629+
updateBorderRadiusProps(result, borderRadii, oldProps->borderRadii);
630+
}
631+
426632
return result;
427633
}
428634

0 commit comments

Comments
 (0)