@@ -211,6 +211,10 @@ bool YGNodeIsDirty(YGNodeRef node) {
211
211
return node->isDirty ();
212
212
}
213
213
214
+ bool YGNodeLayoutGetDidUseLegacyFlag (const YGNodeRef node) {
215
+ return node->didUseLegacyFlag ();
216
+ }
217
+
214
218
int32_t gNodeInstanceCount = 0 ;
215
219
int32_t gConfigInstanceCount = 0 ;
216
220
@@ -243,6 +247,29 @@ YGNodeRef YGNodeClone(YGNodeRef oldNode) {
243
247
return node;
244
248
}
245
249
250
+ static YGNodeRef YGNodeDeepClone (YGNodeRef oldNode) {
251
+ YGNodeRef node = YGNodeClone (oldNode);
252
+ YGVector vec = YGVector ();
253
+ vec.reserve (oldNode->getChildren ().size ());
254
+ YGNodeRef childNode = nullptr ;
255
+ for (auto & item : oldNode->getChildren ()) {
256
+ childNode = YGNodeDeepClone (item);
257
+ childNode->setParent (node);
258
+ vec.push_back (childNode);
259
+ }
260
+ node->setChildren (vec);
261
+
262
+ if (oldNode->getNextChild () != nullptr ) {
263
+ node->setNextChild (YGNodeDeepClone (oldNode->getNextChild ()));
264
+ }
265
+
266
+ if (node->getConfig () != nullptr ) {
267
+ node->setConfig (new YGConfig (*node->getConfig ()));
268
+ }
269
+
270
+ return node;
271
+ }
272
+
246
273
void YGNodeFree (const YGNodeRef node) {
247
274
if (node->getParent ()) {
248
275
node->getParent ()->removeChild (node);
@@ -1975,10 +2002,15 @@ static void YGNodelayoutImpl(const YGNodeRef node,
1975
2002
} else {
1976
2003
if (!node->getConfig ()->useLegacyStretchBehaviour &&
1977
2004
(totalFlexGrowFactors == 0 || node->resolveFlexGrow () == 0 )) {
1978
- // If we don't have any children to flex or we can't flex the node itself,
1979
- // space we've used is all space we need. Root node also should be shrunk to minimum
2005
+ // If we don't have any children to flex or we can't flex the node
2006
+ // itself, space we've used is all space we need. Root node also
2007
+ // should be shrunk to minimum
1980
2008
availableInnerMainDim = sizeConsumedOnCurrentLine;
1981
2009
}
2010
+
2011
+ if (node->getConfig ()->useLegacyStretchBehaviour ) {
2012
+ node->setLayoutDidUseLegacyFlag (true );
2013
+ }
1982
2014
sizeBasedOnContent = !node->getConfig ()->useLegacyStretchBehaviour ;
1983
2015
}
1984
2016
}
@@ -3330,7 +3362,6 @@ void YGNodeCalculateLayout(const YGNodeRef node,
3330
3362
// input
3331
3363
// parameters don't change.
3332
3364
gCurrentGenerationCount ++;
3333
-
3334
3365
node->resolveDimension ();
3335
3366
float width = YGUndefined;
3336
3367
YGMeasureMode widthMeasureMode = YGMeasureModeUndefined;
@@ -3396,6 +3427,59 @@ void YGNodeCalculateLayout(const YGNodeRef node,
3396
3427
YGPrintOptionsStyle));
3397
3428
}
3398
3429
}
3430
+
3431
+ bool didUseLegacyFlag = node->didUseLegacyFlag ();
3432
+
3433
+ // We want to get rid off `useLegacyStretchBehaviour` from YGConfig. But we
3434
+ // aren't sure whether client's of yoga have gotten rid off this flag or not.
3435
+ // So logging this in YGLayout would help to find out the call sites depending
3436
+ // on this flag. This check would be removed once we are sure no one is
3437
+ // dependent on this flag anymore.
3438
+ if (didUseLegacyFlag) {
3439
+ const YGNodeRef originalNode = YGNodeDeepClone (node);
3440
+ originalNode->resolveDimension ();
3441
+ // Recursively mark nodes as dirty
3442
+ originalNode->markDirtyAndPropogateDownwards ();
3443
+ gCurrentGenerationCount ++;
3444
+ // Rerun the layout, and calculate the diff
3445
+ originalNode->setAndPropogateUseLegacyFlag (false );
3446
+ if (YGLayoutNodeInternal (
3447
+ originalNode,
3448
+ width,
3449
+ height,
3450
+ parentDirection,
3451
+ widthMeasureMode,
3452
+ heightMeasureMode,
3453
+ parentWidth,
3454
+ parentHeight,
3455
+ true ,
3456
+ " initial" ,
3457
+ originalNode->getConfig ())) {
3458
+ originalNode->setPosition (
3459
+ originalNode->getLayout ().direction ,
3460
+ parentWidth,
3461
+ parentHeight,
3462
+ parentWidth);
3463
+ YGRoundToPixelGrid (
3464
+ originalNode,
3465
+ originalNode->getConfig ()->pointScaleFactor ,
3466
+ 0 .0f ,
3467
+ 0 .0f );
3468
+
3469
+ // Set whether the two layouts are different or not.
3470
+ node->setLayoutDoesLegacyFlagAffectsLayout (
3471
+ !originalNode->isLayoutTreeEqualToNode (*node));
3472
+
3473
+ if (gPrintTree ) {
3474
+ YGNodePrint (
3475
+ originalNode,
3476
+ (YGPrintOptions)(
3477
+ YGPrintOptionsLayout | YGPrintOptionsChildren |
3478
+ YGPrintOptionsStyle));
3479
+ }
3480
+ }
3481
+ YGNodeFreeRecursive (originalNode);
3482
+ }
3399
3483
}
3400
3484
3401
3485
void YGConfigSetLogger (const YGConfigRef config, YGLogger logger) {
0 commit comments