MCPcopy Create free account
hub / github.com/Snapchat/Valdi / TEST

Function TEST

valdi/test/runtime/YogaLayout_tests.cpp:9–36  ·  view source on GitHub ↗

flexShrink: children shrink proportionally when container is too small

Source from the content-addressed store, hash-verified

7
8// flexShrink: children shrink proportionally when container is too small
9TEST(YogaLayout, flexShrinkDistributesSpaceProportionally) {
10 ViewNodeTestsDependencies utils;
11
12 auto root = utils.createLayout();
13 auto child1 = utils.createLayout();
14 auto child2 = utils.createLayout();
15
16 utils.setViewNodeAttribute(root, "flexDirection", Value(STRING_LITERAL("row")));
17 utils.setViewNodeAttribute(root, "width", Value(200.0));
18 utils.setViewNodeAttribute(root, "height", Value(100.0));
19
20 utils.setViewNodeAttribute(child1, "width", Value(200.0));
21 utils.setViewNodeAttribute(child1, "flexShrink", Value(1.0));
22 child1->getAttributesApplier().flush(utils.getViewTransactionScope());
23
24 utils.setViewNodeAttribute(child2, "width", Value(200.0));
25 utils.setViewNodeAttribute(child2, "flexShrink", Value(3.0));
26 child2->getAttributesApplier().flush(utils.getViewTransactionScope());
27
28 root->appendChild(utils.getViewTransactionScope(), child1);
29 root->appendChild(utils.getViewTransactionScope(), child2);
30
31 root->performLayout(utils.getViewTransactionScope(), Size(200, 100), LayoutDirectionLTR);
32
33 // 200px overflow, shrink ratio 1:3 => child1 shrinks 50, child2 shrinks 150
34 ASSERT_EQ(Frame(0, 0, 150, 100), child1->getCalculatedFrame());
35 ASSERT_EQ(Frame(150, 0, 50, 100), child2->getCalculatedFrame());
36}
37
38TEST(YogaLayout, flexShrinkZeroPreventsShinking) {
39 ViewNodeTestsDependencies utils;

Callers

nothing calls this directly

Calls 9

createLayoutMethod · 0.80
setViewNodeAttributeMethod · 0.80
appendChildMethod · 0.80
flushMethod · 0.65
performLayoutMethod · 0.65
ValueInterface · 0.50
SizeInterface · 0.50
FrameInterface · 0.50
getLeftMethod · 0.45

Tested by

no test coverage detected