From ecd5829bf8d5c884913317ee0197f49251703a11 Mon Sep 17 00:00:00 2001 From: Andrey Mishanin Date: Fri, 30 Jun 2017 09:19:33 -0700 Subject: [PATCH] Overflow detection in Yoga Reviewed By: gkassabli Differential Revision: D5336645 fbshipit-source-id: c4f87d1754d7bac848e8d347b31d619393b94d2c --- ReactCommon/yoga/yoga/Yoga.c | 5 +++++ ReactCommon/yoga/yoga/Yoga.h | 1 + 2 files changed, 6 insertions(+) diff --git a/ReactCommon/yoga/yoga/Yoga.c b/ReactCommon/yoga/yoga/Yoga.c index b94692635..aba42c7d4 100644 --- a/ReactCommon/yoga/yoga/Yoga.c +++ b/ReactCommon/yoga/yoga/Yoga.c @@ -54,6 +54,7 @@ typedef struct YGLayout { uint32_t computedFlexBasisGeneration; float computedFlexBasis; + bool hadOverflow; // Instead of recomputing the entire layout every single time, we // cache some information to break early when nothing changed @@ -192,6 +193,7 @@ static YGNode gYGNodeDefaults = { .lastParentDirection = (YGDirection) -1, .nextCachedMeasurementsIndex = 0, .computedFlexBasis = YGUndefined, + .hadOverflow = false, .measuredDimensions = YG_DEFAULT_DIMENSION_VALUES, .cachedLayout = @@ -782,6 +784,7 @@ YG_NODE_LAYOUT_PROPERTY_IMPL(float, Bottom, position[YGEdgeBottom]); YG_NODE_LAYOUT_PROPERTY_IMPL(float, Width, dimensions[YGDimensionWidth]); YG_NODE_LAYOUT_PROPERTY_IMPL(float, Height, dimensions[YGDimensionHeight]); YG_NODE_LAYOUT_PROPERTY_IMPL(YGDirection, Direction, direction); +YG_NODE_LAYOUT_PROPERTY_IMPL(bool, HadOverflow, hadOverflow); YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Margin, margin); YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Border, border); @@ -2574,12 +2577,14 @@ static void YGNodelayoutImpl(const YGNodeRef node, performLayout && !requiresStretchLayout, "flex", config); + node->layout.hadOverflow = node->layout.hadOverflow || currentRelativeChild->layout.hadOverflow; currentRelativeChild = currentRelativeChild->nextChild; } } remainingFreeSpace = originalRemainingFreeSpace + deltaFreeSpace; + node->layout.hadOverflow = node->layout.hadOverflow || (remainingFreeSpace < 0); // STEP 6: MAIN-AXIS JUSTIFICATION & CROSS-AXIS SIZE DETERMINATION diff --git a/ReactCommon/yoga/yoga/Yoga.h b/ReactCommon/yoga/yoga/Yoga.h index 3579941ce..c3d3260d3 100644 --- a/ReactCommon/yoga/yoga/Yoga.h +++ b/ReactCommon/yoga/yoga/Yoga.h @@ -215,6 +215,7 @@ YG_NODE_LAYOUT_PROPERTY(float, Bottom); YG_NODE_LAYOUT_PROPERTY(float, Width); YG_NODE_LAYOUT_PROPERTY(float, Height); YG_NODE_LAYOUT_PROPERTY(YGDirection, Direction); +YG_NODE_LAYOUT_PROPERTY(bool, HadOverflow); // Get the computed values for these nodes after performing layout. If they were set using // point values then the returned value will be the same as YGNodeStyleGetXXX. However if