From 3b1515f2b73c874eac3196de62fc9659a6a44005 Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Tue, 27 Sep 2016 10:07:59 -0700 Subject: [PATCH] Fix bug introduced by D3886866 Summary: I accidentally turned the logic around when cleaning up some code. This was subtle and only caught a week later by a RN product engineer. This fixes the bug without reverting the rest of the code cleanup. Reviewed By: lucasr Differential Revision: D3923635 fbshipit-source-id: bfeb175bb40393be63cafb6a995b22701b87ffec --- CSSLayout/CSSLayout.c | 4 +- tests/CSSLayoutFlexWrapTest.cpp | 176 ++++++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+), 2 deletions(-) diff --git a/CSSLayout/CSSLayout.c b/CSSLayout/CSSLayout.c index dd55ed3f..84c51e79 100644 --- a/CSSLayout/CSSLayout.c +++ b/CSSLayout/CSSLayout.c @@ -1705,7 +1705,7 @@ static void layoutNodeImpl(const CSSNodeRef node, for (ii = startIndex; ii < childCount; ii++) { const CSSNodeRef child = CSSNodeListGet(node->children, ii); - if (child->style.positionType == CSSPositionTypeAbsolute) { + if (child->style.positionType == CSSPositionTypeRelative) { if (child->lineIndex != i) { break; } @@ -1724,7 +1724,7 @@ static void layoutNodeImpl(const CSSNodeRef node, for (ii = startIndex; ii < endIndex; ii++) { const CSSNodeRef child = CSSNodeListGet(node->children, ii); - if (child->style.positionType == CSSPositionTypeAbsolute) { + if (child->style.positionType == CSSPositionTypeRelative) { switch (getAlignItem(node, child)) { case CSSAlignFlexStart: child->layout.position[pos[crossAxis]] = diff --git a/tests/CSSLayoutFlexWrapTest.cpp b/tests/CSSLayoutFlexWrapTest.cpp index 5a9c3869..302b137c 100644 --- a/tests/CSSLayoutFlexWrapTest.cpp +++ b/tests/CSSLayoutFlexWrapTest.cpp @@ -23,6 +23,20 @@
+ +
+
+
+
+
+
+ +
+
+
+
+
+
* */ @@ -192,3 +206,165 @@ TEST(CSSLayoutTest, wrap_row) { ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child3)); ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child3)); } + +TEST(CSSLayoutTest, wrap_row_align_items_flex_end) { + const CSSNodeRef root = CSSNodeNew(); + CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); + CSSNodeStyleSetAlignItems(root, CSSAlignFlexEnd); + CSSNodeStyleSetFlexWrap(root, CSSWrapTypeWrap); + CSSNodeStyleSetWidth(root, 100); + + const CSSNodeRef root_child0 = CSSNodeNew(); + CSSNodeStyleSetWidth(root_child0, 30); + CSSNodeStyleSetHeight(root_child0, 10); + CSSNodeInsertChild(root, root_child0, 0); + + const CSSNodeRef root_child1 = CSSNodeNew(); + CSSNodeStyleSetWidth(root_child1, 30); + CSSNodeStyleSetHeight(root_child1, 20); + CSSNodeInsertChild(root, root_child1, 1); + + const CSSNodeRef root_child2 = CSSNodeNew(); + CSSNodeStyleSetWidth(root_child2, 30); + CSSNodeStyleSetHeight(root_child2, 30); + CSSNodeInsertChild(root, root_child2, 2); + + const CSSNodeRef root_child3 = CSSNodeNew(); + CSSNodeStyleSetWidth(root_child3, 30); + CSSNodeStyleSetHeight(root_child3, 30); + CSSNodeInsertChild(root, root_child3, 3); + CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); + + ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); + ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); + ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); + ASSERT_EQ(60, CSSNodeLayoutGetHeight(root)); + + ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child0)); + ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); + + ASSERT_EQ(30, CSSNodeLayoutGetLeft(root_child1)); + ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child1)); + ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child1)); + ASSERT_EQ(20, CSSNodeLayoutGetHeight(root_child1)); + + ASSERT_EQ(60, CSSNodeLayoutGetLeft(root_child2)); + ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); + ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child2)); + ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child2)); + + ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child3)); + ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child3)); + ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child3)); + ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child3)); + + CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); + + ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); + ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); + ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); + ASSERT_EQ(60, CSSNodeLayoutGetHeight(root)); + + ASSERT_EQ(70, CSSNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(20, CSSNodeLayoutGetTop(root_child0)); + ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); + + ASSERT_EQ(40, CSSNodeLayoutGetLeft(root_child1)); + ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child1)); + ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child1)); + ASSERT_EQ(20, CSSNodeLayoutGetHeight(root_child1)); + + ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child2)); + ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); + ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child2)); + ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child2)); + + ASSERT_EQ(70, CSSNodeLayoutGetLeft(root_child3)); + ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child3)); + ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child3)); + ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child3)); +} + +TEST(CSSLayoutTest, wrap_row_align_items_center) { + const CSSNodeRef root = CSSNodeNew(); + CSSNodeStyleSetFlexDirection(root, CSSFlexDirectionRow); + CSSNodeStyleSetAlignItems(root, CSSAlignCenter); + CSSNodeStyleSetFlexWrap(root, CSSWrapTypeWrap); + CSSNodeStyleSetWidth(root, 100); + + const CSSNodeRef root_child0 = CSSNodeNew(); + CSSNodeStyleSetWidth(root_child0, 30); + CSSNodeStyleSetHeight(root_child0, 10); + CSSNodeInsertChild(root, root_child0, 0); + + const CSSNodeRef root_child1 = CSSNodeNew(); + CSSNodeStyleSetWidth(root_child1, 30); + CSSNodeStyleSetHeight(root_child1, 20); + CSSNodeInsertChild(root, root_child1, 1); + + const CSSNodeRef root_child2 = CSSNodeNew(); + CSSNodeStyleSetWidth(root_child2, 30); + CSSNodeStyleSetHeight(root_child2, 30); + CSSNodeInsertChild(root, root_child2, 2); + + const CSSNodeRef root_child3 = CSSNodeNew(); + CSSNodeStyleSetWidth(root_child3, 30); + CSSNodeStyleSetHeight(root_child3, 30); + CSSNodeInsertChild(root, root_child3, 3); + CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR); + + ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); + ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); + ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); + ASSERT_EQ(60, CSSNodeLayoutGetHeight(root)); + + ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); + ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); + + ASSERT_EQ(30, CSSNodeLayoutGetLeft(root_child1)); + ASSERT_EQ(5, CSSNodeLayoutGetTop(root_child1)); + ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child1)); + ASSERT_EQ(20, CSSNodeLayoutGetHeight(root_child1)); + + ASSERT_EQ(60, CSSNodeLayoutGetLeft(root_child2)); + ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); + ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child2)); + ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child2)); + + ASSERT_EQ(0, CSSNodeLayoutGetLeft(root_child3)); + ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child3)); + ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child3)); + ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child3)); + + CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL); + + ASSERT_EQ(0, CSSNodeLayoutGetLeft(root)); + ASSERT_EQ(0, CSSNodeLayoutGetTop(root)); + ASSERT_EQ(100, CSSNodeLayoutGetWidth(root)); + ASSERT_EQ(60, CSSNodeLayoutGetHeight(root)); + + ASSERT_EQ(70, CSSNodeLayoutGetLeft(root_child0)); + ASSERT_EQ(10, CSSNodeLayoutGetTop(root_child0)); + ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child0)); + ASSERT_EQ(10, CSSNodeLayoutGetHeight(root_child0)); + + ASSERT_EQ(40, CSSNodeLayoutGetLeft(root_child1)); + ASSERT_EQ(5, CSSNodeLayoutGetTop(root_child1)); + ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child1)); + ASSERT_EQ(20, CSSNodeLayoutGetHeight(root_child1)); + + ASSERT_EQ(10, CSSNodeLayoutGetLeft(root_child2)); + ASSERT_EQ(0, CSSNodeLayoutGetTop(root_child2)); + ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child2)); + ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child2)); + + ASSERT_EQ(70, CSSNodeLayoutGetLeft(root_child3)); + ASSERT_EQ(30, CSSNodeLayoutGetTop(root_child3)); + ASSERT_EQ(30, CSSNodeLayoutGetWidth(root_child3)); + ASSERT_EQ(30, CSSNodeLayoutGetHeight(root_child3)); +}