@@ -1701,6 +1701,10 @@ static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues(
17011701 return flexAlgoRowMeasurement;
17021702}
17031703
1704+ // It distributes the free space to the flexible items and ensures that the size
1705+ // of the flex items abide the min and max constraints. At the end of this
1706+ // function the child nodes would have proper size. Prior using this function
1707+ // please ensure that YGDistributeFreeSpaceFirstPass is called.
17041708static void YGDistributeFreeSpaceSecondPass (
17051709 YGCollectFlexItemsRowValues& collectedFlexItemsValues,
17061710 const YGNodeRef node,
@@ -1878,9 +1882,9 @@ static void YGDistributeFreeSpaceSecondPass(
18781882 collectedFlexItemsValues.remainingFreeSpace += deltaFreeSpace;
18791883}
18801884
1881- // It distributes the free space to the flexible items, for those flexible items
1882- // whose min and max constraints are triggered, the clamped size is removed from
1883- // the remaingfreespace.
1885+ // It distributes the free space to the flexible items.For those flexible items
1886+ // whose min and max constraints are triggered, those flex item's clamped size
1887+ // is removed from the remaingfreespace.
18841888static void YGDistributeFreeSpaceFirstPass (
18851889 YGCollectFlexItemsRowValues& collectedFlexItemsValues,
18861890 const YGFlexDirection mainAxis,
@@ -1959,6 +1963,70 @@ static void YGDistributeFreeSpaceFirstPass(
19591963 collectedFlexItemsValues.remainingFreeSpace -= deltaFreeSpace;
19601964}
19611965
1966+ // Do two passes over the flex items to figure out how to distribute the
1967+ // remaining space.
1968+ // The first pass finds the items whose min/max constraints trigger,
1969+ // freezes them at those
1970+ // sizes, and excludes those sizes from the remaining space. The second
1971+ // pass sets the size
1972+ // of each flexible item. It distributes the remaining space amongst the
1973+ // items whose min/max
1974+ // constraints didn't trigger in pass 1. For the other items, it sets
1975+ // their sizes by forcing
1976+ // their min/max constraints to trigger again.
1977+ //
1978+ // This two pass approach for resolving min/max constraints deviates from
1979+ // the spec. The
1980+ // spec (https://www.w3.org/TR/YG-flexbox-1/#resolve-flexible-lengths)
1981+ // describes a process
1982+ // that needs to be repeated a variable number of times. The algorithm
1983+ // implemented here
1984+ // won't handle all cases but it was simpler to implement and it mitigates
1985+ // performance
1986+ // concerns because we know exactly how many passes it'll do.
1987+ //
1988+ // At the end of this function the child nodes would have the proper size
1989+ // assigned to them.
1990+ //
1991+ static void YGResolveFlexibleLength (
1992+ const YGNodeRef node,
1993+ YGCollectFlexItemsRowValues& collectedFlexItemsValues,
1994+ const YGFlexDirection mainAxis,
1995+ const YGFlexDirection crossAxis,
1996+ const float mainAxisParentSize,
1997+ const float availableInnerMainDim,
1998+ const float availableInnerCrossDim,
1999+ const float availableInnerWidth,
2000+ const float availableInnerHeight,
2001+ const bool flexBasisOverflows,
2002+ const YGMeasureMode measureModeCrossDim,
2003+ const bool performLayout,
2004+ const YGConfigRef config) {
2005+ // First pass: detect the flex items whose min/max constraints trigger
2006+ YGDistributeFreeSpaceFirstPass (
2007+ collectedFlexItemsValues,
2008+ mainAxis,
2009+ mainAxisParentSize,
2010+ availableInnerMainDim,
2011+ availableInnerWidth);
2012+
2013+ // Second pass: resolve the sizes of the flexible items
2014+ YGDistributeFreeSpaceSecondPass (
2015+ collectedFlexItemsValues,
2016+ node,
2017+ mainAxis,
2018+ crossAxis,
2019+ mainAxisParentSize,
2020+ availableInnerMainDim,
2021+ availableInnerCrossDim,
2022+ availableInnerWidth,
2023+ availableInnerHeight,
2024+ flexBasisOverflows,
2025+ measureModeCrossDim,
2026+ performLayout,
2027+ config);
2028+ }
2029+
19622030//
19632031// This is the main routine that implements a subset of the flexbox layout
19642032// algorithm
@@ -2304,40 +2372,9 @@ static void YGNodelayoutImpl(const YGNodeRef node,
23042372 }
23052373
23062374 if (!canSkipFlex) {
2307- // Do two passes over the flex items to figure out how to distribute the
2308- // remaining space.
2309- // The first pass finds the items whose min/max constraints trigger,
2310- // freezes them at those
2311- // sizes, and excludes those sizes from the remaining space. The second
2312- // pass sets the size
2313- // of each flexible item. It distributes the remaining space amongst the
2314- // items whose min/max
2315- // constraints didn't trigger in pass 1. For the other items, it sets
2316- // their sizes by forcing
2317- // their min/max constraints to trigger again.
2318- //
2319- // This two pass approach for resolving min/max constraints deviates from
2320- // the spec. The
2321- // spec (https://www.w3.org/TR/YG-flexbox-1/#resolve-flexible-lengths)
2322- // describes a process
2323- // that needs to be repeated a variable number of times. The algorithm
2324- // implemented here
2325- // won't handle all cases but it was simpler to implement and it mitigates
2326- // performance
2327- // concerns because we know exactly how many passes it'll do.
2328-
2329- // First pass: detect the flex items whose min/max constraints trigger
2330- YGDistributeFreeSpaceFirstPass (
2331- collectedFlexItemsValues,
2332- mainAxis,
2333- mainAxisParentSize,
2334- availableInnerMainDim,
2335- availableInnerWidth);
2336-
2337- // Second pass: resolve the sizes of the flexible items
2338- YGDistributeFreeSpaceSecondPass (
2339- collectedFlexItemsValues,
2375+ YGResolveFlexibleLength (
23402376 node,
2377+ collectedFlexItemsValues,
23412378 mainAxis,
23422379 crossAxis,
23432380 mainAxisParentSize,
0 commit comments