diff --git a/ReactCommon/yoga/yoga/Utils.cpp b/ReactCommon/yoga/yoga/Utils.cpp index 5c670c31d..6fa8df823 100644 --- a/ReactCommon/yoga/yoga/Utils.cpp +++ b/ReactCommon/yoga/yoga/Utils.cpp @@ -57,3 +57,12 @@ float YGFloatSanitize(const float& val) { float YGUnwrapFloatOptional(const YGFloatOptional& op) { return op.isUndefined() ? YGUndefined : op.getValue(); } + +YGFloatOptional YGFloatOptionalMax( + const YGFloatOptional& op1, + const YGFloatOptional& op2) { + if (!op1.isUndefined() && !op2.isUndefined()) { + return op1.getValue() > op2.getValue() ? op1 : op2; + } + return op1.isUndefined() ? op2 : op1; +} diff --git a/ReactCommon/yoga/yoga/Utils.h b/ReactCommon/yoga/yoga/Utils.h index ce45e348b..6c95b1e7a 100644 --- a/ReactCommon/yoga/yoga/Utils.h +++ b/ReactCommon/yoga/yoga/Utils.h @@ -65,6 +65,10 @@ bool YGFloatsEqual(const float a, const float b); // compiler flag. float YGFloatMax(const float a, const float b); +YGFloatOptional YGFloatOptionalMax( + const YGFloatOptional& op1, + const YGFloatOptional& op2); + // We need custom min function, since we want that, if one argument is // YGUndefined then the min funtion should return the other argument as the min // value. We wouldn't have needed a custom min function if YGUndefined was NAN diff --git a/ReactCommon/yoga/yoga/YGNode.cpp b/ReactCommon/yoga/yoga/YGNode.cpp index d10f19414..913ec329e 100644 --- a/ReactCommon/yoga/yoga/YGNode.cpp +++ b/ReactCommon/yoga/yoga/YGNode.cpp @@ -654,21 +654,21 @@ float YGNode::getTrailingBorder(const YGFlexDirection flexDirection) const { return YGFloatMax(computedEdgeValue, 0.0f); } -float YGNode::getLeadingPadding( - const YGFlexDirection axis, - const float widthSize) const { +YGFloatOptional YGNode::getLeadingPadding( + const YGFlexDirection& axis, + const float& widthSize) const { + const YGFloatOptional& paddingEdgeStart = + YGResolveValue(style_.padding[YGEdgeStart], widthSize); if (YGFlexDirectionIsRow(axis) && style_.padding[YGEdgeStart].unit != YGUnitUndefined && - !YGResolveValue(style_.padding[YGEdgeStart], widthSize).isUndefined() && - YGUnwrapFloatOptional( - YGResolveValue(style_.padding[YGEdgeStart], widthSize)) > 0.0f) { - return YGUnwrapFloatOptional(YGResolveValue(style_.padding[YGEdgeStart], widthSize)); + !paddingEdgeStart.isUndefined() && paddingEdgeStart.getValue() > 0.0f) { + return paddingEdgeStart; } - float resolvedValue = YGUnwrapFloatOptional(YGResolveValue( + YGFloatOptional resolvedValue = YGResolveValue( *YGComputedEdgeValue(style_.padding, leading[axis], &YGValueZero), - widthSize)); - return YGFloatMax(resolvedValue, 0.0f); + widthSize); + return YGFloatOptionalMax(resolvedValue, YGFloatOptional(0.0f)); } float YGNode::getTrailingPadding( @@ -692,7 +692,8 @@ float YGNode::getTrailingPadding( float YGNode::getLeadingPaddingAndBorder( const YGFlexDirection axis, const float widthSize) const { - return getLeadingPadding(axis, widthSize) + getLeadingBorder(axis); + return YGUnwrapFloatOptional(getLeadingPadding(axis, widthSize)) + + getLeadingBorder(axis); } float YGNode::getTrailingPaddingAndBorder( diff --git a/ReactCommon/yoga/yoga/YGNode.h b/ReactCommon/yoga/yoga/YGNode.h index 02afb830e..cdb6fae47 100644 --- a/ReactCommon/yoga/yoga/YGNode.h +++ b/ReactCommon/yoga/yoga/YGNode.h @@ -93,7 +93,9 @@ struct YGNode { float getTrailingMargin(const YGFlexDirection axis, const float widthSize) const; float getLeadingBorder(const YGFlexDirection flexDirection) const; float getTrailingBorder(const YGFlexDirection flexDirection) const; - float getLeadingPadding(const YGFlexDirection axis, const float widthSize) const; + YGFloatOptional getLeadingPadding( + const YGFlexDirection& axis, + const float& widthSize) const; float getTrailingPadding(const YGFlexDirection axis, const float widthSize) const; float getLeadingPaddingAndBorder( const YGFlexDirection axis, diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index 271eff3a2..12f8facb1 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -2573,11 +2573,15 @@ static void YGNodelayoutImpl(const YGNodeRef node, node->getTrailingBorder(flexColumnDirection), YGEdgeBottom); node->setLayoutPadding( - node->getLeadingPadding(flexRowDirection, ownerWidth), YGEdgeStart); + YGUnwrapFloatOptional( + node->getLeadingPadding(flexRowDirection, ownerWidth)), + YGEdgeStart); node->setLayoutPadding( node->getTrailingPadding(flexRowDirection, ownerWidth), YGEdgeEnd); node->setLayoutPadding( - node->getLeadingPadding(flexColumnDirection, ownerWidth), YGEdgeTop); + YGUnwrapFloatOptional( + node->getLeadingPadding(flexColumnDirection, ownerWidth)), + YGEdgeTop); node->setLayoutPadding( node->getTrailingPadding(flexColumnDirection, ownerWidth), YGEdgeBottom);