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 @@ -284,6 +284,12 @@ protected override WSize MeasureOverride(WSize availableSize)
{
if (_renderer == null)
{
// Make sure we supply a real number for sizes otherwise virtualization won't function
if (double.IsFinite(availableSize.Width) && !double.IsFinite(availableSize.Height))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just want to make sure this is ok in CV scenarios where we have horizontal list scrolling set as the layout.

return new WSize(availableSize.Width, 32);
else if (!double.IsFinite(availableSize.Width) && double.IsFinite(availableSize.Height))
return new WSize(88, availableSize.Height);

return base.MeasureOverride(availableSize);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Handlers.Items;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
using Microsoft.UI.Xaml;
using Xunit;
using WSetter = Microsoft.UI.Xaml.Setter;
Expand Down Expand Up @@ -101,6 +102,66 @@ void ValidateItemContainerStyle(CollectionView collectionView)
Assert.Equal(0d, minHeight);
}

[Fact]
public async Task ValidateItemsVirtualize()
{
SetupBuilder();

const int listItemCount = 1000;

var collectionView = new CollectionView()
{
ItemTemplate = new Controls.DataTemplate(() =>
{
var template = new Grid()
{
ColumnDefinitions = new ColumnDefinitionCollection(
[
new ColumnDefinition(25),
new ColumnDefinition(25),
new ColumnDefinition(25),
new ColumnDefinition(25),
new ColumnDefinition(25),
])
};

for (int i = 0; i < 5; i++)
{
var label = new Label();
label.SetBinding(Label.TextProperty, new Binding("Symbol"));
Grid.SetColumn(label, i);
template.Add(label);
}

return template;
}),
ItemsSource = Enumerable.Range(0, listItemCount)
.Select(x => new { Symbol = x })
.ToList()
};

await CreateHandlerAndAddToWindow<CollectionViewHandler>(collectionView, async handler =>
{
var listView = (UI.Xaml.Controls.ListView)collectionView.Handler.PlatformView;

int childCount = 0;
int prevChildCount = -1;

await Task.Delay(2000);

await AssertionExtensions.Wait(() =>
{
// Wait until the list stops growing
prevChildCount = childCount;
childCount = listView.GetChildren<UI.Xaml.Controls.TextBlock>().Count();
return childCount == prevChildCount;
}, 10000);

// If this is broken we'll get way more than 1000 elements
Assert.True(childCount < 1000);
});
}

[Fact]
public async Task ValidateSendRemainingItemsThresholdReached()
{
Expand Down