diff --git a/src/Controls/src/Core/Handlers/Items/Android/ItemContentView.cs b/src/Controls/src/Core/Handlers/Items/Android/ItemContentView.cs index 71f0ff2136fc..580ea95549ba 100644 --- a/src/Controls/src/Core/Handlers/Items/Android/ItemContentView.cs +++ b/src/Controls/src/Core/Handlers/Items/Android/ItemContentView.cs @@ -151,8 +151,6 @@ _pixelSize is not null && { _pixelSize = null; } - - _pixelSize = null; } } diff --git a/src/Controls/src/Core/Handlers/Items/StructuredItemsViewHandler.Android.cs b/src/Controls/src/Core/Handlers/Items/StructuredItemsViewHandler.Android.cs index dcf87f722158..109892b41cb3 100644 --- a/src/Controls/src/Core/Handlers/Items/StructuredItemsViewHandler.Android.cs +++ b/src/Controls/src/Core/Handlers/Items/StructuredItemsViewHandler.Android.cs @@ -21,7 +21,14 @@ public static void MapFooterTemplate(StructuredItemsViewHandler hand } public static void MapItemsLayout(StructuredItemsViewHandler handler, StructuredItemsView itemsView) - => (handler.PlatformView as IMauiRecyclerView)?.UpdateLayoutManager(); + { + if (handler.PlatformView is IMauiRecyclerView recyclerView) + { + recyclerView.UpdateAdapter(); + recyclerView.UpdateScrollingMode(); + recyclerView.UpdateLayoutManager(); + } + } public static void MapItemSizingStrategy(StructuredItemsViewHandler handler, StructuredItemsView itemsView) => (handler.PlatformView as IMauiRecyclerView)?.UpdateAdapter(); diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ShouldMeasureFirstItemInHorizontalLayouts.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ShouldMeasureFirstItemInHorizontalLayouts.png new file mode 100644 index 000000000000..b333188d00c5 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ShouldMeasureFirstItemInHorizontalLayouts.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue29192.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue29192.cs new file mode 100644 index 000000000000..29b091182801 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue29192.cs @@ -0,0 +1,48 @@ +using System.Collections.ObjectModel; + +namespace Maui.Controls.Sample.Issues; +[Issue(IssueTracker.Github, 29192, "[Android] CollectionView MeasureFirstItem ItemSizingStrategy Not Applied in Horizontal Layouts", PlatformAffected.Android)] +public class Issue29192 : ContentPage +{ + public Issue29192() + { + CollectionView collectionView = new CollectionView(); + + var layout = new Grid(); + var bindingContext = new Issue29192ViewModel(); + + collectionView.BindingContext = bindingContext; + collectionView.AutomationId = "CollectionView"; + collectionView.ItemSizingStrategy = ItemSizingStrategy.MeasureFirstItem; + collectionView.ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal); + + collectionView.ItemTemplate = new DataTemplate(() => + { + var label = new Label(); + label.SetBinding(Label.TextProperty, "."); + return label; + }); + + // Set the ItemsSource binding + collectionView.SetBinding(CollectionView.ItemsSourceProperty, "Items"); + layout.Children.Add(collectionView); + + Content = layout; + } +} + + +public class Issue29192ViewModel +{ + public ObservableCollection Items { get; set; } + + public Issue29192ViewModel() + { + Items = new ObservableCollection + { + "Short text.", + "This is a long text; it should be wrapped to avoid truncation or overflow.", + "This is very long text." + }; + } +} diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29192.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29192.cs new file mode 100644 index 000000000000..fdb7a11bd27c --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29192.cs @@ -0,0 +1,22 @@ +#if TEST_FAILS_ON_WINDOWS && TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_IOS // CollectionView MeasureFirstItem sizing not applied on Windows, iOS and macOS) https://github.com/dotnet/maui/issues/29130 +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue29192 : _IssuesUITest +{ + public override string Issue => "[Android] CollectionView MeasureFirstItem ItemSizingStrategy Not Applied in Horizontal Layouts"; + + public Issue29192(TestDevice device) : base(device) { } + + [Test] + [Category(UITestCategories.CollectionView)] + public void ShouldMeasureFirstItemInHorizontalLayouts() + { + App.WaitForElement("CollectionView"); + VerifyScreenshot(); + } +} +#endif \ No newline at end of file