Skip to content

Commit 05999a1

Browse files
authored
[iOS] CollectionView footer sizing when source is empty - fix (dotnet#28610)
* [iOS] CollectionView footer sizing fix * Added snapshots * Added Macos snapshot * Update StructuredItemsViewController.cs * Update StructuredItemsViewController.cs
1 parent 8ee00e0 commit 05999a1

File tree

8 files changed

+91
-2
lines changed

8 files changed

+91
-2
lines changed

src/Controls/src/Core/Handlers/Items/iOS/StructuredItemsViewController.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void UpdateHeaderFooterPosition()
206206
}
207207
}
208208

209-
if (_headerUIView != null && _headerUIView.Frame.Y != headerHeight)
209+
if (_headerUIView != null && (_headerUIView.Frame.Y != -headerHeight || _headerUIView.Frame.Width != CollectionView.Frame.Width))
210210
{
211211
_headerUIView.Frame = new CoreGraphics.CGRect(0, -headerHeight, CollectionView.Frame.Width, headerHeight);
212212
}
@@ -218,7 +218,7 @@ void UpdateHeaderFooterPosition()
218218
height = ItemsViewLayout.CollectionViewContentSize.Height;
219219
}
220220

221-
if (_footerUIView != null && (_footerUIView.Frame.Y != height || emptyHeight > 0 || _footerUIView.Frame.Height != footerHeight))
221+
if (_footerUIView != null && (_footerUIView.Frame.Y != height || emptyHeight > 0 || _footerUIView.Frame.Height != footerHeight || _footerUIView.Frame.Width != CollectionView.Frame.Width))
222222
{
223223
_footerUIView.Frame = new CoreGraphics.CGRect(0, height + emptyHeight, CollectionView.Frame.Width, footerHeight);
224224
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"
5+
x:Class="Maui.Controls.Sample.Issues.Issue28580">
6+
<Grid Padding="30">
7+
<CollectionView>
8+
<CollectionView.Header>
9+
<Border
10+
Stroke="Black"
11+
Margin="0">
12+
<Grid
13+
ColumnDefinitions="*,Auto"
14+
ColumnSpacing="5">
15+
<Label
16+
Grid.Column="1"
17+
Text="add new"
18+
HorizontalOptions="Center"
19+
VerticalOptions="Center"
20+
VerticalTextAlignment="Center"/>
21+
22+
<Label
23+
Grid.Column="0"
24+
Text="+"
25+
HorizontalOptions="End"
26+
VerticalOptions="Center"
27+
VerticalTextAlignment="Center"/>
28+
</Grid>
29+
</Border>
30+
</CollectionView.Header>
31+
32+
<CollectionView.Footer>
33+
<Border
34+
Stroke="Black"
35+
Margin="0">
36+
<Grid
37+
ColumnDefinitions="*,Auto"
38+
ColumnSpacing="5">
39+
<Label
40+
Grid.Column="1"
41+
Text="add new"
42+
AutomationId="labelInFooter"
43+
HorizontalOptions="Center"
44+
VerticalOptions="Center"
45+
VerticalTextAlignment="Center"/>
46+
47+
<Label
48+
Grid.Column="0"
49+
Text="+"
50+
HorizontalOptions="End"
51+
VerticalOptions="Center"
52+
VerticalTextAlignment="Center"/>
53+
</Grid>
54+
</Border>
55+
</CollectionView.Footer>
56+
</CollectionView>
57+
</Grid>
58+
</ContentPage>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
3+
[Issue(IssueTracker.Github, 28580, "CollectionView footer sizing when source is empty")]
4+
public partial class Issue28580 : ContentPage
5+
{
6+
public Issue28580()
7+
{
8+
InitializeComponent();
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues;
6+
public class Issue28580 : _IssuesUITest
7+
{
8+
public Issue28580(TestDevice testDevice) : base(testDevice)
9+
{
10+
}
11+
12+
public override string Issue => "CollectionView footer sizing when source is empty";
13+
14+
[Test]
15+
[Category(UITestCategories.CollectionView)]
16+
public void FooterWithEmptyCVShouldHaveCorrectSize()
17+
{
18+
App.WaitForElement("labelInFooter");
19+
VerifyScreenshot();
20+
}
21+
}

0 commit comments

Comments
 (0)