Skip to content

Commit e9a1bb2

Browse files
committed
Revert "[iOS] CollectionView footer sizing when source is empty in SR5 (#28971)"
1 parent d35fff9 commit e9a1bb2

File tree

6 files changed

+110
-24
lines changed

6 files changed

+110
-24
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,6 @@ public override void ViewWillAppear(bool animated)
199199
public override void ViewWillLayoutSubviews()
200200
{
201201
ConstrainItemsToBounds();
202-
203-
if (CollectionView is Items.MauiCollectionView { NeedsCellLayout: true } collectionView)
204-
{
205-
collectionView.NeedsCellLayout = false;
206-
}
207-
208202
base.ViewWillLayoutSubviews();
209203
InvalidateMeasureIfContentSizeChanged();
210204
LayoutEmptyView();

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ internal class MauiCollectionView : UICollectionView, IUIViewLifeCycleEvents, IP
1010
bool _invalidateParentWhenMovedToWindow;
1111

1212
WeakReference<ICustomMauiCollectionViewDelegate>? _customDelegate;
13-
14-
internal bool NeedsCellLayout { get; set; }
15-
1613
public MauiCollectionView(CGRect frame, UICollectionViewLayout layout) : base(frame, layout)
1714
{
1815
}
@@ -30,11 +27,10 @@ void IPlatformMeasureInvalidationController.InvalidateAncestorsMeasuresWhenMoved
3027

3128
void IPlatformMeasureInvalidationController.InvalidateMeasure(bool isPropagating)
3229
{
33-
if (isPropagating)
30+
if (!isPropagating)
3431
{
35-
NeedsCellLayout = true;
32+
SetNeedsLayout();
3633
}
37-
SetNeedsLayout();
3834
}
3935

4036
[UnconditionalSuppressMessage("Memory", "MEM0002", Justification = IUIViewLifeCycleEvents.UnconditionalSuppressMessage)]

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,27 @@ protected override CGRect DetermineEmptyViewFrame()
8686

8787
public override void ViewWillLayoutSubviews()
8888
{
89-
var hasHeaderOrFooter = _footerViewFormsElement is not null || _headerViewFormsElement is not null;
90-
if (hasHeaderOrFooter && CollectionView is MauiCollectionView { NeedsCellLayout: true } collectionView)
89+
base.ViewWillLayoutSubviews();
90+
91+
// This update is only relevant if you have a footer view because it's used to place the footer view
92+
// based on the ContentSize so we just update the positions if the ContentSize has changed
93+
if (_footerUIView != null)
9194
{
92-
if (_headerViewFormsElement is not null)
95+
var emptyView = CollectionView.ViewWithTag(EmptyTag);
96+
97+
if (IsHorizontal)
9398
{
94-
RemeasureLayout(_headerViewFormsElement);
99+
if (_footerUIView.Frame.X != ItemsViewLayout.CollectionViewContentSize.Width ||
100+
_footerUIView.Frame.X < emptyView?.Frame.X)
101+
UpdateHeaderFooterPosition();
95102
}
96-
97-
if (_footerViewFormsElement is not null)
103+
else
98104
{
99-
RemeasureLayout(_footerViewFormsElement);
105+
if (_footerUIView.Frame.Y != ItemsViewLayout.CollectionViewContentSize.Height ||
106+
_footerUIView.Frame.Y < (emptyView?.Frame.Y + emptyView?.Frame.Height))
107+
UpdateHeaderFooterPosition();
100108
}
101-
102-
UpdateHeaderFooterPosition();
103109
}
104-
105-
base.ViewWillLayoutSubviews();
106110
}
107111

108112
internal void UpdateFooterView()
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
[Issue(IssueTracker.Github, 29051, "I8_Headers_and_Footers displays the footer 2019 in the middle of the header", PlatformAffected.iOS)]
3+
public class Issue29051 : ContentPage
4+
{
5+
public Issue29051()
6+
{
7+
var mainGrid = new Grid
8+
{
9+
Margin = new Thickness(20),
10+
RowDefinitions =
11+
{
12+
new RowDefinition { Height = GridLength.Auto },
13+
new RowDefinition { Height = GridLength.Star }
14+
}
15+
};
16+
17+
var instructionsStack = new StackLayout
18+
{
19+
Children =
20+
{
21+
new Label { Text = "1. The test passes if the view is displayed in Vertical list layout." },
22+
new Label { Text = "2. The test passes if the header text display 'Monkeys'." },
23+
new Label { Text = "3. The test passes if the footer text display '2019'." }
24+
}
25+
};
26+
27+
Grid.SetRow(instructionsStack, 0);
28+
mainGrid.Children.Add(instructionsStack);
29+
30+
var collectionView = new CollectionView
31+
{
32+
Header = "Monkeys",
33+
Footer = "2019",
34+
ItemTemplate = new DataTemplate(() =>
35+
{
36+
var itemGrid = new Grid
37+
{
38+
Padding = new Thickness(10),
39+
RowDefinitions =
40+
{
41+
new RowDefinition { Height = GridLength.Auto },
42+
new RowDefinition { Height = GridLength.Auto }
43+
},
44+
ColumnDefinitions =
45+
{
46+
new ColumnDefinition { Width = GridLength.Auto },
47+
new ColumnDefinition { Width = GridLength.Star }
48+
}
49+
};
50+
51+
var nameLabel = new Label
52+
{
53+
FontAttributes = FontAttributes.Bold
54+
};
55+
nameLabel.SetBinding(Label.TextProperty, "Name");
56+
nameLabel.SetBinding(Label.AutomationIdProperty, "AutomationId");
57+
58+
Grid.SetColumn(nameLabel, 1);
59+
itemGrid.Children.Add(nameLabel);
60+
61+
return itemGrid;
62+
}),
63+
ItemsSource = Enumerable.Range(0, 20).Select(i => new { Name = $"Item {i}", AutomationId = $"Item{i}" }).ToList(),
64+
};
65+
66+
Grid.SetRow(collectionView, 1);
67+
mainGrid.Children.Add(collectionView);
68+
69+
Content = mainGrid;
70+
}
71+
}

src/Controls/tests/TestCases.HostApp/MauiProgram.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public App()
7272

7373
public Page CreateDefaultMainPage()
7474
{
75-
return new CoreNavigationPage();
75+
return new Issue29051();
7676
}
7777

7878
protected override void OnAppLinkRequestReceived(Uri uri)
Lines changed: 21 additions & 0 deletions
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 Issue29051 : _IssuesUITest
7+
{
8+
public Issue29051(TestDevice testDevice) : base(testDevice)
9+
{
10+
}
11+
12+
public override string Issue => "I8_Headers_and_Footers displays the footer 2019 in the middle of the header";
13+
14+
[Test]
15+
[Category(UITestCategories.CollectionView)]
16+
public void FooterAndHeaderArePlacedCorrectlyAboveAndBelowCollectionView()
17+
{
18+
App.WaitForElement("Item1");
19+
VerifyScreenshot();
20+
}
21+
}

0 commit comments

Comments
 (0)