@@ -1701,6 +1701,10 @@ static YGCollectFlexItemsRowValues YGCalculateCollectFlexItemsRowValues(
1701
1701
return flexAlgoRowMeasurement;
1702
1702
}
1703
1703
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.
1704
1708
static void YGDistributeFreeSpaceSecondPass (
1705
1709
YGCollectFlexItemsRowValues& collectedFlexItemsValues,
1706
1710
const YGNodeRef node,
@@ -1878,9 +1882,9 @@ static void YGDistributeFreeSpaceSecondPass(
1878
1882
collectedFlexItemsValues.remainingFreeSpace += deltaFreeSpace;
1879
1883
}
1880
1884
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.
1884
1888
static void YGDistributeFreeSpaceFirstPass (
1885
1889
YGCollectFlexItemsRowValues& collectedFlexItemsValues,
1886
1890
const YGFlexDirection mainAxis,
@@ -1959,6 +1963,70 @@ static void YGDistributeFreeSpaceFirstPass(
1959
1963
collectedFlexItemsValues.remainingFreeSpace -= deltaFreeSpace;
1960
1964
}
1961
1965
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
+
1962
2030
//
1963
2031
// This is the main routine that implements a subset of the flexbox layout
1964
2032
// algorithm
@@ -2304,40 +2372,9 @@ static void YGNodelayoutImpl(const YGNodeRef node,
2304
2372
}
2305
2373
2306
2374
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 (
2340
2376
node,
2377
+ collectedFlexItemsValues,
2341
2378
mainAxis,
2342
2379
crossAxis,
2343
2380
mainAxisParentSize,
0 commit comments