Skip to content

Commit

Permalink
[Android] Fixed CollectionView MeasureFirstItem Rendering issue (dotn…
Browse files Browse the repository at this point in the history
…et#25367)

* Fixed-25191 : CollectionView ItemSizingStrategy:MeasureFirstItem renders labels incorrectly.

* added windows snapshot.
  • Loading branch information
Vignesh-SF3580 authored Oct 22, 2024
1 parent ea0e7bb commit c21b518
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,12 @@ _pixelSize is not null &&
// Even though we already know the size we still need to pass the measure through to the children.
if (_pixelSize is not null)
{
var w = (int)this.FromPixels(_pixelSize.Value.Width);
var h = (int)this.FromPixels(_pixelSize.Value.Height);

// If the platform childs measure has been invalidated, it's going to still want to
// participate in the measure lifecycle in order to update its internal
// book keeping.
_ = (View.Handler as IPlatformViewHandler)?.MeasureVirtualView(
MeasureSpec.MakeMeasureSpec(w, MeasureSpecMode.Exactly),
MeasureSpec.MakeMeasureSpec(h, MeasureSpecMode.Exactly)
MeasureSpec.MakeMeasureSpec((int)_pixelSize.Value.Width, MeasureSpecMode.Exactly),
MeasureSpec.MakeMeasureSpec((int)_pixelSize.Value.Height, MeasureSpecMode.Exactly)
);

SetMeasuredDimension((int)_pixelSize.Value.Width, (int)_pixelSize.Value.Height);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25191.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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="Maui.Controls.Sample.Issues.Issue25191">

<Grid RowDefinitions="50,*" x:Name="grid">

<CollectionView Grid.Row="2" x:Name="collectionView"
ItemSizingStrategy="MeasureFirstItem"
ItemsSource="{Binding Items}"
AutomationId="collectionView">
<CollectionView.EmptyView>
<Label HorizontalOptions="Center"
Text="Test Label"
VerticalOptions="Center" />
</CollectionView.EmptyView>
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="{x:Null}">
<Border Margin="0,5"
BackgroundColor="White"
HeightRequest="140"
StrokeShape="RoundRectangle 8"
StrokeThickness="0">
<Grid Margin="10,8"
ColumnDefinitions="80,*,0.5*,*"
ColumnSpacing="0"
RowDefinitions="18,8,*,*,*"
RowSpacing="0">

<Label Margin="5,0,0,0"
FontSize="10"
Text="Header Label"
TextColor="DimGray" />

<Label Grid.Row="0"
Grid.Column="3"
FontSize="10"
HorizontalOptions="End"
LineBreakMode="WordWrap"
Text="Top Right Text Here"
TextColor="DimGray" />

<Border Grid.Row="2"
Grid.RowSpan="3"
BackgroundColor="Red"
StrokeShape="RoundRectangle 10" />

<Button Grid.Row="2"
Grid.Column="1"
Grid.ColumnSpan="3"
Margin="8,0,0,0"
FontSize="14"
Text="Test Button"
VerticalOptions="Center" />

<Label Grid.Row="3"
Grid.Column="1"
Grid.ColumnSpan="3"
Margin="8,0,0,0"
FontSize="10"
Text="Middle Text Here"
TextColor="Gray"
VerticalOptions="Center" />

<Label Grid.Row="4" x:Name="label"
Grid.Column="3"
FontSize="12"
HorizontalOptions="End"
LineBreakMode="NoWrap"
Text="Footer Label"
TextColor="Black"
VerticalOptions="Center" />
</Grid>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>

</Grid>

</ContentPage>
25 changes: 25 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25191.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.ObjectModel;

namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 25191, "CollectionView ItemSizingStrategy:MeasureFirstItem renders labels incorrectly", PlatformAffected.Android)]
public partial class Issue25191 : ContentPage
{
public Issue25191()
{
InitializeComponent();
BindingContext = new MainViewModel();
}
}

public class MainViewModel
{
public ObservableCollection<string> Items { get; set; } = new ObservableCollection<string>
{
"Item 1",
"Item 2",
"Item 3",
"Item 4"
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#if !MACCATALYST
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue25191 : _IssuesUITest
{
public Issue25191(TestDevice device) : base(device)
{
}

public override string Issue => "CollectionView ItemSizingStrategy:MeasureFirstItem renders labels incorrectly";

[Test]
[Category(UITestCategories.CollectionView)]
public void CollectionViewMeasureFirstItem()
{
App.WaitForElement("collectionView");
VerifyScreenshot();
}
}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c21b518

Please sign in to comment.