Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit e68d13a

Browse files
Fixed wrong groups CollectionView header size (#8563) fixes #8557
Co-authored-by: Samantha Houts <[email protected]>
1 parent ea2411e commit e68d13a

File tree

4 files changed

+166
-2
lines changed

4 files changed

+166
-2
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<controls:TestContentPage
3+
xmlns="http://xamarin.com/schemas/2014/forms"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
5+
xmlns:controls="clr-namespace:Xamarin.Forms.Controls"
6+
x:Class="Xamarin.Forms.Controls.Issues.Issue8557">
7+
<CollectionView
8+
ItemsSource="{Binding GroupContent}"
9+
IsGrouped="True"
10+
ItemSizingStrategy="{OnPlatform Android=MeasureAllItems, iOS=MeasureFirstItem}">
11+
<CollectionView.GroupHeaderTemplate>
12+
<DataTemplate>
13+
<Grid
14+
ColumnSpacing="0"
15+
Margin="0,30"
16+
BackgroundColor="Yellow">
17+
<Grid.ColumnDefinitions>
18+
<ColumnDefinition Width="*" />
19+
<ColumnDefinition Width="120" />
20+
<ColumnDefinition Width="*" />
21+
</Grid.ColumnDefinitions>
22+
<BoxView
23+
Grid.Column="0"
24+
VerticalOptions="Center"
25+
HeightRequest="1"
26+
BackgroundColor="Gray"/>
27+
<Label
28+
Grid.Column="1"
29+
Text="{Binding Name}"
30+
HorizontalTextAlignment="Center"
31+
VerticalTextAlignment="Center"
32+
FontSize="26"/>
33+
<BoxView
34+
Grid.Column="2"
35+
VerticalOptions="Center"
36+
HeightRequest="1"
37+
BackgroundColor="Gray"/>
38+
</Grid>
39+
</DataTemplate>
40+
</CollectionView.GroupHeaderTemplate>
41+
<CollectionView.ItemsLayout>
42+
<GridItemsLayout
43+
Orientation="Vertical"
44+
Span="2"/>
45+
</CollectionView.ItemsLayout>
46+
<CollectionView.ItemTemplate>
47+
<DataTemplate>
48+
<Frame
49+
HasShadow="false"
50+
Padding="0">
51+
<Label
52+
Text="{Binding Description}"
53+
HorizontalTextAlignment="Center"
54+
VerticalTextAlignment="Center"
55+
HeightRequest="100"/>
56+
</Frame>
57+
</DataTemplate>
58+
</CollectionView.ItemTemplate>
59+
</CollectionView>
60+
</controls:TestContentPage>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using Xamarin.Forms.CustomAttributes;
2+
using Xamarin.Forms.Internals;
3+
using Xamarin.Forms.Xaml;
4+
using System.Collections.Generic;
5+
6+
#if UITEST
7+
using Xamarin.UITest;
8+
using Xamarin.UITest.Queries;
9+
using NUnit.Framework;
10+
using Xamarin.Forms.Core.UITests;
11+
using System.Linq;
12+
#endif
13+
14+
namespace Xamarin.Forms.Controls.Issues
15+
{
16+
#if UITEST
17+
[NUnit.Framework.Category(UITestCategories.CollectionView)]
18+
#endif
19+
#if APP
20+
[XamlCompilation(XamlCompilationOptions.Compile)]
21+
#endif
22+
[Preserve(AllMembers = true)]
23+
[Issue(IssueTracker.Github, 8557, "[Bug] Grouped header with incorrect size when use GridItemsLayout with two columns on the CollectionView", PlatformAffected.iOS)]
24+
public partial class Issue8557 : TestContentPage
25+
{
26+
#if APP
27+
public Issue8557()
28+
{
29+
InitializeComponent();
30+
31+
BindingContext = new Issue8557ViewModel();
32+
}
33+
#endif
34+
35+
protected override void Init()
36+
{
37+
38+
}
39+
}
40+
41+
[Preserve(AllMembers = true)]
42+
public class Issue8557Model
43+
{
44+
public string Description { get; set; }
45+
}
46+
47+
[Preserve(AllMembers = true)]
48+
public class Issue8557GroupModel : List<Issue8557Model>
49+
{
50+
public string Name { get; set; }
51+
52+
public Issue8557GroupModel(string name, List<Issue8557Model> data) : base(data)
53+
{
54+
Name = name;
55+
}
56+
}
57+
58+
[Preserve(AllMembers = true)]
59+
public class Issue8557ViewModel
60+
{
61+
public List<Issue8557GroupModel> GroupContent { get; private set; }
62+
63+
public Issue8557ViewModel()
64+
{
65+
GroupContent = new List<Issue8557GroupModel>
66+
{
67+
new Issue8557GroupModel(
68+
"Group 1",
69+
new List<Issue8557Model>
70+
{
71+
new Issue8557Model { Description = "Description 1.1" },
72+
new Issue8557Model { Description = "Description 1.2" },
73+
new Issue8557Model { Description = "Description 1.3" },
74+
new Issue8557Model { Description = "Description 1.4" }
75+
}
76+
),
77+
new Issue8557GroupModel(
78+
"Group 2",
79+
new List<Issue8557Model>
80+
{
81+
new Issue8557Model { Description = "Description 2.1" },
82+
new Issue8557Model { Description = "Description 2.2" },
83+
new Issue8557Model { Description = "Description 2.3" },
84+
new Issue8557Model { Description = "Description 2.4" }
85+
}
86+
)
87+
};
88+
}
89+
}
90+
}

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,7 @@
12381238
<Compile Include="$(MSBuildThisFileDirectory)Issue8417.xaml.cs" />
12391239
<Compile Include="$(MSBuildThisFileDirectory)Issue8647.cs" />
12401240
<Compile Include="$(MSBuildThisFileDirectory)Issue7510.cs" />
1241+
<Compile Include="$(MSBuildThisFileDirectory)Issue8557.xaml.cs" />
12411242
<Compile Include="$(MSBuildThisFileDirectory)Issue8753.cs" />
12421243
<Compile Include="$(MSBuildThisFileDirectory)Issue8693.cs" />
12431244
<Compile Include="$(MSBuildThisFileDirectory)Issue7813.xaml.cs" />
@@ -1397,6 +1398,7 @@
13971398
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
13981399
</EmbeddedResource>
13991400
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue8417.xaml" />
1401+
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue8557.xaml" />
14001402
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue7813.xaml" />
14011403
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue8638.xaml" />
14021404
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue8779.xaml" />

Xamarin.Forms.Platform.iOS/CollectionView/GroupableItemsViewController.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void UpdateDefaultSupplementaryView(DefaultCell cell, NSString elementKind, NSIn
8888

8989
if (cell is ItemsViewCell)
9090
{
91-
cell.ConstrainTo(ItemsViewLayout.ConstrainedDimension);
91+
cell.ConstrainTo(GetLayoutSpanCount() * ItemsViewLayout.ConstrainedDimension);
9292
}
9393
}
9494

@@ -104,7 +104,7 @@ void UpdateTemplatedSupplementaryView(TemplatedCell cell, NSString elementKind,
104104

105105
if (cell is ItemsViewCell)
106106
{
107-
cell.ConstrainTo(ItemsViewLayout.ConstrainedDimension);
107+
cell.ConstrainTo(GetLayoutSpanCount() * ItemsViewLayout.ConstrainedDimension);
108108
}
109109
}
110110

@@ -172,6 +172,18 @@ internal void HandleScrollAnimationEnded()
172172
_scrollAnimationEndedCallback = null;
173173
}
174174

175+
int GetLayoutSpanCount()
176+
{
177+
var span = 1;
178+
179+
if (ItemsView?.ItemsLayout is GridItemsLayout gridItemsLayout)
180+
{
181+
span = gridItemsLayout.Span;
182+
}
183+
184+
return span;
185+
}
186+
175187
internal UIEdgeInsets GetInsetForSection(ItemsViewLayout itemsViewLayout,
176188
UICollectionView collectionView, nint section)
177189
{

0 commit comments

Comments
 (0)