Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing invalidation if owner has undefined dimensions #1017

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/YGRelayoutTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,33 @@ TEST(YogaTest, recalculate_resolvedDimonsion_onchange) {

YGNodeFreeRecursive(root);
}


YGSize _measureRecalc(YGNodeRef node, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode) {
return YGSize { 0, 0};
}

TEST(YogaTest, recalculate_on_layout_values_change) {
const YGConfigRef config = YGConfigNew();
YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureWebFlexBasis, true);
YGConfigSetPointScaleFactor(config, 3.f);
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
YGNodeStyleSetAlignContent(root, YGAlignFlexStart);
const YGNodeRef child = YGNodeNewWithConfig(config);
YGNodeStyleSetMinHeightPercent(child, 40.f);
YGNodeStyleSetMaxHeightPercent(child, 60.f);
YGNodeStyleSetHeight(child, 10.f);
YGNodeStyleSetWidth(child, 50.0f);
YGNodeSetMeasureFunc(child, _measureRecalc);
YGNodeInsertChild(root, child, 0);

YGNodeCalculateLayout(root, 50.0f, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(child));

YGNodeCalculateLayout(root, 50.0f, 30.0f, YGDirectionLTR);
ASSERT_FLOAT_EQ(12, YGNodeLayoutGetHeight(child));

YGNodeFreeRecursive(root);
}
3 changes: 3 additions & 0 deletions yoga/YGLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ struct YGLayout {
uint32_t generationCount = 0;
YGDirection lastOwnerDirection = YGDirectionInherit;

bool lastOwnerHadUndefinedHeight = false;
bool lastOwnerHadUndefinedWidth = false;

uint32_t nextCachedMeasurementsIndex = 0;
std::array<YGCachedMeasurement, YG_MAX_CACHED_RESULT_COUNT>
cachedMeasurements = {};
Expand Down
9 changes: 8 additions & 1 deletion yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3867,9 +3867,14 @@ bool YGLayoutNodeInternal(

depth++;

bool ownerHasUndefinedHeight = YGFloatIsUndefined(ownerHeight);
bool ownerHasUndefinedWidth = YGFloatIsUndefined(ownerWidth);

const bool needToVisitNode =
(node->isDirty() && layout->generationCount != generationCount) ||
layout->lastOwnerDirection != ownerDirection;
layout->lastOwnerDirection != ownerDirection ||
layout->lastOwnerHadUndefinedHeight != ownerHasUndefinedHeight||
layout->lastOwnerHadUndefinedWidth != ownerHasUndefinedWidth;

if (needToVisitNode) {
// Invalidate the cached results.
Expand Down Expand Up @@ -4051,6 +4056,8 @@ bool YGLayoutNodeInternal(
}

layout->lastOwnerDirection = ownerDirection;
layout->lastOwnerHadUndefinedHeight = ownerHasUndefinedHeight;
layout->lastOwnerHadUndefinedWidth = ownerHasUndefinedWidth;

if (cachedResults == nullptr) {
if (layout->nextCachedMeasurementsIndex + 1 >
Expand Down