Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,15 @@ virtual internal CGRect LayoutEmptyView()

if (_emptyViewFormsElement != null && ((IElementController)ItemsView).LogicalChildren.IndexOf(_emptyViewFormsElement) != -1)
{
_emptyViewFormsElement.Measure(frame.Width, frame.Height);
_emptyViewFormsElement.Arrange(frame.ToRectangle());
if (frame.Width > 0 && frame.Height > 0)
{
_emptyViewFormsElement.Measure(frame.Width, frame.Height);

// Arrange in the native container's local coordinate space (0,0).
// The native container (_emptyUIView) is already positioned correctly by iOS,
// so the MAUI element just needs to fill its container without additional offset.
_emptyViewFormsElement.Arrange(new Rect(0, 0, frame.Width, frame.Height));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On iOS devices with notches/home indicators, safe area insets; is correct?

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.

Yes @jsuarezruiz , I have ensured the fix with the latest changes on a notch screen device; it’s working fine.

Demo.mov

}
}

_emptyUIView.Frame = frame;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue31465.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System.Collections.ObjectModel;

namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 31465, "The page can be dragged down, and it would cause an extra space between Header and EmptyView text.", PlatformAffected.iOS)]
public class Issue31465 : ContentPage
{
public Issue31465()
{
var grid = new Grid
{
Margin = new Thickness(20),
RowDefinitions =
{
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Star }
}
};

// Header Label
var headerLabel = new Label
{
Text = "Test for CollectionView empty view positioning",
AutomationId = "HeaderLabel",
};
Grid.SetRow(headerLabel, 0);
grid.Children.Add(headerLabel);

// CollectionView
var collectionView = new CollectionView
{
AutomationId = "CollectionView",
ItemsSource = Array.Empty<string>(), // empty array to trigger EmptyView
ItemTemplate = new DataTemplate(() =>
{
return new Label
{
TextColor = Colors.Black,
FontSize = 16,
// This binding works with string items
BindingContext = "{Binding .}"
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

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

The BindingContext property should not be assigned a string value. It should be assigned the actual binding expression. Use this.SetBinding(BindingContextProperty, \".\") instead, or remove this line entirely since the binding context will be set automatically for DataTemplate items.

Suggested change
BindingContext = "{Binding .}"

Copilot uses AI. Check for mistakes.
};
})
};

// EmptyView
collectionView.EmptyView = new Label
{
BackgroundColor = Color.FromArgb("#FFE40606"),
Text = "EmptyView: This should show when no data.",
TextColor = Color.FromArgb("#512BD4")
};

collectionView.Header = new Button
Comment thread
jsuarezruiz marked this conversation as resolved.
{
AutomationId = "CollectionViewHeader",
BackgroundColor = Colors.LightBlue,
Text = "Click me to verify the EmptyView position",
TextColor = Color.FromArgb("#512BD4")
};

Grid.SetRow(collectionView, 1);
grid.Children.Add(collectionView);

// Set ContentPage content
Content = grid;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue31465 : _IssuesUITest
{
public Issue31465(TestDevice device) : base(device) { }

public override string Issue => "The page can be dragged down, and it would cause an extra space between Header and EmptyView text.";
[Test]
[Category(UITestCategories.CollectionView)]
public void VerifyCollectionViewEmptyView()
{
App.WaitForElement("HeaderLabel");
App.Click("CollectionViewHeader");
VerifyScreenshot();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pending snapshots, running a build.

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.

@jsuarezruiz , I have added the snapshots for all platforms

}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading