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 @@ -102,6 +102,7 @@ public override UICollectionReusableView GetViewForSupplementaryElement(UICollec
UpdateDefaultSupplementaryView(DefaultCell2, elementKind, indexPath);
break;
case TemplatedCell2 TemplatedCell2:
TemplatedCell2.ScrollDirection = ScrollDirection;
UpdateTemplatedSupplementaryView(TemplatedCell2, elementKind, indexPath);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public override UICollectionReusableView GetViewForSupplementaryElement(UICollec
UpdateDefaultSupplementaryView(defaultCell, elementKind);
break;
case TemplatedCell2 templatedCell:
templatedCell.ScrollDirection = ScrollDirection;
UpdateTemplatedSupplementaryView(templatedCell, elementKind);
break;
}
Expand Down
50 changes: 50 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue35113.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Collections.ObjectModel;

namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 35113, "CV2 header/footer view width is not expanded to its content width on iOS/macOS", PlatformAffected.iOS | PlatformAffected.macOS)]
public class Issue35113 : ContentPage
{
public Issue35113()
{
var items = new ObservableCollection<string>();
for (int i = 0; i < 2; i++)
items.Add($"Item {i}");

// Header label with no explicit WidthRequest so it must self-size to its content width.
// With the bug: ScrollDirection defaults to Vertical on the supplementary TemplatedCell2.
// GetMeasureConstraints() constrains width to preferredAttributes.Size.Width (~30pt from
// LayoutFactory2's estimated value). The label text is clipped/invisible at 30pt and
// is absent from the accessibility tree — WaitForElement times out.
// With the fix: ScrollDirection = Horizontal is set, width is unconstrained, the label
// expands to its full content width and becomes accessible in the UI tree.
Content = new CollectionView2
{
ItemsLayout = new GridItemsLayout(3, ItemsLayoutOrientation.Horizontal),
Header = new Label
{
Text = "This Is A Header",
AutomationId = "Issue35113Header",
BackgroundColor = Colors.LightBlue,
FontSize = 24,
Padding = new Thickness(8),
},
Footer = new Label
{
Text = "This Is A Footer",
AutomationId = "Issue35113Footer",
BackgroundColor = Colors.LightGreen,
FontSize = 24,
Padding = new Thickness(8),
},
ItemTemplate = new DataTemplate(() =>
{
var label = new Label { Padding = 8 };
label.SetBinding(Label.TextProperty, ".");
return new Border { Content = label, Padding = 4 };
}),
ItemsSource = items,
AutomationId = "Issue35113CollectionView",
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue35113 : _IssuesUITest
{
public override string Issue => "CV2 header/footer view width is not expanded to its content width on iOS/macOS";

public Issue35113(TestDevice device) : base(device) { }

[Test]
[Category(UITestCategories.CollectionView)]
public void HorizontalGridHeaderExpandsToContentWidth()
{
// With the bug: the header's supplementary cell is constrained to ~30pt wide
// (LayoutFactory2 estimated value) because ScrollDirection is never set on
// TemplatedCell2. The header Label "This Is A Header" at FontSize=24 wraps
// into a narrow column — GetRect().Width should be near 30pt.
// With the fix: ScrollDirection is set correctly, the header self-sizes to
// content width — GetRect().Width should be well over 100pt.
App.WaitForElement("Issue35113Header");
var rect = App.FindElement("Issue35113Header").GetRect();
Assert.That(rect.Width, Is.GreaterThan(100),
$"Header width {rect.Width} should be > 100 when fully expanded. " +
"If ~30, ScrollDirection was not set on the supplementary TemplatedCell2.");
}

[Test]
[Category(UITestCategories.CollectionView)]
public void HorizontalGridFooterExpandsToContentWidth()
{
App.WaitForElement("Issue35113CollectionView");
App.ScrollTo("Issue35113Footer");
App.WaitForElement("Issue35113Footer");
var rect = App.FindElement("Issue35113Footer").GetRect();
Comment on lines +35 to +37
Assert.That(rect.Width, Is.GreaterThan(100),
$"Footer width {rect.Width} should be > 100 when fully expanded. " +
"If ~30, ScrollDirection was not set on the supplementary TemplatedCell2.");
}
}
Loading