Remove the use of legacy flag and log the diff if its used
Summary: Check if the layout tree is different if we do not use legacy flags. If they are different then report to the client Reviewed By: emilsjolander Differential Revision: D6856812 fbshipit-source-id: e4724d80702cc75c1894e348e137b24e663573d2
This commit is contained in:
committed by
Facebook Github Bot
parent
66045bd13d
commit
63be3ff84c
@@ -211,6 +211,10 @@ bool YGNodeIsDirty(YGNodeRef node) {
|
||||
return node->isDirty();
|
||||
}
|
||||
|
||||
bool YGNodeLayoutGetDidUseLegacyFlag(const YGNodeRef node) {
|
||||
return node->didUseLegacyFlag();
|
||||
}
|
||||
|
||||
int32_t gNodeInstanceCount = 0;
|
||||
int32_t gConfigInstanceCount = 0;
|
||||
|
||||
@@ -243,6 +247,29 @@ YGNodeRef YGNodeClone(YGNodeRef oldNode) {
|
||||
return node;
|
||||
}
|
||||
|
||||
static YGNodeRef YGNodeDeepClone(YGNodeRef oldNode) {
|
||||
YGNodeRef node = YGNodeClone(oldNode);
|
||||
YGVector vec = YGVector();
|
||||
vec.reserve(oldNode->getChildren().size());
|
||||
YGNodeRef childNode = nullptr;
|
||||
for (auto& item : oldNode->getChildren()) {
|
||||
childNode = YGNodeDeepClone(item);
|
||||
childNode->setParent(node);
|
||||
vec.push_back(childNode);
|
||||
}
|
||||
node->setChildren(vec);
|
||||
|
||||
if (oldNode->getNextChild() != nullptr) {
|
||||
node->setNextChild(YGNodeDeepClone(oldNode->getNextChild()));
|
||||
}
|
||||
|
||||
if (node->getConfig() != nullptr) {
|
||||
node->setConfig(new YGConfig(*node->getConfig()));
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
void YGNodeFree(const YGNodeRef node) {
|
||||
if (node->getParent()) {
|
||||
node->getParent()->removeChild(node);
|
||||
@@ -1975,10 +2002,15 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
||||
} else {
|
||||
if (!node->getConfig()->useLegacyStretchBehaviour &&
|
||||
(totalFlexGrowFactors == 0 || node->resolveFlexGrow() == 0)) {
|
||||
// If we don't have any children to flex or we can't flex the node itself,
|
||||
// space we've used is all space we need. Root node also should be shrunk to minimum
|
||||
// If we don't have any children to flex or we can't flex the node
|
||||
// itself, space we've used is all space we need. Root node also
|
||||
// should be shrunk to minimum
|
||||
availableInnerMainDim = sizeConsumedOnCurrentLine;
|
||||
}
|
||||
|
||||
if (node->getConfig()->useLegacyStretchBehaviour) {
|
||||
node->setLayoutDidUseLegacyFlag(true);
|
||||
}
|
||||
sizeBasedOnContent = !node->getConfig()->useLegacyStretchBehaviour;
|
||||
}
|
||||
}
|
||||
@@ -3330,7 +3362,6 @@ void YGNodeCalculateLayout(const YGNodeRef node,
|
||||
// input
|
||||
// parameters don't change.
|
||||
gCurrentGenerationCount++;
|
||||
|
||||
node->resolveDimension();
|
||||
float width = YGUndefined;
|
||||
YGMeasureMode widthMeasureMode = YGMeasureModeUndefined;
|
||||
@@ -3396,6 +3427,59 @@ void YGNodeCalculateLayout(const YGNodeRef node,
|
||||
YGPrintOptionsStyle));
|
||||
}
|
||||
}
|
||||
|
||||
bool didUseLegacyFlag = node->didUseLegacyFlag();
|
||||
|
||||
// We want to get rid off `useLegacyStretchBehaviour` from YGConfig. But we
|
||||
// aren't sure whether client's of yoga have gotten rid off this flag or not.
|
||||
// So logging this in YGLayout would help to find out the call sites depending
|
||||
// on this flag. This check would be removed once we are sure no one is
|
||||
// dependent on this flag anymore.
|
||||
if (didUseLegacyFlag) {
|
||||
const YGNodeRef originalNode = YGNodeDeepClone(node);
|
||||
originalNode->resolveDimension();
|
||||
// Recursively mark nodes as dirty
|
||||
originalNode->markDirtyAndPropogateDownwards();
|
||||
gCurrentGenerationCount++;
|
||||
// Rerun the layout, and calculate the diff
|
||||
originalNode->setAndPropogateUseLegacyFlag(false);
|
||||
if (YGLayoutNodeInternal(
|
||||
originalNode,
|
||||
width,
|
||||
height,
|
||||
parentDirection,
|
||||
widthMeasureMode,
|
||||
heightMeasureMode,
|
||||
parentWidth,
|
||||
parentHeight,
|
||||
true,
|
||||
"initial",
|
||||
originalNode->getConfig())) {
|
||||
originalNode->setPosition(
|
||||
originalNode->getLayout().direction,
|
||||
parentWidth,
|
||||
parentHeight,
|
||||
parentWidth);
|
||||
YGRoundToPixelGrid(
|
||||
originalNode,
|
||||
originalNode->getConfig()->pointScaleFactor,
|
||||
0.0f,
|
||||
0.0f);
|
||||
|
||||
// Set whether the two layouts are different or not.
|
||||
node->setLayoutDoesLegacyFlagAffectsLayout(
|
||||
!originalNode->isLayoutTreeEqualToNode(*node));
|
||||
|
||||
if (gPrintTree) {
|
||||
YGNodePrint(
|
||||
originalNode,
|
||||
(YGPrintOptions)(
|
||||
YGPrintOptionsLayout | YGPrintOptionsChildren |
|
||||
YGPrintOptionsStyle));
|
||||
}
|
||||
}
|
||||
YGNodeFreeRecursive(originalNode);
|
||||
}
|
||||
}
|
||||
|
||||
void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) {
|
||||
|
Reference in New Issue
Block a user