Skip to content

Commit dde62b0

Browse files
prakashKannanSf3972PureWeen
authored andcommitted
Fixed-Footer-Scrolling-Issue (#29381)
1 parent b0e1a89 commit dde62b0

File tree

4 files changed

+88
-10
lines changed

4 files changed

+88
-10
lines changed

src/Controls/src/Core/Handlers/Items/Android/Adapters/EmptyViewAdapter.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ protected RecyclerView.ViewHolder CreateHeaderFooterViewHolder(object content, D
223223
}
224224

225225
// No template, Footer is not a Forms View, so just display Footer.ToString
226-
return SimpleViewHolder.FromText(content?.ToString(), context, false);
226+
return SimpleViewHolder.FromText(content?.ToString(), context, fill: false);
227227
}
228228

229229
protected RecyclerView.ViewHolder CreateEmptyViewHolder(object content, DataTemplate template, ViewGroup parent)
@@ -235,7 +235,7 @@ protected RecyclerView.ViewHolder CreateEmptyViewHolder(object content, DataTemp
235235
if (content is not View formsView)
236236
{
237237
// No template, EmptyView is not a Forms View, so just display EmptyView.ToString
238-
return SimpleViewHolder.FromText(content?.ToString(), context);
238+
return SimpleViewHolder.FromText(content?.ToString(), context, () => GetWidth(parent), () => GetHeight(parent), ItemsView);
239239
}
240240

241241
// EmptyView is a Forms View; display that
@@ -319,6 +319,14 @@ void UpdateHeaderFooterHeight(object item, bool isHeader)
319319
size = content.Measure(double.PositiveInfinity, double.PositiveInfinity);
320320
}
321321

322+
if (item is string text)
323+
{
324+
Label label = new Label { Text = text };
325+
TemplateHelpers.GetHandler(label, ItemsView.FindMauiContext());
326+
327+
size = label.Measure(double.PositiveInfinity, double.PositiveInfinity);
328+
}
329+
322330
var itemHeight = size.Height;
323331

324332
if (isHeader)

src/Controls/src/Core/Handlers/Items/Android/SimpleViewHolder.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ public void Recycle(ItemsView itemsView)
2727
itemsView.RemoveLogicalChild(View);
2828
}
2929

30-
public static SimpleViewHolder FromText(string text, Context context, bool fill = true)
30+
public static SimpleViewHolder FromText(string text, Context context, Func<double> width = null, Func<double> height = null, ItemsView container = null, bool fill = true)
3131
{
32-
var textView = new TextView(context) { Text = text };
33-
3432
if (fill)
3533
{
36-
var layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent,
37-
ViewGroup.LayoutParams.MatchParent);
38-
textView.LayoutParameters = layoutParams;
34+
// When displaying an EmptyView with Header and Footer, we need to account for the Header and Footer sizes in layout calculations.
35+
// This prevents the EmptyView from occupying the full remaining space.
36+
Label label = new Label() { Text = text, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
37+
SizedItemContentView itemContentControl = new SizedItemContentView(context, width, height);
38+
itemContentControl.RealizeContent(label, container);
39+
return new SimpleViewHolder(itemContentControl, null);
3940
}
4041

41-
textView.Gravity = GravityFlags.Center;
42-
42+
TextView textView = new TextView(context) { Text = text, Gravity = GravityFlags.Center };
4343
return new SimpleViewHolder(textView, null);
4444
}
4545

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
3+
[Issue(IssueTracker.Github, 28765, "[Android] Inconsistent footer scrolling in CollectionView when EmptyView as string", PlatformAffected.Android)]
4+
public class Issue28765 : TestContentPage
5+
{
6+
override protected void Init()
7+
{
8+
Grid grid = new Grid
9+
{
10+
RowDefinitions =
11+
{
12+
new RowDefinition { Height = GridLength.Star },
13+
new RowDefinition { Height = GridLength.Star }
14+
}
15+
};
16+
17+
CollectionView headerFooterView = new CollectionView
18+
{
19+
EmptyView = "No items to display",
20+
Header = new Label
21+
{
22+
Text = "Header View",
23+
},
24+
Footer = new Label
25+
{
26+
Text = "Footer View"
27+
}
28+
};
29+
30+
CollectionView headerFooterStringView = new CollectionView
31+
{
32+
EmptyView = "No items to display",
33+
Header = "Header String",
34+
Footer = "Footer String"
35+
};
36+
Grid.SetRow(headerFooterStringView, 1);
37+
38+
grid.Children.Add(headerFooterView);
39+
grid.Children.Add(headerFooterStringView);
40+
41+
Content = grid;
42+
}
43+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues;
6+
7+
public class Issue28765 : _IssuesUITest
8+
{
9+
public override string Issue => "[Android] Inconsistent footer scrolling in CollectionView when EmptyView as string";
10+
public Issue28765(TestDevice device) : base(device)
11+
{
12+
}
13+
14+
[Test, Order(1)]
15+
[Category(UITestCategories.CollectionView)]
16+
public void EmptyViewStringWithHeaderAndFooterAsView()
17+
{
18+
App.WaitForElement("Footer View");
19+
}
20+
21+
[Test, Order(2)]
22+
[Category(UITestCategories.CollectionView)]
23+
public void EmptyViewStringWithHeaderAndFooterString()
24+
{
25+
App.WaitForElement("Footer String");
26+
}
27+
}

0 commit comments

Comments
 (0)