diff --git a/src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs b/src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs index 7e93d347b36e..bea0ef24b850 100644 --- a/src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs +++ b/src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs @@ -469,6 +469,7 @@ void UpdateEmptyViewVisibility(bool isEmpty) if (isEmpty) { + CollectionView.LayoutIfNeeded(); ShowEmptyView(); } else @@ -544,6 +545,7 @@ void HideEmptyView() } _emptyUIView.RemoveFromSuperview(); + CollectionView.ContentInset = UIEdgeInsets.Zero; _emptyViewDisplayed = false; } @@ -559,6 +561,24 @@ void TearDownEmptyView() _emptyViewFormsElement = null; } + void RemeasureLayout(VisualElement formsElement) + { + if (IsHorizontal) + { + MeasureAndArrange(formsElement, double.PositiveInfinity, CollectionView.Frame.Height); + } + else + { + MeasureAndArrange(formsElement, CollectionView.Frame.Width, double.PositiveInfinity); + } + } + + void MeasureAndArrange(VisualElement element, double widthConstraint, double heightConstraint) + { + var request = element.Measure(widthConstraint, heightConstraint); + element.Arrange(new Rect(0, 0, request.Width, request.Height)); + } + void LayoutEmptyView() { if (!_initialized || _emptyUIView == null || _emptyUIView.Superview == null) @@ -568,7 +588,10 @@ void LayoutEmptyView() var frame = DetermineEmptyViewFrame(); + RemeasureLayout(_emptyViewFormsElement); + frame = new CGRect(frame.X, frame.Y, frame.Width, Math.Max(frame.Height, _emptyViewFormsElement.Height)); _emptyUIView.Frame = frame; + CollectionView.ContentInset = new UIEdgeInsets(0, 0, frame.Height, 0); if (_emptyViewFormsElement != null && ((IElementController)ItemsView).LogicalChildren.IndexOf(_emptyViewFormsElement) != -1) _emptyViewFormsElement.Layout(frame.ToRectangle()); diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue28118.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue28118.xaml new file mode 100644 index 000000000000..df47e3d79724 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue28118.xaml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + diff --git a/src/Controls/tests/TestCases.HostApp/Issues/issue28118.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/issue28118.xaml.cs new file mode 100644 index 000000000000..a7db4048cfa7 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/issue28118.xaml.cs @@ -0,0 +1,9 @@ +namespace Maui.Controls.Sample.Issues; +[Issue(IssueTracker.Github, 28118, "CollectionView - empty view issues", PlatformAffected.iOS)] +public partial class Issue28118 : ContentPage +{ + public Issue28118() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28118.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28118.cs new file mode 100644 index 000000000000..89cbde595237 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28118.cs @@ -0,0 +1,22 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; +public class Issue28118 : _IssuesUITest +{ + public Issue28118(TestDevice testDevice) : base(testDevice) + { + } + + public override string Issue => "CollectionView - empty view issues"; + + [Test] + [Category(UITestCategories.CollectionView)] + public void EmptyViewShouldScroll() + { + App.WaitForElement("CollectionView"); + App.ScrollDown("CollectionView", ScrollStrategy.Gesture, 0.5); + App.WaitForElement("SuccessLabel"); + } +} \ No newline at end of file