From f3ef8f85103938162d77622a2730790dfb3f2d7d Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Wed, 14 Mar 2018 04:17:18 -0700 Subject: [PATCH] Remove the use of YGUndefined for flex-basis Reviewed By: emilsjolander Differential Revision: D7243924 fbshipit-source-id: 2bfaca1a5e3da40d5292a273cabf705f59c9d666 --- ReactCommon/yoga/yoga/YGStyle.cpp | 2 +- ReactCommon/yoga/yoga/Yoga.cpp | 49 ++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/ReactCommon/yoga/yoga/YGStyle.cpp b/ReactCommon/yoga/yoga/YGStyle.cpp index c1f60bb57..031443c8c 100644 --- a/ReactCommon/yoga/yoga/YGStyle.cpp +++ b/ReactCommon/yoga/yoga/YGStyle.cpp @@ -45,7 +45,7 @@ YGStyle::YGStyle() flex(YGFloatOptionalUndefined), flexGrow(YGFloatOptionalUndefined), flexShrink(YGFloatOptionalUndefined), - flexBasis(kYGValueAuto), + flexBasis({0, YGUnitAuto}), margin(kYGDefaultEdgeValuesUnit), position(kYGDefaultEdgeValuesUnit), padding(kYGDefaultEdgeValuesUnit), diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index 107e39c8c..b3f3e2206 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -800,7 +800,54 @@ void YGNodeStyleSetFlexShrink(const YGNodeRef node, const float flexShrink) { } } -YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(YGValue, FlexBasis, flexBasis, flexBasis); +YGValue YGNodeStyleGetFlexBasis(const YGNodeRef node) { + YGValue flexBasis = node->getStyle().flexBasis; + if (flexBasis.unit == YGUnitUndefined || flexBasis.unit == YGUnitAuto) { + // TODO(T26792433): Get rid off the use of YGUndefined at client side + flexBasis.value = YGUndefined; + } + return flexBasis; +} + +void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) { + YGValue value = { + .value = YGFloatSanitize(flexBasis), + .unit = YGFloatIsUndefined(flexBasis) ? YGUnitUndefined : YGUnitPoint, + }; + if ((node->getStyle().flexBasis.value != value.value && + value.unit != YGUnitUndefined) || + node->getStyle().flexBasis.unit != value.unit) { + YGStyle style = node->getStyle(); + style.flexBasis = value; + node->setStyle(style); + node->markDirtyAndPropogate(); + } +} + +void YGNodeStyleSetFlexBasisPercent( + const YGNodeRef node, + const float flexBasisPercent) { + if (node->getStyle().flexBasis.value != flexBasisPercent || + node->getStyle().flexBasis.unit != YGUnitPercent) { + YGStyle style = node->getStyle(); + style.flexBasis.value = YGFloatSanitize(flexBasisPercent); + style.flexBasis.unit = + YGFloatIsUndefined(flexBasisPercent) ? YGUnitAuto : YGUnitPercent; + node->setStyle(style); + node->markDirtyAndPropogate(); + } +} + +void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) { + if (node->getStyle().flexBasis.unit != YGUnitAuto) { + YGStyle style = node->getStyle(); + style.flexBasis.value = 0; + style.flexBasis.unit = YGUnitAuto; + node->setStyle(style); + node->markDirtyAndPropogate(); + } +} + YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Position, position, position); YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Margin, margin, margin); YG_NODE_STYLE_EDGE_PROPERTY_UNIT_AUTO_IMPL(YGValue, Margin, margin);