Fix issue with alternating flex direction and percent postions (#1663)
Summary: X-link: https://github.com/facebook/react-native/pull/44792 Pull Request resolved: https://github.com/facebook/yoga/pull/1663 Fixing https://github.com/facebook/yoga/issues/1658. We had a problem where if a child had a different flex direction than its parent, and it also set a position as a percent, it would look at the wrong axis to evaluate the percent. What was happening was we were passing in the container's mainAxis size and crossAxis size to use to evaluate the position size if it was a percent. However, we matched these sizes with the main/cross axis of the child - which is wrong if the flex direction is different. I changed it so that the function just takes in ownerWidth and ownerHeight then calls isRow to determine which one to use for the main/cross axis position. This reduces the ambiguity quite a bit imo. Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D58172416 fbshipit-source-id: eafd8069e03493fc56c41a76879d1ad9b7e9236d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
72b7e5b5cf
commit
289b62732b
@@ -5,7 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* clang-format off
|
||||
* @generated SignedSource<<4a6a69c4e9bfda6dc73198791f553e13>>
|
||||
* @generated SignedSource<<552f1533812daf0793244bbc8c465e17>>
|
||||
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGFlexDirectionTest.html
|
||||
*/
|
||||
|
||||
@@ -4283,3 +4283,47 @@ TEST(YogaTest, flex_direction_row_reverse_inner_padding_end) {
|
||||
|
||||
YGConfigFree(config);
|
||||
}
|
||||
|
||||
TEST(YogaTest, flex_direction_alternating_with_percent) {
|
||||
const YGConfigRef config = YGConfigNew();
|
||||
|
||||
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
||||
YGNodeStyleSetWidth(root, 200);
|
||||
YGNodeStyleSetHeight(root, 300);
|
||||
|
||||
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow);
|
||||
YGNodeStyleSetPositionPercent(root_child0, YGEdgeLeft, 10);
|
||||
YGNodeStyleSetPositionPercent(root_child0, YGEdgeTop, 10);
|
||||
YGNodeStyleSetWidthPercent(root_child0, 50);
|
||||
YGNodeStyleSetHeightPercent(root_child0, 50);
|
||||
YGNodeInsertChild(root, root_child0, 0);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(300, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(300, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(120, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(30, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
|
||||
YGConfigFree(config);
|
||||
}
|
||||
|
Reference in New Issue
Block a user