flexShrink: children shrink proportionally when container is too small
| 7 | |
| 8 | // flexShrink: children shrink proportionally when container is too small |
| 9 | TEST(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 | |
| 38 | TEST(YogaLayout, flexShrinkZeroPreventsShinking) { |
| 39 | ViewNodeTestsDependencies utils; |
nothing calls this directly
no test coverage detected