Skip to content

Commit 474750b

Browse files
Dhivya-SF4094PureWeen
authored andcommitted
Fixed Footer not displayed at the Bottom When EmptyView in CV2 (#28681)
* Fixed Footer not displayed at the Bottom When EmptyView in CV2 * Updated test sample with Background Color * Updated fix for CV1 * Removed unwanted changes and updated screenshot * Added comment in test sample * Updated test sample * Added snapshot for mac and WinUI * Re- Added mac snapshot * Update HeaderAndFooterShouldBeVisible.png
1 parent fd44ced commit 474750b

File tree

8 files changed

+108
-4
lines changed

8 files changed

+108
-4
lines changed

src/Controls/src/Core/Handlers/Items2/iOS/ItemsViewController2.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,11 @@ void TearDownEmptyView()
564564
_emptyViewFormsElement = null;
565565
}
566566

567-
void LayoutEmptyView()
567+
virtual internal CGRect LayoutEmptyView()
568568
{
569569
if (!_initialized || _emptyUIView == null || _emptyUIView.Superview == null)
570570
{
571-
return;
571+
return CGRect.Empty;
572572
}
573573

574574
var frame = DetermineEmptyViewFrame();
@@ -577,6 +577,8 @@ void LayoutEmptyView()
577577

578578
if (_emptyViewFormsElement != null && ((IElementController)ItemsView).LogicalChildren.IndexOf(_emptyViewFormsElement) != -1)
579579
_emptyViewFormsElement.Layout(frame.ToRectangle());
580+
581+
return frame;
580582
}
581583

582584
internal protected virtual void UpdateVisibility()

src/Controls/src/Core/Handlers/Items2/iOS/StructuredItemsViewController2.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ void UpdateDefaultSupplementaryView(DefaultCell2 cell, NSString elementKind)
101101
: ItemsView.Footer;
102102

103103
cell.Label.Text = obj?.ToString();
104+
cell.Tag = elementKind == UICollectionElementKindSectionKey.Header
105+
? HeaderTag
106+
: FooterTag;
104107
}
105108

106109
void UpdateTemplatedSupplementaryView(TemplatedCell2 cell, NSString elementKind)
@@ -157,6 +160,21 @@ string DetermineViewReuseId(DataTemplate template, object item)
157160
? HorizontalSupplementaryView2.ReuseId
158161
: VerticalSupplementaryView2.ReuseId;
159162
}
163+
internal override CGRect LayoutEmptyView()
164+
{
165+
var emptyViewFrame = base.LayoutEmptyView();
166+
var footerView = CollectionView.ViewWithTag(FooterTag);
167+
168+
if (footerView is not null)
169+
{
170+
if (emptyViewFrame.Height > 0)
171+
footerView.Frame = new CGRect(footerView.Frame.X, emptyViewFrame.Bottom, footerView.Frame.Width, footerView.Frame.Height);
172+
else
173+
footerView.Frame = new CGRect(footerView.Frame.X, CollectionView.ContentSize.Height - footerView.Frame.Height, footerView.Frame.Width, footerView.Frame.Height);
174+
}
175+
176+
return emptyViewFrame;
177+
}
160178

161179
protected override CGRect DetermineEmptyViewFrame()
162180
{
@@ -172,8 +190,8 @@ protected override CGRect DetermineEmptyViewFrame()
172190
if (footerView != null)
173191
footerHeight = footerView.Frame.Height;
174192

175-
return new CGRect(CollectionView.Frame.X, CollectionView.Frame.Y, CollectionView.Frame.Width,
176-
Math.Abs(CollectionView.Frame.Height - (headerHeight + footerHeight)));
193+
return new CGRect(CollectionView.Frame.X, CollectionView.Frame.Y + headerHeight, CollectionView.Frame.Width,
194+
Math.Abs(CollectionView.Frame.Height - (headerHeight + footerHeight)));
177195
}
178196

179197
public override void ViewWillLayoutSubviews()
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System.Collections.ObjectModel;
2+
3+
namespace Maui.Controls.Sample.Issues;
4+
[Issue(IssueTracker.Github, 28604, "Footer Not Displayed at the Bottom When EmptyView is Active in CV2", PlatformAffected.iOS)]
5+
public class Issue28604 : ContentPage
6+
{
7+
private CollectionViewViewModel ViewModel;
8+
9+
public Issue28604()
10+
{
11+
ViewModel = new CollectionViewViewModel();
12+
BindingContext = ViewModel;
13+
14+
var grid = new Grid();
15+
16+
var collectionView = new CollectionView2
17+
{
18+
AutomationId = "CollectionView",
19+
ItemsSource = ViewModel.ItemList,
20+
EmptyView = "EmptyView",
21+
Background = Colors.AliceBlue,
22+
Header = new VerticalStackLayout
23+
{
24+
BackgroundColor = Colors.Red,
25+
Children =
26+
{
27+
new Label
28+
{
29+
Text = "Header",
30+
FontAttributes = FontAttributes.Bold
31+
}
32+
}
33+
},
34+
Footer = new VerticalStackLayout
35+
{
36+
BackgroundColor = Colors.Yellow,
37+
Children =
38+
{
39+
new Label
40+
{
41+
Text = "Footer",
42+
FontAttributes = FontAttributes.Bold
43+
}
44+
}
45+
}
46+
};
47+
grid.Children.Add(collectionView);
48+
49+
Content = grid;
50+
}
51+
}
52+
53+
public class CollectionViewViewModel
54+
{
55+
public ObservableCollection<string> ItemList { get; set; }
56+
57+
public CollectionViewViewModel()
58+
{
59+
ItemList = new ObservableCollection<string>();
60+
}
61+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#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
2+
using NUnit.Framework;
3+
using UITest.Appium;
4+
using UITest.Core;
5+
6+
namespace Microsoft.Maui.TestCases.Tests.Issues;
7+
8+
public class Issue28604 : _IssuesUITest
9+
{
10+
public Issue28604(TestDevice testDevice) : base(testDevice)
11+
{
12+
}
13+
public override string Issue => "Footer Not Displayed at the Bottom When EmptyView is Active in CV2";
14+
15+
[Test]
16+
[Category(UITestCategories.CollectionView)]
17+
public void FooterShouldDisplayAtBottomOfEmptyView()
18+
{
19+
App.WaitForElement("CollectionView");
20+
VerifyScreenshot();
21+
}
22+
}
23+
#endif
Loading

0 commit comments

Comments
 (0)