Fix flex basis not accounting for max size constraint

Reviewed By: gkassabli

Differential Revision: D5044314

fbshipit-source-id: d9f9db832e4943a57a89c9d162ff6077b709795a
This commit is contained in:
Emil Sjolander
2017-05-12 09:03:22 -07:00
committed by Facebook Github Bot
parent 56e44a7fdd
commit 54548894d0
2 changed files with 64 additions and 46 deletions

View File

@@ -449,7 +449,8 @@ void YGNodeSetMeasureFunc(const YGNodeRef node, YGMeasureFunc measureFunc) {
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate places in Litho
node->nodeType = YGNodeTypeDefault;
} else {
YGAssertWithNode(node,
YGAssertWithNode(
node,
YGNodeGetChildCount(node) == 0,
"Cannot set measure function: Nodes with measure functions cannot have children.");
node->measure = measureFunc;
@@ -471,7 +472,9 @@ YGBaselineFunc YGNodeGetBaselineFunc(const YGNodeRef node) {
}
void YGNodeInsertChild(const YGNodeRef node, const YGNodeRef child, const uint32_t index) {
YGAssertWithNode(node, child->parent == NULL, "Child already has a parent, it must be removed first.");
YGAssertWithNode(node,
child->parent == NULL,
"Child already has a parent, it must be removed first.");
YGAssertWithNode(node,
node->measure == NULL,
"Cannot add child: Nodes with measure functions cannot have children.");
@@ -704,7 +707,9 @@ static inline const YGValue *YGNodeResolveFlexBasisPtr(const YGNodeRef node) {
#define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \
type YGNodeLayoutGet##name(const YGNodeRef node, const YGEdge edge) { \
YGAssertWithNode(node, edge < YGEdgeEnd, "Cannot get layout properties of multi-edge shorthands"); \
YGAssertWithNode(node, \
edge < YGEdgeEnd, \
"Cannot get layout properties of multi-edge shorthands"); \
\
if (edge == YGEdgeLeft) { \
if (node->layout.direction == YGDirectionRTL) { \
@@ -1949,11 +1954,13 @@ static void YGNodelayoutImpl(const YGNodeRef node,
const bool performLayout,
const YGConfigRef config) {
YGAssertWithNode(node,
YGFloatIsUndefined(availableWidth) ? widthMeasureMode == YGMeasureModeUndefined : true,
YGFloatIsUndefined(availableWidth) ? widthMeasureMode == YGMeasureModeUndefined
: true,
"availableWidth is indefinite so widthMeasureMode must be "
"YGMeasureModeUndefined");
YGAssertWithNode(node,
YGFloatIsUndefined(availableHeight) ? heightMeasureMode == YGMeasureModeUndefined : true,
YGFloatIsUndefined(availableHeight) ? heightMeasureMode == YGMeasureModeUndefined
: true,
"availableHeight is indefinite so heightMeasureMode must be "
"YGMeasureModeUndefined");
@@ -2337,7 +2344,12 @@ static void YGNodelayoutImpl(const YGNodeRef node,
float deltaFlexGrowFactors = 0;
currentRelativeChild = firstRelativeChild;
while (currentRelativeChild != NULL) {
childFlexBasis = currentRelativeChild->layout.computedFlexBasis;
childFlexBasis =
fminf(YGResolveValue(&currentRelativeChild->style.maxDimensions[dim[mainAxis]],
mainAxisParentSize),
fmaxf(YGResolveValue(&currentRelativeChild->style.minDimensions[dim[mainAxis]],
mainAxisParentSize),
currentRelativeChild->layout.computedFlexBasis));
if (remainingFreeSpace < 0) {
flexShrinkScaledFactor = -YGNodeResolveFlexShrink(currentRelativeChild) * childFlexBasis;
@@ -2375,6 +2387,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
baseMainSize,
availableInnerMainDim,
availableInnerWidth);
if (baseMainSize != boundMainSize) {
// By excluding this item's size and flex factor from remaining,
// this item's
@@ -2399,7 +2412,12 @@ static void YGNodelayoutImpl(const YGNodeRef node,
deltaFreeSpace = 0;
currentRelativeChild = firstRelativeChild;
while (currentRelativeChild != NULL) {
childFlexBasis = currentRelativeChild->layout.computedFlexBasis;
childFlexBasis =
fminf(YGResolveValue(&currentRelativeChild->style.maxDimensions[dim[mainAxis]],
mainAxisParentSize),
fmaxf(YGResolveValue(&currentRelativeChild->style.minDimensions[dim[mainAxis]],
mainAxisParentSize),
currentRelativeChild->layout.computedFlexBasis));
float updatedMainSize = childFlexBasis;
if (remainingFreeSpace < 0) {