Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ void UpdateEmptyViewVisibility(bool isEmpty)

if (isEmpty)
{
CollectionView.LayoutIfNeeded();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to call this if we setting the ContentInset wouldn't t that call layout?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out it doesn't. I tried without it on the latest main and it doesn't work

ShowEmptyView();
}
else
Expand Down Expand Up @@ -544,6 +545,7 @@ void HideEmptyView()
}

_emptyUIView.RemoveFromSuperview();
CollectionView.ContentInset = UIEdgeInsets.Zero;

_emptyViewDisplayed = false;
}
Expand All @@ -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)
Expand All @@ -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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IS this the best way to do it ? Why do we need to inset?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it, a CollectionView with an empty view whose height exceeds the frame won't scroll.


if (_emptyViewFormsElement != null && ((IElementController)ItemsView).LogicalChildren.IndexOf(_emptyViewFormsElement) != -1)
_emptyViewFormsElement.Layout(frame.ToRectangle());
Expand Down
20 changes: 20 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue28118.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns:controls="clr-namespace:Maui.Controls.Sample.Issues"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue28118">
<Grid RowDefinitions="*">
<CollectionView AutomationId="CollectionView">
<CollectionView.EmptyView>
<VerticalStackLayout>
<ContentView HeightRequest="500"
BackgroundColor="Red"/>
<ContentView HeightRequest="500"
BackgroundColor="Blue"/>
<Label Text="Success"
AutomationId="SuccessLabel"/>
</VerticalStackLayout>
</CollectionView.EmptyView>
</CollectionView>
</Grid>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
Loading