From 2c3e4ec06be93e34ba08760c2115a6b1fdb0fa25 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Fri, 7 Sep 2018 11:12:30 -0700 Subject: [PATCH] Fabric: `borderWidths` field was removed from ViewProps Summary: @public Apperently, we don't need to store and parse this because we are already doing this for `yogaStyle` field. Reviewed By: sahrens Differential Revision: D9649549 fbshipit-source-id: a84a5518674f4c2d574a060cdbebb9562121f5f4 --- .../ComponentViews/View/RCTViewComponentView.mm | 1 - ReactCommon/fabric/components/view/ViewProps.cpp | 13 ++++++++++++- ReactCommon/fabric/components/view/ViewProps.h | 1 - ReactCommon/fabric/components/view/conversions.h | 13 +++++++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm index 74dfdba76..77cb3d1e5 100644 --- a/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm @@ -158,7 +158,6 @@ using namespace facebook::react; // `border` if ( - oldViewProps.borderWidths != newViewProps.borderWidths || oldViewProps.borderStyles != newViewProps.borderStyles || oldViewProps.borderRadii != newViewProps.borderRadii || oldViewProps.borderColors != newViewProps.borderColors diff --git a/ReactCommon/fabric/components/view/ViewProps.cpp b/ReactCommon/fabric/components/view/ViewProps.cpp index f656882fc..91dba8460 100644 --- a/ReactCommon/fabric/components/view/ViewProps.cpp +++ b/ReactCommon/fabric/components/view/ViewProps.cpp @@ -25,7 +25,6 @@ ViewProps::ViewProps(const ViewProps &sourceProps, const RawProps &rawProps): opacity(convertRawProp(rawProps, "opacity", sourceProps.opacity, (Float)1.0)), foregroundColor(convertRawProp(rawProps, "foregroundColor", sourceProps.foregroundColor)), backgroundColor(convertRawProp(rawProps, "backgroundColor", sourceProps.backgroundColor)), - borderWidths(convertRawProp(rawProps, "border", "Width", sourceProps.borderWidths)), borderRadii(convertRawProp(rawProps, "border", "Radius", sourceProps.borderRadii)), borderColors(convertRawProp(rawProps, "border", "Color", sourceProps.borderColors)), borderStyles(convertRawProp(rawProps, "border", "Style", sourceProps.borderStyles)), @@ -44,6 +43,18 @@ ViewProps::ViewProps(const ViewProps &sourceProps, const RawProps &rawProps): #pragma mark - Convenience Methods BorderMetrics ViewProps::resolveBorderMetrics(bool isRTL) const { + auto borderWidths = CascadedBorderWidths { + .left = optionalFloatFromYogaValue(yogaStyle.border[YGEdgeLeft]), + .top = optionalFloatFromYogaValue(yogaStyle.border[YGEdgeTop]), + .right = optionalFloatFromYogaValue(yogaStyle.border[YGEdgeRight]), + .bottom = optionalFloatFromYogaValue(yogaStyle.border[YGEdgeBottom]), + .start = optionalFloatFromYogaValue(yogaStyle.border[YGEdgeStart]), + .end = optionalFloatFromYogaValue(yogaStyle.border[YGEdgeEnd]), + .horizontal = optionalFloatFromYogaValue(yogaStyle.border[YGEdgeHorizontal]), + .vertical = optionalFloatFromYogaValue(yogaStyle.border[YGEdgeVertical]), + .all = optionalFloatFromYogaValue(yogaStyle.border[YGEdgeAll]) + }; + return { .borderColors = borderColors.resolve(isRTL, {}), .borderWidths = borderWidths.resolve(isRTL, 0), diff --git a/ReactCommon/fabric/components/view/ViewProps.h b/ReactCommon/fabric/components/view/ViewProps.h index 9ac4fa296..9af01c710 100644 --- a/ReactCommon/fabric/components/view/ViewProps.h +++ b/ReactCommon/fabric/components/view/ViewProps.h @@ -39,7 +39,6 @@ public: const SharedColor backgroundColor {}; // Borders - const CascadedBorderWidths borderWidths {}; const CascadedBorderRadii borderRadii {}; const CascadedBorderColors borderColors {}; const CascadedBorderStyles borderStyles {}; diff --git a/ReactCommon/fabric/components/view/conversions.h b/ReactCommon/fabric/components/view/conversions.h index 76dc48909..244e15b63 100644 --- a/ReactCommon/fabric/components/view/conversions.h +++ b/ReactCommon/fabric/components/view/conversions.h @@ -58,6 +58,19 @@ inline YGValue yogaStyleValueFromFloat(const Float &value) { return {(float)value, YGUnitPoint}; } +inline folly::Optional optionalFloatFromYogaValue(const YGValue &value, folly::Optional base = {}) { + switch (value.unit) { + case YGUnitUndefined: + return {}; + case YGUnitPoint: + return fabricFloatFromYogaFloat(value.value); + case YGUnitPercent: + return base.has_value() ? folly::Optional(base.value() * fabricFloatFromYogaFloat(value.value)) : folly::Optional(); + case YGUnitAuto: + return {}; + } +} + inline LayoutMetrics layoutMetricsFromYogaNode(YGNode &yogaNode) { LayoutMetrics layoutMetrics;