Fix handling 'auto' checks in absolute layout (#1689)
Summary: X-link: https://github.com/facebook/react-native/pull/46216 Regarding [issue](https://github.com/facebook/react-native/issues/45817) with incorrect layout when `left` is set to `auto`. This PR introduces handling `auto` whenever inline or flex position is checked to be defined and it fixes above issue. Changelog: [General][Fixed] - Fix handling 'auto' checks in absolute layout ## Tests: I have run the provided unit tests and everything passes. Pull Request resolved: https://github.com/facebook/yoga/pull/1689 Reviewed By: cipolleschi Differential Revision: D61737876 Pulled By: NickGerleman fbshipit-source-id: 531199a91c5e122b930b49725ea567cbb1d592ce
This commit is contained in:
committed by
Facebook GitHub Bot
parent
596f8dff3c
commit
6d6f69bee7
@@ -5,7 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* clang-format off
|
||||
* @generated SignedSource<<425ef3591b2f5cf0bc6d9daa9c5db96c>>
|
||||
* @generated SignedSource<<499316b3f7b7ec5c406abf5ac77837f1>>
|
||||
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAbsolutePositionTest.html
|
||||
*/
|
||||
|
||||
@@ -57,6 +57,138 @@ TEST(YogaTest, absolute_layout_width_height_start_top) {
|
||||
YGConfigFree(config);
|
||||
}
|
||||
|
||||
TEST(YogaTest, absolute_layout_width_height_left_auto_right) {
|
||||
YGConfigRef config = YGConfigNew();
|
||||
|
||||
YGNodeRef root = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
||||
YGNodeStyleSetWidth(root, 100);
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute);
|
||||
YGNodeStyleSetPositionAuto(root_child0, YGEdgeLeft);
|
||||
YGNodeStyleSetPosition(root_child0, YGEdgeRight, 10);
|
||||
YGNodeStyleSetWidth(root_child0, 10);
|
||||
YGNodeStyleSetHeight(root_child0, 10);
|
||||
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(100, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
|
||||
YGConfigFree(config);
|
||||
}
|
||||
|
||||
TEST(YogaTest, absolute_layout_width_height_left_right_auto) {
|
||||
YGConfigRef config = YGConfigNew();
|
||||
|
||||
YGNodeRef root = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
||||
YGNodeStyleSetWidth(root, 100);
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute);
|
||||
YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 10);
|
||||
YGNodeStyleSetPositionAuto(root_child0, YGEdgeRight);
|
||||
YGNodeStyleSetWidth(root_child0, 10);
|
||||
YGNodeStyleSetHeight(root_child0, 10);
|
||||
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(100, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
|
||||
YGConfigFree(config);
|
||||
}
|
||||
|
||||
TEST(YogaTest, absolute_layout_width_height_left_auto_right_auto) {
|
||||
YGConfigRef config = YGConfigNew();
|
||||
|
||||
YGNodeRef root = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
||||
YGNodeStyleSetWidth(root, 100);
|
||||
YGNodeStyleSetHeight(root, 100);
|
||||
|
||||
YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||
YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute);
|
||||
YGNodeStyleSetPositionAuto(root_child0, YGEdgeLeft);
|
||||
YGNodeStyleSetPositionAuto(root_child0, YGEdgeRight);
|
||||
YGNodeStyleSetWidth(root_child0, 10);
|
||||
YGNodeStyleSetHeight(root_child0, 10);
|
||||
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(100, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
|
||||
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
||||
|
||||
ASSERT_FLOAT_EQ(90, YGNodeLayoutGetLeft(root_child0));
|
||||
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
||||
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
|
||||
|
||||
YGNodeFreeRecursive(root);
|
||||
|
||||
YGConfigFree(config);
|
||||
}
|
||||
|
||||
TEST(YogaTest, absolute_layout_width_height_end_bottom) {
|
||||
YGConfigRef config = YGConfigNew();
|
||||
|
||||
|
Reference in New Issue
Block a user