Breaking: per-node pointScaleFactor (#1379)

Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1379

X-link: https://github.com/facebook/react-native/pull/39403

Right now we have a `pointScaleFactor` per-node, but only ever read the one off the root node. In most cases where config is global, these will be the same, but it is possible for these to differ.

This... doesn't make much sense from an API perspective, and there are edge cases where we may want to allow laying out a subtree with a different DPI then the rest of the tree (though I think there might be other solutions to that).

We should rethink some of what is currently on config being allowed per-node (do we really need each node to be able to have a separate logger?), but this makes the model consistent in the meantime.

This change is breaking to any users relying on setting `pointScaleFactor` on the config of the root node, but not other nodes.

Reviewed By: yungsters

Differential Revision: D49181131

fbshipit-source-id: f1363ca242094f04b995fd50c1e56834d5003425
This commit is contained in:
Nick Gerleman
2023-09-13 14:11:25 -07:00
committed by Facebook GitHub Bot
parent 0a90b16ac6
commit 66cc95f932
4 changed files with 86 additions and 49 deletions

View File

@@ -80,3 +80,45 @@ TEST(YogaTest, consistent_rounding_during_repeated_layouts) {
YGConfigFree(config);
}
TEST(YogaTest, per_node_point_scale_factor) {
const YGConfigRef config1 = YGConfigNew();
YGConfigSetPointScaleFactor(config1, 2);
const YGConfigRef config2 = YGConfigNew();
YGConfigSetPointScaleFactor(config2, 1);
const YGConfigRef config3 = YGConfigNew();
YGConfigSetPointScaleFactor(config3, 0.5f);
const YGNodeRef root = YGNodeNewWithConfig(config1);
YGNodeStyleSetWidth(root, 11.5);
YGNodeStyleSetHeight(root, 11.5);
const YGNodeRef node0 = YGNodeNewWithConfig(config2);
YGNodeStyleSetWidth(node0, 9.5);
YGNodeStyleSetHeight(node0, 9.5);
YGNodeInsertChild(root, node0, 0);
const YGNodeRef node1 = YGNodeNewWithConfig(config3);
YGNodeStyleSetWidth(node1, 7);
YGNodeStyleSetHeight(node1, 7);
YGNodeInsertChild(node0, node1, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(YGNodeLayoutGetWidth(root), 11.5);
ASSERT_EQ(YGNodeLayoutGetHeight(root), 11.5);
ASSERT_EQ(YGNodeLayoutGetWidth(node0), 10);
ASSERT_EQ(YGNodeLayoutGetHeight(node0), 10);
ASSERT_EQ(YGNodeLayoutGetWidth(node1), 8);
ASSERT_EQ(YGNodeLayoutGetHeight(node1), 8);
YGNodeFreeRecursive(root);
YGConfigFree(config1);
YGConfigFree(config2);
YGConfigFree(config3);
}