Skip to content
Open
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
44 changes: 28 additions & 16 deletions packages/react-native/ReactCommon/yoga/test/BaselineTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,34 +408,43 @@ TEST(MinContentTest, testOwnPercentageMarginLeavesChildrenShared) {
YGConfigRef config = autoMinSizeConfig();
MeasureCalls calls;
YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetWidth(root, 300);
YGNodeStyleSetHeight(root, 100);
YGNodeRef item = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(item, 50);
YGNodeStyleSetHeight(item, 200);
YGNodeStyleSetFlexBasis(item, 100);
YGNodeStyleSetFlexShrink(item, 1);
YGNodeInsertChild(root, item, 0);
YGNodeRef content = YGNodeNewWithConfig(config);
YGNodeStyleSetMarginPercent(content, YGEdgeLeft, 10);
YGNodeRef leaf = measuredLeaf(config, &calls);
YGNodeInsertChild(content, leaf, 0);
YGNodeInsertChild(item, content, 0);
YGNodeRef staticLeaf = YGNodeNewWithConfig(config);
YGNodeSetMinContentWidth(staticLeaf, 100);
YGNodeInsertChild(item, staticLeaf, 1);
YGNodeRef sibling = YGNodeNewWithConfig(config);
YGNodeStyleSetHeight(sibling, 200);
YGNodeStyleSetFlexBasis(sibling, 300);
YGNodeStyleSetFlexShrink(sibling, 1);
YGNodeInsertChild(root, sibling, 1);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

// The content's own margin keys the item's memo and not the content's, so a
// narrower second tree walks the item again but only reads the content.
// The static leaf keeps the item 100 wide in a narrower second tree, so the
// item's layout comes from cache and only the walk reaches its children.
// The width walk resolves the content's own margin against the root's width,
// which keys the item's memo on that width and not the content's: the walk
// walks the item again but only reads the content.
YGNodeRef rootCopy = YGNodeClone(root);
YGNodeStyleSetWidth(rootCopy, 290);
YGNodeCalculateLayout(rootCopy, YGUndefined, YGUndefined, YGDirectionLTR);

EXPECT_EQ(content, YGNodeGetChild(YGNodeGetChild(rootCopy, 0), 0));
EXPECT_EQ(
leaf, YGNodeGetChild(YGNodeGetChild(YGNodeGetChild(rootCopy, 0), 0), 0));
const YGNodeRef itemCopy = YGNodeGetChild(rootCopy, 0);
ASSERT_FLOAT_EQ(100.0f, YGNodeLayoutGetWidth(itemCopy));
const LayoutResults& itemLayout = resolveRef(itemCopy)->getLayout();
EXPECT_FLOAT_EQ(
290.0f, itemLayout.minContentOwnerWidth[to_underlying(Dimension::Width)]);
EXPECT_EQ(content, YGNodeGetChild(itemCopy, 0));
EXPECT_EQ(leaf, YGNodeGetChild(YGNodeGetChild(itemCopy, 0), 0));

freeTreesSharingNodes({rootCopy, root});
YGConfigFree(config);
Expand All @@ -446,12 +455,11 @@ TEST(MinContentTest, testWalkClonesOnlyTheChildrenItWritesTo) {
MeasureCalls paddedCalls;
MeasureCalls stableCalls;
YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetAlignItems(root, YGAlignFlexStart);
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetWidth(root, 300);
YGNodeStyleSetHeight(root, 100);
YGNodeRef item = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(item, 50);
YGNodeStyleSetHeight(item, 200);
YGNodeStyleSetFlexBasis(item, 100);
YGNodeStyleSetFlexShrink(item, 1);
YGNodeInsertChild(root, item, 0);
YGNodeRef padded = YGNodeNewWithConfig(config);
Expand All @@ -469,24 +477,28 @@ TEST(MinContentTest, testWalkClonesOnlyTheChildrenItWritesTo) {
YGNodeInsertChild(item, absolute, 3);
YGNodeRef staticLeaf = YGNodeNewWithConfig(config);
YGNodeSetMeasureFunc(staticLeaf, measureUncounted);
YGNodeSetMinContentWidth(staticLeaf, 20);
YGNodeSetMinContentWidth(staticLeaf, 100);
YGNodeSetMinContentHeight(staticLeaf, 5);
YGNodeInsertChild(item, staticLeaf, 4);
YGNodeRef empty = YGNodeNewWithConfig(config);
YGNodeInsertChild(item, empty, 5);
YGNodeRef sibling = YGNodeNewWithConfig(config);
YGNodeStyleSetHeight(sibling, 200);
YGNodeStyleSetFlexBasis(sibling, 300);
YGNodeStyleSetFlexShrink(sibling, 1);
YGNodeInsertChild(root, sibling, 1);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);

// Only `padded`'s memo is keyed on the width, so a narrower second tree walks
// it again and only reads the item's other children and `padded`'s leaf.
// The static leaf keeps the item 100 wide in a narrower second tree, so the
// item's layout comes from cache and only the walk reaches its children.
// The width walk resolves `padded`'s percentage against the root's width, so
// only its memo is keyed on that width: the walk walks it again and only
// reads the item's other children and `padded`'s leaf.
YGNodeRef rootCopy = YGNodeClone(root);
YGNodeStyleSetWidth(rootCopy, 290);
YGNodeCalculateLayout(rootCopy, YGUndefined, YGUndefined, YGDirectionLTR);

const YGNodeRef itemCopy = YGNodeGetChild(rootCopy, 0);
ASSERT_FLOAT_EQ(100.0f, YGNodeLayoutGetWidth(itemCopy));
EXPECT_NE(padded, YGNodeGetChild(itemCopy, 0));
EXPECT_EQ(paddedLeaf, YGNodeGetChild(YGNodeGetChild(itemCopy, 0), 0));
EXPECT_EQ(stable, YGNodeGetChild(itemCopy, 1));
Expand Down
Loading