Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the Header and Footer-Name textbox is cut off in collection view #26947

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,21 @@ protected override CGRect DetermineEmptyViewFrame()
public override void ViewWillLayoutSubviews()
{
base.ViewWillLayoutSubviews();
// This updates the positions of the header view and footer view as their sizes change dynamically
var emptyView = CollectionView.ViewWithTag(EmptyTag);

// This update is only relevant if you have a footer view because it's used to place the footer view
// based on the ContentSize so we just update the positions if the ContentSize has changed
if (_footerUIView != null)
if (IsHorizontal)
{
var emptyView = CollectionView.ViewWithTag(EmptyTag);

if (IsHorizontal)
if ((_headerUIView is not null && (_headerUIView.Frame.X != ItemsViewLayout.CollectionViewContentSize.Width || _headerUIView.Frame.X < emptyView?.Frame.X)) || (_footerUIView is not null && (_footerUIView.Frame.X != ItemsViewLayout.CollectionViewContentSize.Width || _footerUIView.Frame.X != _footerUIView.Frame.Width || _footerUIView.Frame.X < emptyView?.Frame.X)))
{
if (_footerUIView.Frame.X != ItemsViewLayout.CollectionViewContentSize.Width ||
_footerUIView.Frame.X < emptyView?.Frame.X)
UpdateHeaderFooterPosition();
UpdateHeaderFooterPosition();
}
else
}
else
{
if ((_headerUIView is not null && (_headerUIView.Frame.Y != ItemsViewLayout.CollectionViewContentSize.Height || _headerUIView.Frame.Y < (emptyView?.Frame.Y + emptyView?.Frame.Height))) || (_footerUIView is not null && (_footerUIView.Frame.Y != ItemsViewLayout.CollectionViewContentSize.Height || _footerUIView.Frame.Y != _footerUIView.Frame.Height || _footerUIView.Frame.Y < (emptyView?.Frame.Y + emptyView?.Frame.Height))))
{
if (_footerUIView.Frame.Y != ItemsViewLayout.CollectionViewContentSize.Height ||
_footerUIView.Frame.Y < (emptyView?.Frame.Y + emptyView?.Frame.Height))
UpdateHeaderFooterPosition();
UpdateHeaderFooterPosition();
}
}
}
Expand Down Expand Up @@ -209,7 +206,9 @@ void UpdateHeaderFooterPosition()
_headerUIView.Frame = new CoreGraphics.CGRect(-headerWidth, 0, headerWidth, CollectionView.Frame.Height);
}

if (_footerUIView != null && (_footerUIView.Frame.X != ItemsViewLayout.CollectionViewContentSize.Width || emptyWidth > 0))
// The FooterView frame is updated when the CollectionView does not contain any items.
// Previously, the FooterView frame was updated only for a CollectionView with an ItemSource.
if (_footerUIView != null && (_footerUIView.Frame.X != ItemsViewLayout.CollectionViewContentSize.Width || _footerUIView.Frame.X != footerWidth || emptyWidth > 0))
_footerUIView.Frame = new CoreGraphics.CGRect(ItemsViewLayout.CollectionViewContentSize.Width + emptyWidth, 0, footerWidth, CollectionView.Frame.Height);

if (CollectionView.ContentInset.Left != headerWidth || CollectionView.ContentInset.Right != footerWidth)
Expand Down Expand Up @@ -262,7 +261,9 @@ void UpdateHeaderFooterPosition()
height = ItemsViewLayout.CollectionViewContentSize.Height;
}

if (_footerUIView != null && (_footerUIView.Frame.Y != height || emptyHeight > 0))
// The FooterView frame is updated when the CollectionView does not contain any items.
// Previously, the FooterView frame was updated only for a CollectionView with an ItemSource.
if (_footerUIView != null && (_footerUIView.Frame.Y != height || _footerUIView.Frame.Y != footerHeight || emptyHeight > 0))
{
_footerUIView.Frame = new CoreGraphics.CGRect(0, height + emptyHeight, CollectionView.Frame.Width, footerHeight);
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue26186.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?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.Issue26186"
xmlns:cv1="clr-namespace:Maui.Controls.Sample"
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"
Title="Issue26186">
<Grid RowDefinitions="Auto, *">
<Button Grid.Row="0"
Clicked="Button_Clicked"
AutomationId="Button"
Text="Update width for CollectionView"/>
<cv1:CollectionView1 x:Name="collectionView"
AutomationId="CollectionView"
Grid.Row="1">
<cv1:CollectionView1.Header>
<Grid RowSpacing="10"
ColumnSpacing="10">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0"
Grid.Column="0"
Text="Name:"
VerticalTextAlignment="Center"/>
<Entry Grid.Row="0"
Grid.Column="1"/>
<Label Grid.Row="1"
Grid.Column="0"
Text="Faction:"
VerticalTextAlignment="Center"/>
<Picker Grid.Row="1"
Grid.Column="1">
<Picker.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Baboon</x:String>
<x:String>Capuchin Monkey</x:String>
<x:String>Blue Monkey</x:String>
<x:String>Squirrel Monkey</x:String>
<x:String>Golden Lion Tamarin</x:String>
<x:String>Howler Monkey</x:String>
<x:String>Japanese Macaque</x:String>
</x:Array>
</Picker.ItemsSource>
</Picker>
</Grid>
</cv1:CollectionView1.Header>
<cv1:CollectionView1.Footer>
<Grid RowSpacing="10"
ColumnSpacing="10">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0"
Grid.Column="0"
Text="Name:"
VerticalTextAlignment="Center"/>
<Entry Grid.Row="0"
Grid.Column="1"/>
<Label Grid.Row="1"
Grid.Column="0"
Text="Faction:"
VerticalTextAlignment="Center"/>
<Picker Grid.Row="1"
Grid.Column="1">
<Picker.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Baboon</x:String>
<x:String>Capuchin Monkey</x:String>
<x:String>Blue Monkey</x:String>
<x:String>Squirrel Monkey</x:String>
<x:String>Golden Lion Tamarin</x:String>
<x:String>Howler Monkey</x:String>
<x:String>Japanese Macaque</x:String>
</x:Array>
</Picker.ItemsSource>
</Picker>
</Grid>
</cv1:CollectionView1.Footer>
</cv1:CollectionView1>
</Grid>
</ContentPage>
15 changes: 15 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue26186.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 26186, "When dynamically changing the CollectionView's width, the end portion of the CollectionView header's and footer's children is cut off", PlatformAffected.iOS | PlatformAffected.macOS)]
public partial class Issue26186 : ContentPage
{
public Issue26186()
{
InitializeComponent();
}

private void Button_Clicked(object sender, EventArgs e)
{
collectionView.WidthRequest = 300;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue26186(TestDevice testDevice) : _IssuesUITest(testDevice)
{
public override string Issue => "When dynamically changing the CollectionView's width, the end portion of the CollectionView header's and footer's children is cut off";

[Test]
[Category(UITestCategories.CollectionView)]
public void ShouldHeaderFooterUpdateWithoutCroppingOnResizing()
{
App.WaitForElement("Button");
App.Click("Button");
VerifyScreenshot();
}
}
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.