Skip to content

Commit e567502

Browse files
woehrl01facebook-github-bot
authored andcommitted
Added property display: flex and none
Summary: Fix #241 and successor for #302 Added new property ```display``` with ```YGDisplayFlex``` and ```YGDisplayNone```. Allows to hide nodes from the layout without the need to remove it from the DOM. Closes #369 Reviewed By: astreet Differential Revision: D4501141 Pulled By: emilsjolander fbshipit-source-id: 0dfeee381f6d1e4bbba81926126b83dd7abab9d6
1 parent c1cdc1d commit e567502

File tree

27 files changed

+1529
-6
lines changed

27 files changed

+1529
-6
lines changed

YogaKit/Source/YGLayout.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
@property (nonatomic, readwrite, assign) YGPositionType position;
3333
@property (nonatomic, readwrite, assign) YGWrap flexWrap;
3434
@property (nonatomic, readwrite, assign) YGOverflow overflow;
35+
@property (nonatomic, readwrite, assign) YGDisplay display;
3536

3637
@property (nonatomic, readwrite, assign) CGFloat flexGrow;
3738
@property (nonatomic, readwrite, assign) CGFloat flexShrink;

YogaKit/Source/YGLayout.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ - (void)setPosition:(YGPositionType)position
181181
YG_PROPERTY(YGAlign, alignSelf, AlignSelf)
182182
YG_PROPERTY(YGWrap, flexWrap, FlexWrap)
183183
YG_PROPERTY(YGOverflow, overflow, Overflow)
184+
YG_PROPERTY(YGDisplay, display, Display)
184185

185186
YG_PROPERTY(CGFloat, flexGrow, FlexGrow)
186187
YG_PROPERTY(CGFloat, flexShrink, FlexShrink)

csharp/Facebook.Yoga/Native.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ public static extern void YGNodeSetBaselineFunc(
169169
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
170170
public static extern YogaOverflow YGNodeStyleGetOverflow(YGNodeHandle node);
171171

172+
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
173+
public static extern void YGNodeStyleSetDisplay(YGNodeHandle node, YogaDisplay display);
174+
175+
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
176+
public static extern YogaDisplay YGNodeStyleGetDisplay(YGNodeHandle node);
177+
172178
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
173179
public static extern void YGNodeStyleSetFlex(YGNodeHandle node, float flex);
174180

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
namespace Facebook.Yoga
11+
{
12+
public enum YogaDisplay
13+
{
14+
Flex,
15+
None,
16+
}
17+
}

csharp/Facebook.Yoga/YogaNode.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@ public YogaJustify JustifyContent
145145
}
146146
}
147147

148+
public YogaDisplay Display
149+
{
150+
get
151+
{
152+
return Native.YGNodeStyleGetDisplay(_ygNode);
153+
}
154+
155+
set
156+
{
157+
Native.YGNodeStyleSetDisplay(_ygNode, value);
158+
}
159+
}
160+
148161
public YogaAlign AlignItems
149162
{
150163
get
Lines changed: 332 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,332 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
// @Generated by gentest/gentest.rb from gentest/fixtures/YGDisplayTest.html
11+
12+
using System;
13+
using NUnit.Framework;
14+
15+
namespace Facebook.Yoga
16+
{
17+
[TestFixture]
18+
public class YGDisplayTest
19+
{
20+
[Test]
21+
public void Test_display_none()
22+
{
23+
YogaNode root = new YogaNode();
24+
root.FlexDirection = YogaFlexDirection.Row;
25+
root.Width = 100;
26+
root.Height = 100;
27+
28+
YogaNode root_child0 = new YogaNode();
29+
root_child0.FlexGrow = 1;
30+
root.Insert(0, root_child0);
31+
32+
YogaNode root_child1 = new YogaNode();
33+
root_child1.FlexGrow = 1;
34+
root_child1.Display = YogaDisplay.None;
35+
root.Insert(1, root_child1);
36+
root.StyleDirection = YogaDirection.LTR;
37+
root.CalculateLayout();
38+
39+
Assert.AreEqual(0f, root.LayoutX);
40+
Assert.AreEqual(0f, root.LayoutY);
41+
Assert.AreEqual(100f, root.LayoutWidth);
42+
Assert.AreEqual(100f, root.LayoutHeight);
43+
44+
Assert.AreEqual(0f, root_child0.LayoutX);
45+
Assert.AreEqual(0f, root_child0.LayoutY);
46+
Assert.AreEqual(100f, root_child0.LayoutWidth);
47+
Assert.AreEqual(100f, root_child0.LayoutHeight);
48+
49+
Assert.AreEqual(0f, root_child1.LayoutX);
50+
Assert.AreEqual(0f, root_child1.LayoutY);
51+
Assert.AreEqual(0f, root_child1.LayoutWidth);
52+
Assert.AreEqual(0f, root_child1.LayoutHeight);
53+
54+
root.StyleDirection = YogaDirection.RTL;
55+
root.CalculateLayout();
56+
57+
Assert.AreEqual(0f, root.LayoutX);
58+
Assert.AreEqual(0f, root.LayoutY);
59+
Assert.AreEqual(100f, root.LayoutWidth);
60+
Assert.AreEqual(100f, root.LayoutHeight);
61+
62+
Assert.AreEqual(0f, root_child0.LayoutX);
63+
Assert.AreEqual(0f, root_child0.LayoutY);
64+
Assert.AreEqual(100f, root_child0.LayoutWidth);
65+
Assert.AreEqual(100f, root_child0.LayoutHeight);
66+
67+
Assert.AreEqual(0f, root_child1.LayoutX);
68+
Assert.AreEqual(0f, root_child1.LayoutY);
69+
Assert.AreEqual(0f, root_child1.LayoutWidth);
70+
Assert.AreEqual(0f, root_child1.LayoutHeight);
71+
}
72+
73+
[Test]
74+
public void Test_display_none_fixed_size()
75+
{
76+
YogaNode root = new YogaNode();
77+
root.FlexDirection = YogaFlexDirection.Row;
78+
root.Width = 100;
79+
root.Height = 100;
80+
81+
YogaNode root_child0 = new YogaNode();
82+
root_child0.FlexGrow = 1;
83+
root.Insert(0, root_child0);
84+
85+
YogaNode root_child1 = new YogaNode();
86+
root_child1.Width = 20;
87+
root_child1.Height = 20;
88+
root_child1.Display = YogaDisplay.None;
89+
root.Insert(1, root_child1);
90+
root.StyleDirection = YogaDirection.LTR;
91+
root.CalculateLayout();
92+
93+
Assert.AreEqual(0f, root.LayoutX);
94+
Assert.AreEqual(0f, root.LayoutY);
95+
Assert.AreEqual(100f, root.LayoutWidth);
96+
Assert.AreEqual(100f, root.LayoutHeight);
97+
98+
Assert.AreEqual(0f, root_child0.LayoutX);
99+
Assert.AreEqual(0f, root_child0.LayoutY);
100+
Assert.AreEqual(100f, root_child0.LayoutWidth);
101+
Assert.AreEqual(100f, root_child0.LayoutHeight);
102+
103+
Assert.AreEqual(0f, root_child1.LayoutX);
104+
Assert.AreEqual(0f, root_child1.LayoutY);
105+
Assert.AreEqual(0f, root_child1.LayoutWidth);
106+
Assert.AreEqual(0f, root_child1.LayoutHeight);
107+
108+
root.StyleDirection = YogaDirection.RTL;
109+
root.CalculateLayout();
110+
111+
Assert.AreEqual(0f, root.LayoutX);
112+
Assert.AreEqual(0f, root.LayoutY);
113+
Assert.AreEqual(100f, root.LayoutWidth);
114+
Assert.AreEqual(100f, root.LayoutHeight);
115+
116+
Assert.AreEqual(0f, root_child0.LayoutX);
117+
Assert.AreEqual(0f, root_child0.LayoutY);
118+
Assert.AreEqual(100f, root_child0.LayoutWidth);
119+
Assert.AreEqual(100f, root_child0.LayoutHeight);
120+
121+
Assert.AreEqual(0f, root_child1.LayoutX);
122+
Assert.AreEqual(0f, root_child1.LayoutY);
123+
Assert.AreEqual(0f, root_child1.LayoutWidth);
124+
Assert.AreEqual(0f, root_child1.LayoutHeight);
125+
}
126+
127+
[Test]
128+
public void Test_display_none_with_margin()
129+
{
130+
YogaNode root = new YogaNode();
131+
root.FlexDirection = YogaFlexDirection.Row;
132+
root.Width = 100;
133+
root.Height = 100;
134+
135+
YogaNode root_child0 = new YogaNode();
136+
root_child0.MarginLeft = 10;
137+
root_child0.MarginTop = 10;
138+
root_child0.MarginRight = 10;
139+
root_child0.MarginBottom = 10;
140+
root_child0.Width = 20;
141+
root_child0.Height = 20;
142+
root_child0.Display = YogaDisplay.None;
143+
root.Insert(0, root_child0);
144+
145+
YogaNode root_child1 = new YogaNode();
146+
root_child1.FlexGrow = 1;
147+
root.Insert(1, root_child1);
148+
root.StyleDirection = YogaDirection.LTR;
149+
root.CalculateLayout();
150+
151+
Assert.AreEqual(0f, root.LayoutX);
152+
Assert.AreEqual(0f, root.LayoutY);
153+
Assert.AreEqual(100f, root.LayoutWidth);
154+
Assert.AreEqual(100f, root.LayoutHeight);
155+
156+
Assert.AreEqual(0f, root_child0.LayoutX);
157+
Assert.AreEqual(0f, root_child0.LayoutY);
158+
Assert.AreEqual(0f, root_child0.LayoutWidth);
159+
Assert.AreEqual(0f, root_child0.LayoutHeight);
160+
161+
Assert.AreEqual(0f, root_child1.LayoutX);
162+
Assert.AreEqual(0f, root_child1.LayoutY);
163+
Assert.AreEqual(100f, root_child1.LayoutWidth);
164+
Assert.AreEqual(100f, root_child1.LayoutHeight);
165+
166+
root.StyleDirection = YogaDirection.RTL;
167+
root.CalculateLayout();
168+
169+
Assert.AreEqual(0f, root.LayoutX);
170+
Assert.AreEqual(0f, root.LayoutY);
171+
Assert.AreEqual(100f, root.LayoutWidth);
172+
Assert.AreEqual(100f, root.LayoutHeight);
173+
174+
Assert.AreEqual(0f, root_child0.LayoutX);
175+
Assert.AreEqual(0f, root_child0.LayoutY);
176+
Assert.AreEqual(0f, root_child0.LayoutWidth);
177+
Assert.AreEqual(0f, root_child0.LayoutHeight);
178+
179+
Assert.AreEqual(0f, root_child1.LayoutX);
180+
Assert.AreEqual(0f, root_child1.LayoutY);
181+
Assert.AreEqual(100f, root_child1.LayoutWidth);
182+
Assert.AreEqual(100f, root_child1.LayoutHeight);
183+
}
184+
185+
[Test]
186+
public void Test_display_none_with_child()
187+
{
188+
YogaNode root = new YogaNode();
189+
root.FlexDirection = YogaFlexDirection.Row;
190+
root.Width = 100;
191+
root.Height = 100;
192+
193+
YogaNode root_child0 = new YogaNode();
194+
root_child0.FlexGrow = 1;
195+
root_child0.FlexShrink = 1;
196+
root_child0.FlexBasis = 0.Percent();
197+
root.Insert(0, root_child0);
198+
199+
YogaNode root_child1 = new YogaNode();
200+
root_child1.FlexGrow = 1;
201+
root_child1.FlexShrink = 1;
202+
root_child1.FlexBasis = 0.Percent();
203+
root_child1.Display = YogaDisplay.None;
204+
root.Insert(1, root_child1);
205+
206+
YogaNode root_child1_child0 = new YogaNode();
207+
root_child1_child0.FlexGrow = 1;
208+
root_child1_child0.FlexShrink = 1;
209+
root_child1_child0.FlexBasis = 0.Percent();
210+
root_child1_child0.Width = 20;
211+
root_child1_child0.MinWidth = 0;
212+
root_child1_child0.MinHeight = 0;
213+
root_child1.Insert(0, root_child1_child0);
214+
215+
YogaNode root_child2 = new YogaNode();
216+
root_child2.FlexGrow = 1;
217+
root_child2.FlexShrink = 1;
218+
root_child2.FlexBasis = 0.Percent();
219+
root.Insert(2, root_child2);
220+
root.StyleDirection = YogaDirection.LTR;
221+
root.CalculateLayout();
222+
223+
Assert.AreEqual(0f, root.LayoutX);
224+
Assert.AreEqual(0f, root.LayoutY);
225+
Assert.AreEqual(100f, root.LayoutWidth);
226+
Assert.AreEqual(100f, root.LayoutHeight);
227+
228+
Assert.AreEqual(0f, root_child0.LayoutX);
229+
Assert.AreEqual(0f, root_child0.LayoutY);
230+
Assert.AreEqual(50f, root_child0.LayoutWidth);
231+
Assert.AreEqual(100f, root_child0.LayoutHeight);
232+
233+
Assert.AreEqual(0f, root_child1.LayoutX);
234+
Assert.AreEqual(0f, root_child1.LayoutY);
235+
Assert.AreEqual(0f, root_child1.LayoutWidth);
236+
Assert.AreEqual(0f, root_child1.LayoutHeight);
237+
238+
Assert.AreEqual(0f, root_child1_child0.LayoutX);
239+
Assert.AreEqual(0f, root_child1_child0.LayoutY);
240+
Assert.AreEqual(0f, root_child1_child0.LayoutWidth);
241+
Assert.AreEqual(0f, root_child1_child0.LayoutHeight);
242+
243+
Assert.AreEqual(50f, root_child2.LayoutX);
244+
Assert.AreEqual(0f, root_child2.LayoutY);
245+
Assert.AreEqual(50f, root_child2.LayoutWidth);
246+
Assert.AreEqual(100f, root_child2.LayoutHeight);
247+
248+
root.StyleDirection = YogaDirection.RTL;
249+
root.CalculateLayout();
250+
251+
Assert.AreEqual(0f, root.LayoutX);
252+
Assert.AreEqual(0f, root.LayoutY);
253+
Assert.AreEqual(100f, root.LayoutWidth);
254+
Assert.AreEqual(100f, root.LayoutHeight);
255+
256+
Assert.AreEqual(50f, root_child0.LayoutX);
257+
Assert.AreEqual(0f, root_child0.LayoutY);
258+
Assert.AreEqual(50f, root_child0.LayoutWidth);
259+
Assert.AreEqual(100f, root_child0.LayoutHeight);
260+
261+
Assert.AreEqual(0f, root_child1.LayoutX);
262+
Assert.AreEqual(0f, root_child1.LayoutY);
263+
Assert.AreEqual(0f, root_child1.LayoutWidth);
264+
Assert.AreEqual(0f, root_child1.LayoutHeight);
265+
266+
Assert.AreEqual(0f, root_child1_child0.LayoutX);
267+
Assert.AreEqual(0f, root_child1_child0.LayoutY);
268+
Assert.AreEqual(0f, root_child1_child0.LayoutWidth);
269+
Assert.AreEqual(0f, root_child1_child0.LayoutHeight);
270+
271+
Assert.AreEqual(0f, root_child2.LayoutX);
272+
Assert.AreEqual(0f, root_child2.LayoutY);
273+
Assert.AreEqual(50f, root_child2.LayoutWidth);
274+
Assert.AreEqual(100f, root_child2.LayoutHeight);
275+
}
276+
277+
[Test]
278+
public void Test_display_none_with_position()
279+
{
280+
YogaNode root = new YogaNode();
281+
root.FlexDirection = YogaFlexDirection.Row;
282+
root.Width = 100;
283+
root.Height = 100;
284+
285+
YogaNode root_child0 = new YogaNode();
286+
root_child0.FlexGrow = 1;
287+
root.Insert(0, root_child0);
288+
289+
YogaNode root_child1 = new YogaNode();
290+
root_child1.FlexGrow = 1;
291+
root_child1.Top = 10;
292+
root_child1.Display = YogaDisplay.None;
293+
root.Insert(1, root_child1);
294+
root.StyleDirection = YogaDirection.LTR;
295+
root.CalculateLayout();
296+
297+
Assert.AreEqual(0f, root.LayoutX);
298+
Assert.AreEqual(0f, root.LayoutY);
299+
Assert.AreEqual(100f, root.LayoutWidth);
300+
Assert.AreEqual(100f, root.LayoutHeight);
301+
302+
Assert.AreEqual(0f, root_child0.LayoutX);
303+
Assert.AreEqual(0f, root_child0.LayoutY);
304+
Assert.AreEqual(100f, root_child0.LayoutWidth);
305+
Assert.AreEqual(100f, root_child0.LayoutHeight);
306+
307+
Assert.AreEqual(0f, root_child1.LayoutX);
308+
Assert.AreEqual(0f, root_child1.LayoutY);
309+
Assert.AreEqual(0f, root_child1.LayoutWidth);
310+
Assert.AreEqual(0f, root_child1.LayoutHeight);
311+
312+
root.StyleDirection = YogaDirection.RTL;
313+
root.CalculateLayout();
314+
315+
Assert.AreEqual(0f, root.LayoutX);
316+
Assert.AreEqual(0f, root.LayoutY);
317+
Assert.AreEqual(100f, root.LayoutWidth);
318+
Assert.AreEqual(100f, root.LayoutHeight);
319+
320+
Assert.AreEqual(0f, root_child0.LayoutX);
321+
Assert.AreEqual(0f, root_child0.LayoutY);
322+
Assert.AreEqual(100f, root_child0.LayoutWidth);
323+
Assert.AreEqual(100f, root_child0.LayoutHeight);
324+
325+
Assert.AreEqual(0f, root_child1.LayoutX);
326+
Assert.AreEqual(0f, root_child1.LayoutY);
327+
Assert.AreEqual(0f, root_child1.LayoutWidth);
328+
Assert.AreEqual(0f, root_child1.LayoutHeight);
329+
}
330+
331+
}
332+
}

0 commit comments

Comments
 (0)