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 @@ -559,11 +559,11 @@ void TearDownEmptyView()
_emptyViewFormsElement = null;
}

void LayoutEmptyView()
virtual internal CGRect LayoutEmptyView()
{
if (!_initialized || _emptyUIView == null || _emptyUIView.Superview == null)
{
return;
return CGRect.Empty;
}

var frame = DetermineEmptyViewFrame();
Expand All @@ -572,6 +572,8 @@ void LayoutEmptyView()

if (_emptyViewFormsElement != null && ((IElementController)ItemsView).LogicalChildren.IndexOf(_emptyViewFormsElement) != -1)
_emptyViewFormsElement.Layout(frame.ToRectangle());

return frame;
}

internal protected virtual void UpdateVisibility()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ void UpdateDefaultSupplementaryView(DefaultCell2 cell, NSString elementKind)
: ItemsView.Footer;

cell.Label.Text = obj?.ToString();
cell.Tag = elementKind == UICollectionElementKindSectionKey.Header
? HeaderTag
: FooterTag;
}

void UpdateTemplatedSupplementaryView(TemplatedCell2 cell, NSString elementKind)
Expand Down Expand Up @@ -160,6 +163,21 @@ string DetermineViewReuseId(DataTemplate template, object item)
? HorizontalSupplementaryView2.ReuseId
: VerticalSupplementaryView2.ReuseId;
}
internal override CGRect LayoutEmptyView()
{
var emptyViewFrame = base.LayoutEmptyView();
var footerView = CollectionView.ViewWithTag(FooterTag);

if (footerView is not null)
{
if (emptyViewFrame.Height > 0)
footerView.Frame = new CGRect(footerView.Frame.X, emptyViewFrame.Bottom, footerView.Frame.Width, footerView.Frame.Height);
else
footerView.Frame = new CGRect(footerView.Frame.X, CollectionView.ContentSize.Height - footerView.Frame.Height, footerView.Frame.Width, footerView.Frame.Height);
}

return emptyViewFrame;
}

protected override CGRect DetermineEmptyViewFrame()
{
Expand All @@ -175,8 +193,8 @@ protected override CGRect DetermineEmptyViewFrame()
if (footerView != null)
footerHeight = footerView.Frame.Height;

return new CGRect(CollectionView.Frame.X, CollectionView.Frame.Y, CollectionView.Frame.Width,
Math.Abs(CollectionView.Frame.Height - (headerHeight + footerHeight)));
return new CGRect(CollectionView.Frame.X, CollectionView.Frame.Y + headerHeight, CollectionView.Frame.Width,
Math.Abs(CollectionView.Frame.Height - (headerHeight + footerHeight)));
}

public override void ViewWillLayoutSubviews()
Expand Down
61 changes: 61 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue28604.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Collections.ObjectModel;

namespace Maui.Controls.Sample.Issues;
[Issue(IssueTracker.Github, 28604, "Footer Not Displayed at the Bottom When EmptyView is Active in CV2", PlatformAffected.iOS)]
public class Issue28604 : ContentPage
{
private CollectionViewViewModel ViewModel;

public Issue28604()
{
ViewModel = new CollectionViewViewModel();
BindingContext = ViewModel;

var grid = new Grid();

var collectionView = new CollectionView2
{
AutomationId = "CollectionView",
ItemsSource = ViewModel.ItemList,
EmptyView = "EmptyView",
Background = Colors.AliceBlue,
Header = new VerticalStackLayout
{
BackgroundColor = Colors.Red,
Children =
{
new Label
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Can set the BackgroundColor? In this way, we not only verify the position of the header/footer, also the size with the snapshot comparison.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz Updated test sample.

Text = "Header",
FontAttributes = FontAttributes.Bold
}
}
},
Footer = new VerticalStackLayout
{
BackgroundColor = Colors.Yellow,
Children =
{
new Label
{
Text = "Footer",
FontAttributes = FontAttributes.Bold
}
}
}
};
grid.Children.Add(collectionView);

Content = grid;
}
}

public class CollectionViewViewModel
{
public ObservableCollection<string> ItemList { get; set; }

public CollectionViewViewModel()
{
ItemList = new ObservableCollection<string>();
}
}
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,23 @@
#if !ANDROID // this test case is ignored in android, as it has incositent scrolling behavior while using emptyView as string. https://github.com/dotnet/maui/issues/28765
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue28604 : _IssuesUITest
{
public Issue28604(TestDevice testDevice) : base(testDevice)
{
}
public override string Issue => "Footer Not Displayed at the Bottom When EmptyView is Active in CV2";

[Test]
[Category(UITestCategories.CollectionView)]
public void FooterShouldDisplayAtBottomOfEmptyView()
{
App.WaitForElement("CollectionView");
VerifyScreenshot();
Copy link
Contributor

Choose a reason for hiding this comment

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

Pending snapshots, already available in the latest build:
image
Could you commit the images?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz Added the images.

}
}
#endif
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading