|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Collections.ObjectModel; |
| 4 | +using System.Linq; |
4 | 5 | using System.Threading.Tasks; |
5 | 6 | using CoreGraphics; |
6 | 7 | using Foundation; |
7 | 8 | using Microsoft.Maui.Controls; |
8 | 9 | using Microsoft.Maui.Controls.Handlers.Items; |
| 10 | +using Microsoft.Maui.Controls.Handlers.Items2; |
| 11 | +using Microsoft.Maui.Controls.Shapes; |
9 | 12 | using Microsoft.Maui.Graphics; |
10 | 13 | using Microsoft.Maui.Handlers; |
| 14 | +using Microsoft.Maui.Hosting; |
11 | 15 | using Microsoft.Maui.Platform; |
12 | 16 | using UIKit; |
13 | 17 | using Xunit; |
@@ -54,6 +58,61 @@ public CollectionViewStringGroup(string header, IEnumerable<string> data) : base |
54 | 58 | } |
55 | 59 | } |
56 | 60 |
|
| 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 | + |
57 | 116 | [Fact] |
58 | 117 | public async Task CollectionViewContentRespectsMargin() |
59 | 118 | { |
|
0 commit comments