diff --git a/src/Controls/src/Core/Handlers/Items/iOS/StructuredItemsViewController.cs b/src/Controls/src/Core/Handlers/Items/iOS/StructuredItemsViewController.cs
index 3d9ef7689442..8cebe04f6b27 100644
--- a/src/Controls/src/Core/Handlers/Items/iOS/StructuredItemsViewController.cs
+++ b/src/Controls/src/Core/Handlers/Items/iOS/StructuredItemsViewController.cs
@@ -40,16 +40,6 @@ internal override void Disconnect()
_footerViewFormsElement.MeasureInvalidated -= OnFormsElementMeasureInvalidated;
}
- if (_headerUIView is MauiView hv)
- {
- hv.LayoutChanged -= HeaderViewLayoutChanged;
- }
-
- if (_footerUIView is MauiView fv)
- {
- fv.LayoutChanged -= FooterViewLayoutChanged;
- }
-
_headerUIView = null;
_headerViewFormsElement = null;
_footerUIView = null;
@@ -125,36 +115,16 @@ public override void ViewWillLayoutSubviews()
internal void UpdateFooterView()
{
- if (_footerUIView is MauiView mvPrevious)
- {
- mvPrevious.LayoutChanged -= FooterViewLayoutChanged;
- }
-
UpdateSubview(ItemsView?.Footer, ItemsView?.FooterTemplate, FooterTag,
ref _footerUIView, ref _footerViewFormsElement);
UpdateHeaderFooterPosition();
-
- if (_footerUIView is MauiView mv)
- {
- mv.LayoutChanged += FooterViewLayoutChanged;
- }
}
internal void UpdateHeaderView()
{
- if (_headerUIView is MauiView mvPrevious)
- {
- mvPrevious.LayoutChanged -= HeaderViewLayoutChanged;
- }
-
UpdateSubview(ItemsView?.Header, ItemsView?.HeaderTemplate, HeaderTag,
ref _headerUIView, ref _headerViewFormsElement);
UpdateHeaderFooterPosition();
-
- if (_headerUIView is MauiView mv)
- {
- mv.LayoutChanged += HeaderViewLayoutChanged;
- }
}
@@ -200,8 +170,8 @@ void UpdateHeaderFooterPosition()
{
var currentInset = CollectionView.ContentInset;
- nfloat headerWidth = _headerUIView?.Frame.Width ?? 0f;
- nfloat footerWidth = _footerUIView?.Frame.Width ?? 0f;
+ nfloat headerWidth = _headerViewFormsElement?.ToPlatform()?.Frame.Width ?? 0f;
+ nfloat footerWidth = _footerViewFormsElement?.ToPlatform()?.Frame.Width ?? 0f;
nfloat emptyWidth = emptyView?.Frame.Width ?? 0f;
if (_headerUIView != null && _headerUIView.Frame.X != headerWidth)
@@ -230,8 +200,8 @@ void UpdateHeaderFooterPosition()
else
{
var currentInset = CollectionView.ContentInset;
- nfloat headerHeight = _headerUIView?.Frame.Height ?? 0f;
- nfloat footerHeight = _footerUIView?.Frame.Height ?? 0f;
+ nfloat headerHeight = _headerViewFormsElement?.ToPlatform()?.Frame.Height ?? 0f;
+ nfloat footerHeight = _footerViewFormsElement?.ToPlatform()?.Frame.Height ?? 0f;
nfloat emptyHeight = emptyView?.Frame.Height ?? 0f;
if (CollectionView.ContentInset.Top != headerHeight || CollectionView.ContentInset.Bottom != footerHeight)
@@ -283,15 +253,5 @@ internal void UpdateLayoutMeasurements()
if (_footerViewFormsElement != null)
HandleFormsElementMeasureInvalidated(_footerViewFormsElement);
}
-
- void HeaderViewLayoutChanged(object sender, EventArgs e)
- {
- HandleFormsElementMeasureInvalidated(_headerViewFormsElement);
- }
-
- void FooterViewLayoutChanged(object sender, EventArgs e)
- {
- HandleFormsElementMeasureInvalidated(_footerViewFormsElement);
- }
}
}
\ No newline at end of file
diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/HeaderShouldNotCollapseWithItems.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/HeaderShouldNotCollapseWithItems.png
new file mode 100644
index 000000000000..02de2114edb5
Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/HeaderShouldNotCollapseWithItems.png differ
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue25362.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue25362.xaml
new file mode 100644
index 000000000000..d66257d0af53
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue25362.xaml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue25362.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue25362.xaml.cs
new file mode 100644
index 000000000000..f72fa2831aee
--- /dev/null
+++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue25362.xaml.cs
@@ -0,0 +1,24 @@
+using System.Collections.ObjectModel;
+using Microsoft.Maui.Controls;
+using Microsoft.Maui.Controls.Xaml;
+
+namespace Maui.Controls.Sample.Issues;
+
+[XamlCompilation(XamlCompilationOptions.Compile)]
+[Issue(IssueTracker.Github, 25362, "[iOS] CollectionView Items display issue when Header is resized", PlatformAffected.iOS)]
+
+public partial class Issue25362 : ContentPage
+{
+ public ObservableCollection ItemList { get; }
+ public ObservableCollection ItemListHeader { get; }
+
+ public Command AddCommand => new(() => ItemListHeader.Add($"HeaderItem{ItemListHeader.Count + 1}"));
+
+ public Issue25362()
+ {
+ InitializeComponent();
+ ItemList = new() { "Item1", "Item2", "Itme3" };
+ ItemListHeader = new() { "HeaderItem1" };
+ BindingContext = this;
+ }
+}
diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue25362.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue25362.cs
new file mode 100644
index 000000000000..64caa900f72a
--- /dev/null
+++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue25362.cs
@@ -0,0 +1,28 @@
+using NUnit.Framework;
+using UITest.Appium;
+using UITest.Core;
+
+namespace Microsoft.Maui.TestCases.Tests.Issues;
+
+public class Issue25362 : _IssuesUITest
+{
+ public override string Issue => "[iOS] CollectionView Items display issue when Header is resized";
+
+ public Issue25362(TestDevice device) : base(device)
+ { }
+
+ [Test]
+ [Category(UITestCategories.CollectionView)]
+ [FailsOnIOSWhenRunningOnXamarinUITest("This is not working for CV2 yet")]
+ [FailsOnMacWhenRunningOnXamarinUITest("This is not working for CV2 yet")]
+ public void HeaderShouldNotCollapseWithItems()
+ {
+ App.WaitForElement("button");
+ App.Click("button");
+ App.Click("button");
+ App.Click("button");
+
+ //The test passes of header has 4 elements that don't overlap with the collection view's items
+ VerifyScreenshot();
+ }
+}
diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/HeaderShouldNotCollapseWithItems.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/HeaderShouldNotCollapseWithItems.png
new file mode 100644
index 000000000000..b90d317ccac4
Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/HeaderShouldNotCollapseWithItems.png differ
diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/HeaderShouldNotCollapseWithItems.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/HeaderShouldNotCollapseWithItems.png
new file mode 100644
index 000000000000..1b92f71ad666
Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/HeaderShouldNotCollapseWithItems.png differ
diff --git a/src/Core/src/Platform/iOS/MauiView.cs b/src/Core/src/Platform/iOS/MauiView.cs
index 1d9b985611e7..c2d04b68e4e6 100644
--- a/src/Core/src/Platform/iOS/MauiView.cs
+++ b/src/Core/src/Platform/iOS/MauiView.cs
@@ -137,7 +137,6 @@ public override void LayoutSubviews()
}
CrossPlatformArrange(bounds);
- OnLayoutChanged();
}
public override void SetNeedsLayout()
@@ -199,13 +198,5 @@ public override void MovedToWindow()
_movedToWindow?.Invoke(this, EventArgs.Empty);
TryToInvalidateSuperView(true);
}
-
- [UnconditionalSuppressMessage("Memory", "MEM0001", Justification = IUIViewLifeCycleEvents.UnconditionalSuppressMessage)]
- internal event EventHandler? LayoutChanged;
-
- private void OnLayoutChanged()
- {
- LayoutChanged?.Invoke(this, EventArgs.Empty);
- }
}
}