diff --git a/ReactCommon/yoga/yoga/YGNode.cpp b/ReactCommon/yoga/yoga/YGNode.cpp index e3e44e720..df61b14a8 100644 --- a/ReactCommon/yoga/yoga/YGNode.cpp +++ b/ReactCommon/yoga/yoga/YGNode.cpp @@ -605,8 +605,8 @@ float YGNode::resolveFlexShrink() { if (parent_ == nullptr) { return 0.0; } - if (!YGFloatIsUndefined(style_.flexShrink)) { - return style_.flexShrink; + if (!style_.flexShrink.isUndefined) { + return style_.flexShrink.value; } if (!config_->useWebDefaults && !style_.flex.isUndefined && style_.flex.value < 0.0f) { diff --git a/ReactCommon/yoga/yoga/YGNodePrint.cpp b/ReactCommon/yoga/yoga/YGNodePrint.cpp index fd515b51d..8585b7251 100644 --- a/ReactCommon/yoga/yoga/YGNodePrint.cpp +++ b/ReactCommon/yoga/yoga/YGNodePrint.cpp @@ -48,13 +48,6 @@ static void appendFloatOptionalIfDefined( } } -static void -appendFloatIfNotUndefined(string* base, const string key, const float num) { - if (!YGFloatIsUndefined(num)) { - appendFormatedString(base, "%s: %g; ", key.c_str(), num); - } -} - static void appendNumberIfNotUndefined( string* base, const string key, @@ -162,7 +155,8 @@ void YGNodeToString( str, "align-self: %s; ", YGAlignToString(node->getStyle().alignSelf)); } appendFloatOptionalIfDefined(str, "flex-grow", node->getStyle().flexGrow); - appendFloatIfNotUndefined(str, "flex-shrink", node->getStyle().flexShrink); + appendFloatOptionalIfDefined( + str, "flex-shrink", node->getStyle().flexShrink); appendNumberIfNotAuto(str, "flex-basis", node->getStyle().flexBasis); appendFloatOptionalIfDefined(str, "flex", node->getStyle().flex); diff --git a/ReactCommon/yoga/yoga/YGStyle.cpp b/ReactCommon/yoga/yoga/YGStyle.cpp index d3c18e0ec..c1f60bb57 100644 --- a/ReactCommon/yoga/yoga/YGStyle.cpp +++ b/ReactCommon/yoga/yoga/YGStyle.cpp @@ -44,7 +44,7 @@ YGStyle::YGStyle() display(YGDisplayFlex), flex(YGFloatOptionalUndefined), flexGrow(YGFloatOptionalUndefined), - flexShrink(YGUndefined), + flexShrink(YGFloatOptionalUndefined), flexBasis(kYGValueAuto), margin(kYGDefaultEdgeValuesUnit), position(kYGDefaultEdgeValuesUnit), @@ -86,10 +86,11 @@ bool YGStyle::operator==(const YGStyle& style) { areNonFloatValuesEqual && flexGrow.value == style.flexGrow.value; } - if (!(YGFloatIsUndefined(flexShrink) && - YGFloatIsUndefined(style.flexShrink))) { + areNonFloatValuesEqual = areNonFloatValuesEqual && + flexShrink.isUndefined == style.flexShrink.isUndefined; + if (areNonFloatValuesEqual && !style.flexShrink.isUndefined) { areNonFloatValuesEqual = - areNonFloatValuesEqual && flexShrink == style.flexShrink; + areNonFloatValuesEqual && flexShrink.value == style.flexShrink.value; } if (!(YGFloatIsUndefined(aspectRatio) && diff --git a/ReactCommon/yoga/yoga/YGStyle.h b/ReactCommon/yoga/yoga/YGStyle.h index 0da5b77fd..3abc4c084 100644 --- a/ReactCommon/yoga/yoga/YGStyle.h +++ b/ReactCommon/yoga/yoga/YGStyle.h @@ -22,7 +22,7 @@ struct YGStyle { YGDisplay display; YGFloatOptional flex; YGFloatOptional flexGrow; - float flexShrink; + YGFloatOptional flexShrink; YGValue flexBasis; std::array margin; std::array position; diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index fd3a88a2d..107e39c8c 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -517,10 +517,10 @@ float YGNodeStyleGetFlexGrow(const YGNodeRef node) { } float YGNodeStyleGetFlexShrink(const YGNodeRef node) { - return YGFloatIsUndefined(node->getStyle().flexShrink) + return node->getStyle().flexShrink.isUndefined ? (node->getConfig()->useWebDefaults ? kWebDefaultFlexShrink : kDefaultFlexShrink) - : node->getStyle().flexShrink; + : node->getStyle().flexShrink.value; } #define YG_NODE_STYLE_PROPERTY_SETTER_IMPL( \ @@ -786,10 +786,21 @@ void YGNodeStyleSetFlexGrow(const YGNodeRef node, const float flexGrow) { } } -// YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexGrow, flexGrow, flexGrow); -YG_NODE_STYLE_PROPERTY_SETTER_IMPL(float, FlexShrink, flexShrink, flexShrink); -YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(YGValue, FlexBasis, flexBasis, flexBasis); +// TODO(T26792433): Change the API to accept YGFloatOptional. +void YGNodeStyleSetFlexShrink(const YGNodeRef node, const float flexShrink) { + if (!YGFloatOptionalFloatEquals(node->getStyle().flexShrink, flexShrink)) { + YGStyle style = node->getStyle(); + if (YGFloatIsUndefined(flexShrink)) { + style.flexGrow = {true, 0}; + } else { + style.flexShrink = {false, flexShrink}; + } + node->setStyle(style); + node->markDirtyAndPropogate(); + } +} +YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(YGValue, FlexBasis, flexBasis, flexBasis); 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);