From c6e32c9237a0b82c641560fb6bac3dca683e27f1 Mon Sep 17 00:00:00 2001 From: Ahamed-Ali <102580874+Ahamed-Ali@users.noreply.github.com> Date: Fri, 14 Feb 2025 20:41:47 +0530 Subject: [PATCH 1/7] Fixed the Border Rendering issues in CollectionViewHandler2 --- .../TestCases.HostApp/Issues/Issue27608.xaml | 41 +++++++++++++++++++ .../Issues/Issue27608.xaml.cs | 15 +++++++ .../Tests/Issues/Issue27608.cs | 24 +++++++++++ 3 files changed, 80 insertions(+) create mode 100644 src/Controls/tests/TestCases.HostApp/Issues/Issue27608.xaml create mode 100644 src/Controls/tests/TestCases.HostApp/Issues/Issue27608.xaml.cs create mode 100644 src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27608.cs diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue27608.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue27608.xaml new file mode 100644 index 0000000000000..387883a9650fb --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue27608.xaml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue27608.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue27608.xaml.cs new file mode 100644 index 0000000000000..5bba4d1015a9c --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue27608.xaml.cs @@ -0,0 +1,15 @@ +namespace Maui.Controls.Sample.Issues +{ + [Issue(IssueTracker.Github, 27608, "Items shapes are sometimes rendered incorrectly using CollectionView2Handler", PlatformAffected.iOS)] + public partial class Issue27608 : ContentPage + { + public Issue27608() + { + InitializeComponent(); + const int count = 50; + Items = Enumerable.Range(1, count).ToList(); + BindingContext = this; + } + public List Items { get; } + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27608.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27608.cs new file mode 100644 index 0000000000000..6c5b76c8aa8dd --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27608.cs @@ -0,0 +1,24 @@ +using System.Threading; +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues +{ + public class Issue27608 : _IssuesUITest + { + public Issue27608(TestDevice device) : base(device) { } + + public override string Issue => "Items shapes are sometimes rendered incorrectly using CollectionView2Handler"; + + [Test] + [Category(UITestCategories.CollectionView)] + public void CollectionViewBorderItemsShouldRenderCorrectly() + { + App.WaitForElement("CollectionView"); + App.ScrollRight("CollectionView", swipePercentage: 0.99); + Thread.Sleep(1000); + VerifyScreenshot(); + } + } +} \ No newline at end of file From 9a00d41c0b693362bf5b65232576125ee4074581 Mon Sep 17 00:00:00 2001 From: Ahamed-Ali <102580874+Ahamed-Ali@users.noreply.github.com> Date: Fri, 14 Feb 2025 21:07:55 +0530 Subject: [PATCH 2/7] Remove the unwanted namspace --- .../tests/TestCases.Shared.Tests/Tests/Issues/Issue27608.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27608.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27608.cs index 6c5b76c8aa8dd..eb8f077b43d11 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27608.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27608.cs @@ -1,4 +1,3 @@ -using System.Threading; using NUnit.Framework; using UITest.Appium; using UITest.Core; From c28174da3e3e80d3ba1f480b7753f7c263b656e9 Mon Sep 17 00:00:00 2001 From: Ahamed-Ali <102580874+Ahamed-Ali@users.noreply.github.com> Date: Mon, 17 Feb 2025 12:54:28 +0530 Subject: [PATCH 3/7] Removed UI test and added the device test --- .../CollectionView/CollectionViewTests.cs | 3 ++ .../CollectionView/CollectionViewTests.iOS.cs | 48 +++++++++++++++++++ .../TestCases.HostApp/Issues/Issue27608.xaml | 41 ---------------- .../Issues/Issue27608.xaml.cs | 15 ------ .../Tests/Issues/Issue27608.cs | 23 --------- 5 files changed, 51 insertions(+), 79 deletions(-) delete mode 100644 src/Controls/tests/TestCases.HostApp/Issues/Issue27608.xaml delete mode 100644 src/Controls/tests/TestCases.HostApp/Issues/Issue27608.xaml.cs delete mode 100644 src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27608.cs diff --git a/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.cs b/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.cs index a4d646438d679..473a12c236fb8 100644 --- a/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.cs @@ -10,6 +10,7 @@ using Microsoft.Maui.Controls; using Microsoft.Maui.Controls.Handlers.Compatibility; using Microsoft.Maui.Controls.Handlers.Items; +using Microsoft.Maui.Controls.Handlers.Items2; using Microsoft.Maui.Controls.Platform; using Microsoft.Maui.DeviceTests.Stubs; using Microsoft.Maui.Graphics; @@ -44,8 +45,10 @@ void SetupBuilder() handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); + handlers.AddHandler(); #if IOS || MACCATALYST handlers.AddHandler(typeof(NavigationPage), typeof(NavigationRenderer)); + handlers.AddHandler(); #else handlers.AddHandler(typeof(NavigationPage), typeof(NavigationViewHandler)); #endif diff --git a/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.iOS.cs index 8aec647b47370..ba11be03a4598 100644 --- a/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.iOS.cs @@ -1,11 +1,14 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Linq; using System.Threading.Tasks; using CoreGraphics; using Foundation; using Microsoft.Maui.Controls; using Microsoft.Maui.Controls.Handlers.Items; +using Microsoft.Maui.Controls.Handlers.Items2; +using Microsoft.Maui.Controls.Shapes; using Microsoft.Maui.Graphics; using Microsoft.Maui.Handlers; using Microsoft.Maui.Platform; @@ -54,6 +57,51 @@ public CollectionViewStringGroup(string header, IEnumerable data) : base } } + [Fact] + public async Task CollectionViewItemsArrangeCorrectly() + { + SetupBuilder(); + + var items = Enumerable.Range(1, 50).Select(i => $"Item {i}").ToArray(); + + var collectionView = new CollectionView + { + ItemsSource = items, + MaximumHeightRequest = 300, + ItemTemplate = new DataTemplate(() => + { + var label = new Label + { + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center, + }; + label.SetBinding(Label.TextProperty, "."); + + return new Border + { + WidthRequest = 200, + StrokeShape = new RoundRectangle() { CornerRadius = 12 }, + Content = label + }; + }), + ItemsLayout = new GridItemsLayout(ItemsLayoutOrientation.Horizontal) + { + HorizontalItemSpacing = 50 + } + }; + + await CreateHandlerAndAddToWindow(collectionView, handler => + { + // Get the first cell's content + var firstCellContent = collectionView.GetVisualTreeDescendants().OfType().FirstOrDefault(); + + var frame = firstCellContent.Frame; + + Assert.True(frame.Width == 200 && frame.Height == 300); + + }); + } + [Fact] public async Task CollectionViewContentRespectsMargin() { diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue27608.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue27608.xaml deleted file mode 100644 index 387883a9650fb..0000000000000 --- a/src/Controls/tests/TestCases.HostApp/Issues/Issue27608.xaml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue27608.xaml.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue27608.xaml.cs deleted file mode 100644 index 5bba4d1015a9c..0000000000000 --- a/src/Controls/tests/TestCases.HostApp/Issues/Issue27608.xaml.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Maui.Controls.Sample.Issues -{ - [Issue(IssueTracker.Github, 27608, "Items shapes are sometimes rendered incorrectly using CollectionView2Handler", PlatformAffected.iOS)] - public partial class Issue27608 : ContentPage - { - public Issue27608() - { - InitializeComponent(); - const int count = 50; - Items = Enumerable.Range(1, count).ToList(); - BindingContext = this; - } - public List Items { get; } - } -} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27608.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27608.cs deleted file mode 100644 index eb8f077b43d11..0000000000000 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27608.cs +++ /dev/null @@ -1,23 +0,0 @@ -using NUnit.Framework; -using UITest.Appium; -using UITest.Core; - -namespace Microsoft.Maui.TestCases.Tests.Issues -{ - public class Issue27608 : _IssuesUITest - { - public Issue27608(TestDevice device) : base(device) { } - - public override string Issue => "Items shapes are sometimes rendered incorrectly using CollectionView2Handler"; - - [Test] - [Category(UITestCategories.CollectionView)] - public void CollectionViewBorderItemsShouldRenderCorrectly() - { - App.WaitForElement("CollectionView"); - App.ScrollRight("CollectionView", swipePercentage: 0.99); - Thread.Sleep(1000); - VerifyScreenshot(); - } - } -} \ No newline at end of file From 143842b92c31e2e8c7f0b7deb328c7fe88532e67 Mon Sep 17 00:00:00 2001 From: Ahamed-Ali <102580874+Ahamed-Ali@users.noreply.github.com> Date: Mon, 17 Feb 2025 17:01:11 +0530 Subject: [PATCH 4/7] Resolved the build errors --- .../DeviceTests/Elements/CollectionView/CollectionViewTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.cs b/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.cs index 473a12c236fb8..8dc9b1f61a6ba 100644 --- a/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.cs @@ -10,7 +10,9 @@ using Microsoft.Maui.Controls; using Microsoft.Maui.Controls.Handlers.Compatibility; using Microsoft.Maui.Controls.Handlers.Items; +#if IOS || MACCATALYST using Microsoft.Maui.Controls.Handlers.Items2; +#endif using Microsoft.Maui.Controls.Platform; using Microsoft.Maui.DeviceTests.Stubs; using Microsoft.Maui.Graphics; From a3e272d61fd081be981557330729b28f1cae5216 Mon Sep 17 00:00:00 2001 From: Ahamed-Ali <102580874+Ahamed-Ali@users.noreply.github.com> Date: Mon, 17 Feb 2025 18:53:57 +0530 Subject: [PATCH 5/7] Registered the cv2 handler inside the test to avoid other test failures --- .../Elements/CollectionView/CollectionViewTests.cs | 5 ----- .../Elements/CollectionView/CollectionViewTests.iOS.cs | 10 +++++++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.cs b/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.cs index 8dc9b1f61a6ba..a4d646438d679 100644 --- a/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.cs @@ -10,9 +10,6 @@ using Microsoft.Maui.Controls; using Microsoft.Maui.Controls.Handlers.Compatibility; using Microsoft.Maui.Controls.Handlers.Items; -#if IOS || MACCATALYST -using Microsoft.Maui.Controls.Handlers.Items2; -#endif using Microsoft.Maui.Controls.Platform; using Microsoft.Maui.DeviceTests.Stubs; using Microsoft.Maui.Graphics; @@ -47,10 +44,8 @@ void SetupBuilder() handlers.AddHandler(); handlers.AddHandler(); handlers.AddHandler(); - handlers.AddHandler(); #if IOS || MACCATALYST handlers.AddHandler(typeof(NavigationPage), typeof(NavigationRenderer)); - handlers.AddHandler(); #else handlers.AddHandler(typeof(NavigationPage), typeof(NavigationViewHandler)); #endif diff --git a/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.iOS.cs index ba11be03a4598..bf7e0da84e3d9 100644 --- a/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.iOS.cs @@ -60,7 +60,15 @@ public CollectionViewStringGroup(string header, IEnumerable data) : base [Fact] public async Task CollectionViewItemsArrangeCorrectly() { - SetupBuilder(); + EnsureHandlerCreated(builder => + { + builder.ConfigureMauiHandlers(handlers => + { + handlers.AddHandler(); + handlers.AddHandler(); + handlers.AddHandler(); + }); + }); var items = Enumerable.Range(1, 50).Select(i => $"Item {i}").ToArray(); From ace61ac6f417a2867043480d1e40d333b3e7ece2 Mon Sep 17 00:00:00 2001 From: Ahamed-Ali <102580874+Ahamed-Ali@users.noreply.github.com> Date: Fri, 28 Mar 2025 11:30:41 +0530 Subject: [PATCH 6/7] Added a Assert.NotNull test --- .../Elements/CollectionView/CollectionViewTests.iOS.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.iOS.cs index bf7e0da84e3d9..3fe687f6f1330 100644 --- a/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.iOS.cs @@ -103,6 +103,8 @@ await CreateHandlerAndAddToWindow(collectionView, handle // Get the first cell's content var firstCellContent = collectionView.GetVisualTreeDescendants().OfType().FirstOrDefault(); + Assert.NotNull(firstCellContent); + var frame = firstCellContent.Frame; Assert.True(frame.Width == 200 && frame.Height == 300); From 2e1646320a0aa1985cd1af699c3bff46a4034b37 Mon Sep 17 00:00:00 2001 From: Ahamed-Ali <102580874+Ahamed-Ali@users.noreply.github.com> Date: Wed, 14 May 2025 11:36:12 +0530 Subject: [PATCH 7/7] Resolved the conflicts --- .../Elements/CollectionView/CollectionViewTests.iOS.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.iOS.cs index 3fe687f6f1330..21f88c6c9ceeb 100644 --- a/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.iOS.cs +++ b/src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.iOS.cs @@ -11,6 +11,7 @@ using Microsoft.Maui.Controls.Shapes; using Microsoft.Maui.Graphics; using Microsoft.Maui.Handlers; +using Microsoft.Maui.Hosting; using Microsoft.Maui.Platform; using UIKit; using Xunit;