Skip to content

Commit

Permalink
[tests] Add test for issue 20443
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarinho committed Oct 18, 2024
1 parent 87303ab commit c9c70a8
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue20443.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Controls.TestCases.HostApp.Issues.Issue20443"
xmlns:local="clr-namespace:Controls.TestCases.HostApp.Issues"
x:DataType="local:Issue20443ViewModel"
Title="Issue20443">
<ContentPage.BindingContext>
<local:Issue20443ViewModel/>
</ContentPage.BindingContext>
<Grid>
<RefreshView
IsRefreshing="{Binding IsRefreshing}"
Command="{Binding RefreshCommand}">
<CollectionView
ItemSizingStrategy="MeasureAllItems"
ItemsSource="{Binding Items}">
<CollectionView.ItemTemplate>
<local:Issue20443TemplateSelector>
<local:Issue20443TemplateSelector.ItemATemplate>
<DataTemplate>
<Grid
HeightRequest="20"
BackgroundColor="Aqua">
<Label Text="20"/>
</Grid>
</DataTemplate>
</local:Issue20443TemplateSelector.ItemATemplate>
<local:Issue20443TemplateSelector.ItemBTemplate>
<DataTemplate>
<Grid
HeightRequest="100"
BackgroundColor="Pink">
<Label Text="100"/>
</Grid>
</DataTemplate>
</local:Issue20443TemplateSelector.ItemBTemplate>
</local:Issue20443TemplateSelector>
</CollectionView.ItemTemplate>

</CollectionView>
</RefreshView>
</Grid>
</ContentPage>
90 changes: 90 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue20443.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;
using System.Runtime.CompilerServices;

namespace Controls.TestCases.HostApp.Issues
{
[Issue(IssueTracker.Github, 20443, "CollectionView item gets wrong size after refresh", PlatformAffected.iOS)]

public partial class Issue20443 : ContentPage
{
public Issue20443()
{
InitializeComponent();
}
}
public class Issue20443ViewModel : INotifyPropertyChanged
{
public IList<object> Items { get; set; }

private bool _isRefreshing;

public bool IsRefreshing
{
get => _isRefreshing;
set
{
_isRefreshing = value;
OnPropertyChanged();
}
}

public Command RefreshCommand { get; set; }

public Issue20443ViewModel()
{
RefreshCommand = new Command(
async () =>
{
await Task.Delay(2000);
IsRefreshing = false;
});

Items = new List<object>();
for (int i = 0; i < 100; i++)
{
Items.Add(new Issue20443ItemA());
Items.Add(new Issue20443ItemB());
Items.Add(new Issue20443ItemB());
Items.Add(new Issue20443ItemB());
Items.Add(new Issue20443ItemB());
}
}

public event PropertyChangedEventHandler PropertyChanged;

protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}

public class Issue20443ItemA
{

}

public class Issue20443ItemB
{

}

public class Issue20443TemplateSelector : DataTemplateSelector
{
public DataTemplate ItemATemplate { get; set; }
public DataTemplate ItemBTemplate { get; set; }

protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
if (item is Issue20443ItemA)
{
return ItemATemplate;
}

return ItemBTemplate;
}
}
}

0 comments on commit c9c70a8

Please sign in to comment.