Skip to content

Commit df738bf

Browse files
kubafloalbyrock87
andauthored
The footer position is not on the far right of the horizontal grid - fix (#28864)
* Update StructuredItemsViewController.cs * Add UI test --------- Co-authored-by: Alberto Aldegheri <albyrock87@gmail.com>
1 parent 360f436 commit df738bf

File tree

5 files changed

+85
-1
lines changed

5 files changed

+85
-1
lines changed

src/Controls/src/Core/Handlers/Items/iOS/StructuredItemsViewController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void UpdateHeaderFooterPosition()
161161

162162
if (_footerUIView != null && IsViewLoaded && View.Window != null)
163163
{
164-
var width = ItemsViewLayout.CollectionViewContentSize.Height;
164+
var width = ItemsViewLayout.CollectionViewContentSize.Width;
165165
var footerX = width + emptyWidth;
166166
var currentFrame = _footerUIView.Frame;
167167

src/Controls/tests/TestCases.HostApp/Elements/CollectionView/HeaderFooterGalleries/HeaderFooterGallery.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public HeaderFooterGallery()
2020
descriptionLabel,
2121
TestBuilder.NavButton("Header/Footer (String)", () => new HeaderFooterString(), Navigation),
2222
TestBuilder.NavButton("Header/Footer (Forms View)", () => new HeaderFooterView(), Navigation),
23+
TestBuilder.NavButton("Header/Footer (Horizontal Forms View)", () => new HeaderFooterViewHorizontal(), Navigation),
2324
TestBuilder.NavButton("Header/Footer (Template)", () => new HeaderFooterTemplate(), Navigation),
2425
TestBuilder.NavButton("Header/Footer (Grid)", () => new HeaderFooterGrid(), Navigation),
2526
TestBuilder.NavButton("Footer Only (String)", () => new FooterOnlyString(), Navigation),
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:d="http://schemas.microsoft.com/dotnet/2021/maui/design"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
mc:Ignorable="d"
7+
x:Class=" Maui.Controls.Sample.CollectionViewGalleries.HeaderFooterGalleries.HeaderFooterViewHorizontal">
8+
<ContentPage.Content>
9+
<Grid ColumnDefinitions="*,*" RowDefinitions="Auto,*">
10+
<Button Text="Add 2 Items" Grid.Row="0" Grid.Column="0" HorizontalOptions="Center"
11+
Command="{Binding AddCommand}" />
12+
<Button Text="Clear All Items" Grid.Row="0" Grid.Column="1" HorizontalOptions="Center"
13+
Command="{Binding ClearCommand}" />
14+
15+
<CollectionView Grid.Row="1" Grid.ColumnSpan="2" x:Name="CollectionView" AutomationId="CV" ItemsSource="{Binding Items}">
16+
<CollectionView.ItemsLayout>
17+
<LinearItemsLayout Orientation="Horizontal" />
18+
</CollectionView.ItemsLayout>
19+
20+
<CollectionView.Header>
21+
<Grid WidthRequest="160">
22+
<Image Source="oasis.jpg" Aspect="AspectFill"></Image>
23+
<Label Text="{Binding HeaderText}" TextColor="AntiqueWhite"
24+
VerticalOptions="Center" LineBreakMode="WordWrap"
25+
HorizontalTextAlignment="Center" Rotation="10"
26+
FontAttributes="Bold" FontSize="20" />
27+
</Grid>
28+
</CollectionView.Header>
29+
30+
<CollectionView.Footer>
31+
<Grid WidthRequest="160">
32+
<Image Source="cover1.jpg" Aspect="AspectFill"></Image>
33+
<Label Text="{Binding FooterText}" TextColor="AntiqueWhite"
34+
HorizontalTextAlignment="Center" Rotation="10"
35+
VerticalOptions="Center" LineBreakMode="WordWrap"
36+
FontAttributes="Bold" FontSize="20" />
37+
</Grid>
38+
</CollectionView.Footer>
39+
40+
</CollectionView>
41+
</Grid>
42+
</ContentPage.Content>
43+
</ContentPage>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Windows.Input;
2+
3+
namespace Maui.Controls.Sample.CollectionViewGalleries.HeaderFooterGalleries
4+
{
5+
public partial class HeaderFooterViewHorizontal : ContentPage
6+
{
7+
readonly HeaderFooterViewModel _viewModel = new HeaderFooterViewModel(10);
8+
9+
public HeaderFooterViewHorizontal()
10+
{
11+
InitializeComponent();
12+
13+
CollectionView.ItemTemplate = ExampleTemplates.PhotoTemplate();
14+
BindingContext = _viewModel;
15+
}
16+
}
17+
}

src/Controls/tests/TestCases.Shared.Tests/Tests/CollectionView/CollectionViewUITests.HeaderAndFooter.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,29 @@ public void HeaderFooterViewWorks()
4343
App.WaitForElement("This Is A Footer");
4444
}
4545

46+
[Test]
47+
[Category(UITestCategories.CollectionView)]
48+
public void HeaderFooterHorizontalViewWorks()
49+
{
50+
// Navigate to the selection galleries
51+
VisitInitialGallery("Header Footer");
52+
53+
// Navigate to the specific sample inside selection galleries
54+
VisitSubGallery("Header/Footer (Horizontal Forms View)");
55+
56+
// Verify the header is visible
57+
App.WaitForElement("This Is A Header");
58+
59+
// Scroll right to ensure the footer is visible and positioned at the end
60+
for (int i = 0; i < 5; i++)
61+
{
62+
App.ScrollRight("CV", ScrollStrategy.Auto, 0.9, 250);
63+
}
64+
65+
// Verify the footer is visible
66+
App.WaitForElement("This Is A Footer");
67+
}
68+
4669
[Test]
4770
[Category(UITestCategories.CollectionView)]
4871
public void HeaderFooterTemplateWorks()

0 commit comments

Comments
 (0)