Skip to content

Commit

Permalink
Add justify-content: space-evenly
Browse files Browse the repository at this point in the history
Summary:
Adds new ```space-evenly``` for ```justify-content```.

Also adds a typofix in one of the other justify-content tests.

Fixes facebook#657
Closes facebook#658

Differential Revision: D6407996

Pulled By: emilsjolander

fbshipit-source-id: cc837409e1345624b4bd72c31e25fe68dcb0f6a3
  • Loading branch information
woehrl01 authored and facebook-github-bot committed Nov 27, 2017
1 parent 5e39f1a commit 7e3be21
Show file tree
Hide file tree
Showing 17 changed files with 614 additions and 26 deletions.
1 change: 1 addition & 0 deletions csharp/Facebook.Yoga/YogaJustify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public enum YogaJustify
FlexEnd,
SpaceBetween,
SpaceAround,
SpaceEvenly,
}
}
146 changes: 142 additions & 4 deletions csharp/tests/Facebook.Yoga/YGJustifyContentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ public void Test_justify_content_column_flex_start()
root.Insert(0, root_child0);

YogaNode root_child1 = new YogaNode(config);
root_child1.Height = 10;
root.Insert(1, root_child1);

YogaNode root_child2 = new YogaNode(config);
Expand All @@ -396,10 +397,10 @@ public void Test_justify_content_column_flex_start()
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(10f, root_child1.LayoutY);
Assert.AreEqual(102f, root_child1.LayoutWidth);
Assert.AreEqual(0f, root_child1.LayoutHeight);
Assert.AreEqual(10f, root_child1.LayoutHeight);

Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(10f, root_child2.LayoutY);
Assert.AreEqual(20f, root_child2.LayoutY);
Assert.AreEqual(102f, root_child2.LayoutWidth);
Assert.AreEqual(10f, root_child2.LayoutHeight);

Expand All @@ -419,10 +420,10 @@ public void Test_justify_content_column_flex_start()
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(10f, root_child1.LayoutY);
Assert.AreEqual(102f, root_child1.LayoutWidth);
Assert.AreEqual(0f, root_child1.LayoutHeight);
Assert.AreEqual(10f, root_child1.LayoutHeight);

Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(10f, root_child2.LayoutY);
Assert.AreEqual(20f, root_child2.LayoutY);
Assert.AreEqual(102f, root_child2.LayoutWidth);
Assert.AreEqual(10f, root_child2.LayoutHeight);
}
Expand Down Expand Up @@ -867,5 +868,142 @@ public void Test_justify_content_colunn_max_height_and_margin()
Assert.AreEqual(20f, root_child0.LayoutHeight);
}

[Test]
public void Test_justify_content_column_space_evenly()
{
YogaConfig config = new YogaConfig();

YogaNode root = new YogaNode(config);
root.JustifyContent = YogaJustify.SpaceEvenly;
root.Width = 102;
root.Height = 102;

YogaNode root_child0 = new YogaNode(config);
root_child0.Height = 10;
root.Insert(0, root_child0);

YogaNode root_child1 = new YogaNode(config);
root_child1.Height = 10;
root.Insert(1, root_child1);

YogaNode root_child2 = new YogaNode(config);
root_child2.Height = 10;
root.Insert(2, root_child2);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();

Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(102f, root.LayoutWidth);
Assert.AreEqual(102f, root.LayoutHeight);

Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(18f, root_child0.LayoutY);
Assert.AreEqual(102f, root_child0.LayoutWidth);
Assert.AreEqual(10f, root_child0.LayoutHeight);

Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(46f, root_child1.LayoutY);
Assert.AreEqual(102f, root_child1.LayoutWidth);
Assert.AreEqual(10f, root_child1.LayoutHeight);

Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(74f, root_child2.LayoutY);
Assert.AreEqual(102f, root_child2.LayoutWidth);
Assert.AreEqual(10f, root_child2.LayoutHeight);

root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();

Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(102f, root.LayoutWidth);
Assert.AreEqual(102f, root.LayoutHeight);

Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(18f, root_child0.LayoutY);
Assert.AreEqual(102f, root_child0.LayoutWidth);
Assert.AreEqual(10f, root_child0.LayoutHeight);

Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(46f, root_child1.LayoutY);
Assert.AreEqual(102f, root_child1.LayoutWidth);
Assert.AreEqual(10f, root_child1.LayoutHeight);

Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(74f, root_child2.LayoutY);
Assert.AreEqual(102f, root_child2.LayoutWidth);
Assert.AreEqual(10f, root_child2.LayoutHeight);
}

[Test]
public void Test_justify_content_row_space_evenly()
{
YogaConfig config = new YogaConfig();

YogaNode root = new YogaNode(config);
root.FlexDirection = YogaFlexDirection.Row;
root.JustifyContent = YogaJustify.SpaceEvenly;
root.Width = 102;
root.Height = 102;

YogaNode root_child0 = new YogaNode(config);
root_child0.Height = 10;
root.Insert(0, root_child0);

YogaNode root_child1 = new YogaNode(config);
root_child1.Height = 10;
root.Insert(1, root_child1);

YogaNode root_child2 = new YogaNode(config);
root_child2.Height = 10;
root.Insert(2, root_child2);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();

Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(102f, root.LayoutWidth);
Assert.AreEqual(102f, root.LayoutHeight);

Assert.AreEqual(26f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(0f, root_child0.LayoutWidth);
Assert.AreEqual(10f, root_child0.LayoutHeight);

Assert.AreEqual(51f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(0f, root_child1.LayoutWidth);
Assert.AreEqual(10f, root_child1.LayoutHeight);

Assert.AreEqual(77f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(0f, root_child2.LayoutWidth);
Assert.AreEqual(10f, root_child2.LayoutHeight);

root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();

Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(102f, root.LayoutWidth);
Assert.AreEqual(102f, root.LayoutHeight);

Assert.AreEqual(77f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(0f, root_child0.LayoutWidth);
Assert.AreEqual(10f, root_child0.LayoutHeight);

Assert.AreEqual(51f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(0f, root_child1.LayoutWidth);
Assert.AreEqual(10f, root_child1.LayoutHeight);

Assert.AreEqual(26f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(0f, root_child2.LayoutWidth);
Assert.AreEqual(10f, root_child2.LayoutHeight);
}

}
}
1 change: 1 addition & 0 deletions enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
'FlexEnd',
'SpaceBetween',
'SpaceAround',
'SpaceEvenly',
],
'Overflow': [
'Visible',
Expand Down
15 changes: 14 additions & 1 deletion gentest/fixtures/YGJustifyContentTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<div id="justify_content_column_flex_start" style="width: 102px; height: 102px; justify-content: flex-start;">
<div style="height: 10px;"></div>
<div style="heigth: 10px;"></div>
<div style="height: 10px;"></div>
<div style="height: 10px;"></div>
</div>

Expand Down Expand Up @@ -73,3 +73,16 @@
<div id="justify_content_colunn_max_height_and_margin" style="height: 100px; max-height: 80px; margin-top: 100px; justify-content: center; flex-direction: column;">
<div style="height: 20px; width: 20px;"></div>
</div>

<div id="justify_content_column_space_evenly" style="width: 102px; height: 102px; justify-content: space-evenly;">
<div style="height: 10px;"></div>
<div style="height: 10px;"></div>
<div style="height: 10px;"></div>
</div>

<div id="justify_content_row_space_evenly" style="width: 102px; height: 102px; justify-content: space-evenly; flex-direction: row; ">
<div style="height: 10px;"></div>
<div style="height: 10px;"></div>
<div style="height: 10px;"></div>
</div>

1 change: 1 addition & 0 deletions gentest/gentest-cpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
YGJustifyFlexStart:{value:'YGJustifyFlexStart'},
YGJustifySpaceAround:{value:'YGJustifySpaceAround'},
YGJustifySpaceBetween:{value:'YGJustifySpaceBetween'},
YGJustifySpaceEvenly:{value:'YGJustifySpaceEvenly'},

YGOverflowHidden:{value:'YGOverflowHidden'},
YGOverflowVisible:{value:'YGOverflowVisible'},
Expand Down
1 change: 1 addition & 0 deletions gentest/gentest-cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ CSEmitter.prototype = Object.create(Emitter.prototype, {
YGJustifyFlexStart:{value:'YogaJustify.FlexStart'},
YGJustifySpaceAround:{value:'YogaJustify.SpaceAround'},
YGJustifySpaceBetween:{value:'YogaJustify.SpaceBetween'},
YGJustifySpaceEvenly:{value:'YogaJustify.SpaceEvenly'},

YGOverflowHidden:{value:'YogaOverflow.Hidden'},
YGOverflowVisible:{value:'YogaOverflow.Visible'},
Expand Down
1 change: 1 addition & 0 deletions gentest/gentest-java.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
YGJustifyFlexStart:{value:'YogaJustify.FLEX_START'},
YGJustifySpaceAround:{value:'YogaJustify.SPACE_AROUND'},
YGJustifySpaceBetween:{value:'YogaJustify.SPACE_BETWEEN'},
YGJustifySpaceEvenly:{value:'YogaJustify.SPACE_EVENLY'},

YGOverflowHidden:{value:'YogaOverflow.HIDDEN'},
YGOverflowVisible:{value:'YogaOverflow.VISIBLE'},
Expand Down
1 change: 1 addition & 0 deletions gentest/gentest-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ JavascriptEmitter.prototype = Object.create(Emitter.prototype, {
YGJustifyFlexStart:{value:'Yoga.JUSTIFY_FLEX_START'},
YGJustifySpaceAround:{value:'Yoga.JUSTIFY_SPACE_AROUND'},
YGJustifySpaceBetween:{value:'Yoga.JUSTIFY_SPACE_BETWEEN'},
YGJustifySpaceEvenly:{value:'Yoga.JUSTIFY_SPACE_EVENLY'},

YGOverflowHidden:{value:'Yoga.OVERFLOW_HIDDEN'},
YGOverflowVisible:{value:'Yoga.OVERFLOW_VISIBLE'},
Expand Down
1 change: 1 addition & 0 deletions gentest/gentest.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ function justifyValue(e, value) {
case 'center': return e.YGJustifyCenter;
case 'space-around': return e.YGJustifySpaceAround;
case 'space-between': return e.YGJustifySpaceBetween;
case 'space-evenly': return e.YGJustifySpaceEvenly;
case 'flex-start': return e.YGJustifyFlexStart;
case 'flex-end': return e.YGJustifyFlexEnd;
}
Expand Down
5 changes: 4 additions & 1 deletion java/com/facebook/yoga/YogaJustify.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public enum YogaJustify {
CENTER(1),
FLEX_END(2),
SPACE_BETWEEN(3),
SPACE_AROUND(4);
SPACE_AROUND(4),
SPACE_EVENLY(5);

private int mIntValue;

Expand All @@ -36,6 +37,8 @@ public static YogaJustify fromInt(int value) {
case 2: return FLEX_END;
case 3: return SPACE_BETWEEN;
case 4: return SPACE_AROUND;
case 5:
return SPACE_EVENLY;
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
Expand Down
Loading

0 comments on commit 7e3be21

Please sign in to comment.