Skip to content

Commit 1233eb6

Browse files
coadofacebook-github-bot
authored andcommitted
Add support for other view props to the Animation Backend (#54947)
Summary: ## Summary: Adds support for `borderCurves`, `borderStyles`, `pointerEvents`, `isolation`, `cursor`, `boxShadow`, and `mixBlendMode` props to be passed as `AnimatedProp` to the animation backend. ## Changelog: [General][Added] - Added support for `borderCurves`, `borderStyles`, `pointerEvents`, `isolation`, `cursor`, `boxShadow`, and `mixBlendMode` props to the AnimationBackend. Differential Revision: D89544552
1 parent 451abfd commit 1233eb6

File tree

4 files changed

+429
-0
lines changed

4 files changed

+429
-0
lines changed

packages/react-native/ReactCommon/react/renderer/animationbackend/AnimatedPropSerializer.cpp

Lines changed: 335 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,313 @@ void packOutlineWidth(
198198
dyn.insert("outlineWidth", get<Float>(animatedProp));
199199
}
200200

201+
void packBorderCurveEdge(
202+
folly::dynamic& dyn,
203+
const std::string& propName,
204+
const std::optional<BorderCurve>& curveValue) {
205+
if (curveValue.has_value()) {
206+
std::string curveStr;
207+
switch (curveValue.value()) {
208+
case BorderCurve::Circular:
209+
curveStr = "circular";
210+
break;
211+
case BorderCurve::Continuous:
212+
curveStr = "continuous";
213+
break;
214+
}
215+
dyn.insert(propName, curveStr);
216+
}
217+
}
218+
219+
void packBorderCurves(
220+
folly::dynamic& dyn,
221+
const AnimatedPropBase& animatedProp) {
222+
const auto& borderCurves = get<CascadedBorderCurves>(animatedProp);
223+
224+
packBorderCurveEdge(dyn, "borderTopLeftCurve", borderCurves.topLeft);
225+
packBorderCurveEdge(dyn, "borderTopRightCurve", borderCurves.topRight);
226+
packBorderCurveEdge(dyn, "borderBottomLeftCurve", borderCurves.bottomLeft);
227+
packBorderCurveEdge(dyn, "borderBottomRightCurve", borderCurves.bottomRight);
228+
229+
if (borderCurves.all.has_value()) {
230+
std::string curveStr;
231+
switch (borderCurves.all.value()) {
232+
case BorderCurve::Circular:
233+
curveStr = "circular";
234+
break;
235+
case BorderCurve::Continuous:
236+
curveStr = "continuous";
237+
break;
238+
}
239+
dyn.insert("borderCurve", curveStr);
240+
}
241+
}
242+
243+
std::string borderStyleToString(BorderStyle style) {
244+
switch (style) {
245+
case BorderStyle::Solid:
246+
return "solid";
247+
case BorderStyle::Dotted:
248+
return "dotted";
249+
case BorderStyle::Dashed:
250+
return "dashed";
251+
}
252+
}
253+
254+
void packBorderStyleEdge(
255+
folly::dynamic& dyn,
256+
const std::string& propName,
257+
const std::optional<BorderStyle>& styleValue) {
258+
if (styleValue.has_value()) {
259+
dyn.insert(propName, borderStyleToString(styleValue.value()));
260+
}
261+
}
262+
263+
void packBorderStyles(
264+
folly::dynamic& dyn,
265+
const AnimatedPropBase& animatedProp) {
266+
const auto& borderStyles = get<CascadedBorderStyles>(animatedProp);
267+
268+
packBorderStyleEdge(dyn, "borderLeftStyle", borderStyles.left);
269+
packBorderStyleEdge(dyn, "borderTopStyle", borderStyles.top);
270+
packBorderStyleEdge(dyn, "borderRightStyle", borderStyles.right);
271+
packBorderStyleEdge(dyn, "borderBottomStyle", borderStyles.bottom);
272+
packBorderStyleEdge(dyn, "borderStartStyle", borderStyles.start);
273+
packBorderStyleEdge(dyn, "borderEndStyle", borderStyles.end);
274+
275+
if (borderStyles.all.has_value()) {
276+
dyn.insert("borderStyle", borderStyleToString(borderStyles.all.value()));
277+
}
278+
}
279+
280+
void packPointerEvents(
281+
folly::dynamic& dyn,
282+
const AnimatedPropBase& animatedProp) {
283+
const auto& pointerEvents = get<PointerEventsMode>(animatedProp);
284+
std::string pointerEventsStr;
285+
switch (pointerEvents) {
286+
case PointerEventsMode::Auto:
287+
pointerEventsStr = "auto";
288+
break;
289+
case PointerEventsMode::None:
290+
pointerEventsStr = "none";
291+
break;
292+
case PointerEventsMode::BoxNone:
293+
pointerEventsStr = "box-none";
294+
break;
295+
case PointerEventsMode::BoxOnly:
296+
pointerEventsStr = "box-only";
297+
break;
298+
}
299+
dyn.insert("pointerEvents", pointerEventsStr);
300+
}
301+
302+
void packIsolation(folly::dynamic& dyn, const AnimatedPropBase& animatedProp) {
303+
const auto& isolation = get<Isolation>(animatedProp);
304+
std::string isolationStr;
305+
switch (isolation) {
306+
case Isolation::Auto:
307+
isolationStr = "auto";
308+
break;
309+
case Isolation::Isolate:
310+
isolationStr = "isolate";
311+
break;
312+
}
313+
dyn.insert("isolation", isolationStr);
314+
}
315+
316+
void packCursor(folly::dynamic& dyn, const AnimatedPropBase& animatedProp) {
317+
const auto& cursor = get<Cursor>(animatedProp);
318+
std::string cursorStr;
319+
switch (cursor) {
320+
case Cursor::Auto:
321+
cursorStr = "auto";
322+
break;
323+
case Cursor::Alias:
324+
cursorStr = "alias";
325+
break;
326+
case Cursor::AllScroll:
327+
cursorStr = "all-scroll";
328+
break;
329+
case Cursor::Cell:
330+
cursorStr = "cell";
331+
break;
332+
case Cursor::ColResize:
333+
cursorStr = "col-resize";
334+
break;
335+
case Cursor::ContextMenu:
336+
cursorStr = "context-menu";
337+
break;
338+
case Cursor::Copy:
339+
cursorStr = "copy";
340+
break;
341+
case Cursor::Crosshair:
342+
cursorStr = "crosshair";
343+
break;
344+
case Cursor::Default:
345+
cursorStr = "default";
346+
break;
347+
case Cursor::EResize:
348+
cursorStr = "e-resize";
349+
break;
350+
case Cursor::EWResize:
351+
cursorStr = "ew-resize";
352+
break;
353+
case Cursor::Grab:
354+
cursorStr = "grab";
355+
break;
356+
case Cursor::Grabbing:
357+
cursorStr = "grabbing";
358+
break;
359+
case Cursor::Help:
360+
cursorStr = "help";
361+
break;
362+
case Cursor::Move:
363+
cursorStr = "move";
364+
break;
365+
case Cursor::NResize:
366+
cursorStr = "n-resize";
367+
break;
368+
case Cursor::NEResize:
369+
cursorStr = "ne-resize";
370+
break;
371+
case Cursor::NESWResize:
372+
cursorStr = "nesw-resize";
373+
break;
374+
case Cursor::NSResize:
375+
cursorStr = "ns-resize";
376+
break;
377+
case Cursor::NWResize:
378+
cursorStr = "nw-resize";
379+
break;
380+
case Cursor::NWSEResize:
381+
cursorStr = "nwse-resize";
382+
break;
383+
case Cursor::NoDrop:
384+
cursorStr = "no-drop";
385+
break;
386+
case Cursor::None:
387+
cursorStr = "none";
388+
break;
389+
case Cursor::NotAllowed:
390+
cursorStr = "not-allowed";
391+
break;
392+
case Cursor::Pointer:
393+
cursorStr = "pointer";
394+
break;
395+
case Cursor::Progress:
396+
cursorStr = "progress";
397+
break;
398+
case Cursor::RowResize:
399+
cursorStr = "row-resize";
400+
break;
401+
case Cursor::SResize:
402+
cursorStr = "s-resize";
403+
break;
404+
case Cursor::SEResize:
405+
cursorStr = "se-resize";
406+
break;
407+
case Cursor::SWResize:
408+
cursorStr = "sw-resize";
409+
break;
410+
case Cursor::Text:
411+
cursorStr = "text";
412+
break;
413+
case Cursor::Url:
414+
cursorStr = "url";
415+
break;
416+
case Cursor::WResize:
417+
cursorStr = "w-resize";
418+
break;
419+
case Cursor::Wait:
420+
cursorStr = "wait";
421+
break;
422+
case Cursor::ZoomIn:
423+
cursorStr = "zoom-in";
424+
break;
425+
case Cursor::ZoomOut:
426+
cursorStr = "zoom-out";
427+
break;
428+
}
429+
dyn.insert("cursor", cursorStr);
430+
}
431+
432+
void packBoxShadow(folly::dynamic& dyn, const AnimatedPropBase& animatedProp) {
433+
const auto& boxShadows = get<std::vector<BoxShadow>>(animatedProp);
434+
auto shadowArray = folly::dynamic::array();
435+
for (const auto& shadow : boxShadows) {
436+
folly::dynamic shadowObj = folly::dynamic::object();
437+
shadowObj["offsetX"] = shadow.offsetX;
438+
shadowObj["offsetY"] = shadow.offsetY;
439+
shadowObj["blurRadius"] = shadow.blurRadius;
440+
shadowObj["spreadDistance"] = shadow.spreadDistance;
441+
shadowObj["inset"] = shadow.inset;
442+
if (shadow.color) {
443+
shadowObj["color"] = static_cast<int32_t>(*shadow.color);
444+
}
445+
shadowArray.push_back(shadowObj);
446+
}
447+
dyn.insert("boxShadow", shadowArray);
448+
}
449+
450+
void packMixBlendMode(
451+
folly::dynamic& dyn,
452+
const AnimatedPropBase& animatedProp) {
453+
const auto& blendMode = get<BlendMode>(animatedProp);
454+
std::string blendModeStr;
455+
switch (blendMode) {
456+
case BlendMode::Normal:
457+
blendModeStr = "normal";
458+
break;
459+
case BlendMode::Multiply:
460+
blendModeStr = "multiply";
461+
break;
462+
case BlendMode::Screen:
463+
blendModeStr = "screen";
464+
break;
465+
case BlendMode::Overlay:
466+
blendModeStr = "overlay";
467+
break;
468+
case BlendMode::Darken:
469+
blendModeStr = "darken";
470+
break;
471+
case BlendMode::Lighten:
472+
blendModeStr = "lighten";
473+
break;
474+
case BlendMode::ColorDodge:
475+
blendModeStr = "color-dodge";
476+
break;
477+
case BlendMode::ColorBurn:
478+
blendModeStr = "color-burn";
479+
break;
480+
case BlendMode::HardLight:
481+
blendModeStr = "hard-light";
482+
break;
483+
case BlendMode::SoftLight:
484+
blendModeStr = "soft-light";
485+
break;
486+
case BlendMode::Difference:
487+
blendModeStr = "difference";
488+
break;
489+
case BlendMode::Exclusion:
490+
blendModeStr = "exclusion";
491+
break;
492+
case BlendMode::Hue:
493+
blendModeStr = "hue";
494+
break;
495+
case BlendMode::Saturation:
496+
blendModeStr = "saturation";
497+
break;
498+
case BlendMode::Color:
499+
blendModeStr = "color";
500+
break;
501+
case BlendMode::Luminosity:
502+
blendModeStr = "luminosity";
503+
break;
504+
}
505+
dyn.insert("mixBlendMode", blendModeStr);
506+
}
507+
201508
void packAnimatedProp(
202509
folly::dynamic& dyn,
203510
const std::unique_ptr<AnimatedPropBase>& animatedProp) {
@@ -258,6 +565,34 @@ void packAnimatedProp(
258565
packOutlineWidth(dyn, *animatedProp);
259566
break;
260567

568+
case BORDER_CURVES:
569+
packBorderCurves(dyn, *animatedProp);
570+
break;
571+
572+
case BORDER_STYLES:
573+
packBorderStyles(dyn, *animatedProp);
574+
break;
575+
576+
case POINTER_EVENTS:
577+
packPointerEvents(dyn, *animatedProp);
578+
break;
579+
580+
case ISOLATION:
581+
packIsolation(dyn, *animatedProp);
582+
break;
583+
584+
case CURSOR:
585+
packCursor(dyn, *animatedProp);
586+
break;
587+
588+
case BOX_SHADOW:
589+
packBoxShadow(dyn, *animatedProp);
590+
break;
591+
592+
case MIX_BLEND_MODE:
593+
packMixBlendMode(dyn, *animatedProp);
594+
break;
595+
261596
case WIDTH:
262597
case HEIGHT:
263598
case FLEX:

0 commit comments

Comments
 (0)