Skip to content

Commit

Permalink
[iOS] Fix for CollectionView single item horizontal alignment issue w…
Browse files Browse the repository at this point in the history
…hen using ItemsLayout with a Footer. (#24564)

* fix added for collectionView single item alignment with footer,

* Test sample changes.

* Modified the automation sample.

* Added automation images.

* Added comments.
  • Loading branch information
Tamilarasan-Paranthaman authored Sep 10, 2024
1 parent 64343f5 commit 7d6c5a9
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Controls/src/Core/Handlers/Items/iOS/GridViewLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ bool NeedsSingleItemHorizontalAlignmentAdjustment(UICollectionViewLayoutAttribut
return false;
}

if (layoutAttributesForRectElements[0].Frame.Top != CollectionView.Frame.Top + CollectionView.ContentInset.Bottom)
// We need to determine whether this 'if' statement is needed, as its relevance is currently uncertain.
if (layoutAttributesForRectElements[0].Frame.Top != CollectionView.Frame.Top)
{
return false;
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue21728.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue21728"
xmlns:ns="clr-namespace:Maui.Controls.Sample.Issues">
<CollectionView x:Name="collectionview" AutomationId="collectionview" ItemsLayout="VerticalGrid, 2">
<CollectionView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding Name}" BackgroundColor="Red" HeightRequest="200" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
</DataTemplate>
</CollectionView.ItemTemplate>
<CollectionView.Footer>
<ContentView >
<ContentView.ControlTemplate>
<ControlTemplate>
<Label Text="CollectionView Footer"/>
</ControlTemplate>
</ContentView.ControlTemplate>
</ContentView>
</CollectionView.Footer>
</CollectionView>
</ContentPage>
26 changes: 26 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue21728.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 21728, "CollectionView item alignment issue when a single item is present with a footer", PlatformAffected.iOS)]
public partial class Issue21728 : ContentPage
{
public IList<TestItem> Items { get; set; }

public Issue21728()
{
InitializeComponent();
BindingContext = this;
Items = new List<TestItem>();
Items.Add(new TestItem() { Name = "Test Item 1" });
collectionview.ItemsSource = Items;
}

public class TestItem
{
public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#if !MACCATALYST
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue21728 : _IssuesUITest
{
public override string Issue => "CollectionView item alignment issue when a single item is present with a footer";

public Issue21728(TestDevice device)
: base(device)
{ }

[Test]
[Category(UITestCategories.CollectionView)]
public void CollectionViewSingleItemAlignmentWithFooter()
{
App.WaitForElement("collectionview");

VerifyScreenshot();
}
}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7d6c5a9

Please sign in to comment.