Skip to content

Commit 683bde3

Browse files
authored
[iOS/Mac] Fixed the Border Rendering issues in CollectionViewHandler2 (#27801)
* Fixed the Border Rendering issues in CollectionViewHandler2 * Remove the unwanted namspace * Removed UI test and added the device test * Resolved the build errors * Registered the cv2 handler inside the test to avoid other test failures * Added a Assert.NotNull test * Resolved the conflicts
1 parent 567aa26 commit 683bde3

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

src/Controls/tests/DeviceTests/Elements/CollectionView/CollectionViewTests.iOS.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
4+
using System.Linq;
45
using System.Threading.Tasks;
56
using CoreGraphics;
67
using Foundation;
78
using Microsoft.Maui.Controls;
89
using Microsoft.Maui.Controls.Handlers.Items;
10+
using Microsoft.Maui.Controls.Handlers.Items2;
11+
using Microsoft.Maui.Controls.Shapes;
912
using Microsoft.Maui.Graphics;
1013
using Microsoft.Maui.Handlers;
14+
using Microsoft.Maui.Hosting;
1115
using Microsoft.Maui.Platform;
1216
using UIKit;
1317
using Xunit;
@@ -54,6 +58,61 @@ public CollectionViewStringGroup(string header, IEnumerable<string> data) : base
5458
}
5559
}
5660

61+
[Fact]
62+
public async Task CollectionViewItemsArrangeCorrectly()
63+
{
64+
EnsureHandlerCreated(builder =>
65+
{
66+
builder.ConfigureMauiHandlers(handlers =>
67+
{
68+
handlers.AddHandler<CollectionView, CollectionViewHandler2>();
69+
handlers.AddHandler<Border, BorderHandler>();
70+
handlers.AddHandler<Label, LabelHandler>();
71+
});
72+
});
73+
74+
var items = Enumerable.Range(1, 50).Select(i => $"Item {i}").ToArray();
75+
76+
var collectionView = new CollectionView
77+
{
78+
ItemsSource = items,
79+
MaximumHeightRequest = 300,
80+
ItemTemplate = new DataTemplate(() =>
81+
{
82+
var label = new Label
83+
{
84+
HorizontalOptions = LayoutOptions.Center,
85+
VerticalOptions = LayoutOptions.Center,
86+
};
87+
label.SetBinding(Label.TextProperty, ".");
88+
89+
return new Border
90+
{
91+
WidthRequest = 200,
92+
StrokeShape = new RoundRectangle() { CornerRadius = 12 },
93+
Content = label
94+
};
95+
}),
96+
ItemsLayout = new GridItemsLayout(ItemsLayoutOrientation.Horizontal)
97+
{
98+
HorizontalItemSpacing = 50
99+
}
100+
};
101+
102+
await CreateHandlerAndAddToWindow<CollectionViewHandler2>(collectionView, handler =>
103+
{
104+
// Get the first cell's content
105+
var firstCellContent = collectionView.GetVisualTreeDescendants().OfType<Border>().FirstOrDefault();
106+
107+
Assert.NotNull(firstCellContent);
108+
109+
var frame = firstCellContent.Frame;
110+
111+
Assert.True(frame.Width == 200 && frame.Height == 300);
112+
113+
});
114+
}
115+
57116
[Fact]
58117
public async Task CollectionViewContentRespectsMargin()
59118
{

0 commit comments

Comments
 (0)