Skip to content

Commit

Permalink
Fix bug introduced by D3886866
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Emil Sjolander authored and Facebook Github Bot 6 committed Sep 27, 2016
1 parent 6b16dc4 commit 3b1515f
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CSSLayout/CSSLayout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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]] =
Expand Down
176 changes: 176 additions & 0 deletions tests/CSSLayoutFlexWrapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@
<div style="height: 30px; width: 30px;"></div>
<div style="height: 30px; width: 30px;"></div>
</div>
<div id="wrap_row_align_items_flex_end" style="width: 100px; flex-direction: row; flex-wrap: wrap; align-items: flex-end;">
<div style="height: 10px; width: 30px;"></div>
<div style="height: 20px; width: 30px;"></div>
<div style="height: 30px; width: 30px;"></div>
<div style="height: 30px; width: 30px;"></div>
</div>
<div id="wrap_row_align_items_center" style="width: 100px; flex-direction: row; flex-wrap: wrap; align-items: center;">
<div style="height: 10px; width: 30px;"></div>
<div style="height: 20px; width: 30px;"></div>
<div style="height: 30px; width: 30px;"></div>
<div style="height: 30px; width: 30px;"></div>
</div>
*
*/

Expand Down Expand Up @@ -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));
}

0 comments on commit 3b1515f

Please sign in to comment.