File tree Expand file tree Collapse file tree 7 files changed +142
-0
lines changed
Core/tests/UnitTests/Layouts Expand file tree Collapse file tree 7 files changed +142
-0
lines changed Original file line number Diff line number Diff line change @@ -7,5 +7,17 @@ namespace Microsoft.Maui.Controls
7
7
public class HorizontalStackLayout : StackBase
8
8
{
9
9
protected override ILayoutManager CreateLayoutManager ( ) => new HorizontalStackLayoutManager ( this ) ;
10
+
11
+ internal override void ComputeConstraintForView ( View view )
12
+ {
13
+ if ( ( Constraint & LayoutConstraint . VerticallyFixed ) != 0 && view . VerticalOptions . Alignment == LayoutAlignment . Fill )
14
+ {
15
+ view . ComputedConstraint = LayoutConstraint . VerticallyFixed ;
16
+ }
17
+ else
18
+ {
19
+ view . ComputedConstraint = LayoutConstraint . None ;
20
+ }
21
+ }
10
22
}
11
23
}
Original file line number Diff line number Diff line change @@ -36,5 +36,31 @@ protected override ILayoutManager CreateLayoutManager()
36
36
{
37
37
return new StackLayoutManager ( this ) ;
38
38
}
39
+
40
+ internal override void ComputeConstraintForView ( View view )
41
+ {
42
+ if ( Orientation == StackOrientation . Horizontal )
43
+ {
44
+ if ( ( Constraint & LayoutConstraint . VerticallyFixed ) != 0 && view . VerticalOptions . Alignment == LayoutAlignment . Fill )
45
+ {
46
+ view . ComputedConstraint = LayoutConstraint . VerticallyFixed ;
47
+ }
48
+ else
49
+ {
50
+ view . ComputedConstraint = LayoutConstraint . None ;
51
+ }
52
+ }
53
+ else
54
+ {
55
+ if ( ( Constraint & LayoutConstraint . HorizontallyFixed ) != 0 && view . HorizontalOptions . Alignment == LayoutAlignment . Fill )
56
+ {
57
+ view . ComputedConstraint = LayoutConstraint . HorizontallyFixed ;
58
+ }
59
+ else
60
+ {
61
+ view . ComputedConstraint = LayoutConstraint . None ;
62
+ }
63
+ }
64
+ }
39
65
}
40
66
}
Original file line number Diff line number Diff line change @@ -7,5 +7,17 @@ namespace Microsoft.Maui.Controls
7
7
public class VerticalStackLayout : StackBase
8
8
{
9
9
protected override ILayoutManager CreateLayoutManager ( ) => new VerticalStackLayoutManager ( this ) ;
10
+
11
+ internal override void ComputeConstraintForView ( View view )
12
+ {
13
+ if ( ( Constraint & LayoutConstraint . HorizontallyFixed ) != 0 && view . HorizontalOptions . Alignment == LayoutAlignment . Fill )
14
+ {
15
+ view . ComputedConstraint = LayoutConstraint . HorizontallyFixed ;
16
+ }
17
+ else
18
+ {
19
+ view . ComputedConstraint = LayoutConstraint . None ;
20
+ }
21
+ }
10
22
}
11
23
}
Original file line number Diff line number Diff line change 13
13
[ assembly: InternalsVisibleTo ( "Microsoft.Maui.Controls.Compatibility.Tizen" ) ]
14
14
[ assembly: InternalsVisibleTo ( "Microsoft.Maui.Controls.Core.Design" ) ]
15
15
[ assembly: InternalsVisibleTo ( "Microsoft.Maui.Controls.Core.UnitTests" ) ]
16
+ [ assembly: InternalsVisibleTo ( "Microsoft.Maui.UnitTests" ) ]
16
17
[ assembly: InternalsVisibleTo ( "Microsoft.Maui.Controls.Android.UnitTests" ) ]
17
18
[ assembly: InternalsVisibleTo ( "Microsoft.Maui.Controls.Compatibility.Android.UnitTests" ) ]
18
19
[ assembly: InternalsVisibleTo ( "Microsoft.Maui.Controls.Compatibility.UAP.UnitTests" ) ]
Original file line number Diff line number Diff line change
1
+ using Microsoft . Maui . Controls ;
2
+ using Xunit ;
3
+
4
+ namespace Microsoft . Maui . UnitTests . Layouts
5
+ {
6
+ [ Category ( TestCategory . Core , TestCategory . Layout ) ]
7
+ public class HorizontalStackLayoutTests
8
+ {
9
+ [ Fact ]
10
+ public void ConstrainsViewsVerticallyWhenConstrained ( )
11
+ {
12
+ var layout = new HorizontalStackLayout ( ) ;
13
+ var child = new ContentView ( ) ;
14
+ layout . Add ( child ) ;
15
+
16
+ Assert . Equal ( LayoutConstraint . None , child . Constraint ) ;
17
+
18
+ layout . HeightRequest = 100 ;
19
+ Assert . Equal ( LayoutConstraint . VerticallyFixed , child . Constraint ) ;
20
+
21
+ child . WidthRequest = 50 ;
22
+ Assert . Equal ( LayoutConstraint . Fixed , child . Constraint ) ;
23
+ }
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ using Microsoft . Maui . Controls ;
2
+ using Xunit ;
3
+
4
+ namespace Microsoft . Maui . UnitTests . Layouts
5
+ {
6
+ [ Category ( TestCategory . Core , TestCategory . Layout ) ]
7
+ public class StackLayoutTests
8
+ {
9
+ [ Fact ]
10
+ public void VerticalOrientationConstrainsViewsHorizontallyWhenConstrained ( )
11
+ {
12
+ var layout = new StackLayout { Orientation = StackOrientation . Vertical } ;
13
+ var child = new ContentView ( ) ;
14
+ layout . Add ( child ) ;
15
+
16
+ Assert . Equal ( LayoutConstraint . None , child . Constraint ) ;
17
+
18
+ layout . WidthRequest = 100 ;
19
+ Assert . Equal ( LayoutConstraint . HorizontallyFixed , child . Constraint ) ;
20
+
21
+ child . HeightRequest = 50 ;
22
+ Assert . Equal ( LayoutConstraint . Fixed , child . Constraint ) ;
23
+ }
24
+
25
+ [ Fact ]
26
+ public void HorizontalOrientationConstrainsViewsVerticallyWhenConstrained ( )
27
+ {
28
+ var layout = new StackLayout { Orientation = StackOrientation . Horizontal } ;
29
+ var child = new ContentView ( ) ;
30
+ layout . Add ( child ) ;
31
+
32
+ Assert . Equal ( LayoutConstraint . None , child . Constraint ) ;
33
+
34
+ layout . HeightRequest = 100 ;
35
+ Assert . Equal ( LayoutConstraint . VerticallyFixed , child . Constraint ) ;
36
+
37
+ child . WidthRequest = 50 ;
38
+ Assert . Equal ( LayoutConstraint . Fixed , child . Constraint ) ;
39
+ }
40
+ }
41
+ }
Original file line number Diff line number Diff line change
1
+ using Microsoft . Maui . Controls ;
2
+ using Xunit ;
3
+
4
+ namespace Microsoft . Maui . UnitTests . Layouts
5
+ {
6
+ [ Category ( TestCategory . Core , TestCategory . Layout ) ]
7
+ public class VerticalStackLayoutTests
8
+ {
9
+ [ Fact ]
10
+ public void ConstrainsViewsHorizontallyWhenConstrained ( )
11
+ {
12
+ var layout = new VerticalStackLayout ( ) ;
13
+ var child = new ContentView ( ) ;
14
+ layout . Add ( child ) ;
15
+
16
+ Assert . Equal ( LayoutConstraint . None , child . Constraint ) ;
17
+
18
+ layout . WidthRequest = 100 ;
19
+ Assert . Equal ( LayoutConstraint . HorizontallyFixed , child . Constraint ) ;
20
+
21
+ child . HeightRequest = 50 ;
22
+ Assert . Equal ( LayoutConstraint . Fixed , child . Constraint ) ;
23
+ }
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments