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

CollectionView Items display issue when Header is resized on iOS #21812

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ internal override void Disconnect()
_footerViewFormsElement.MeasureInvalidated -= OnFormsElementMeasureInvalidated;
}

if (_headerUIView is MauiView hv)
{
hv.LayoutChanged -= HeaderViewLayoutChanged;
}

if (_footerUIView is MauiView fv)
{
fv.LayoutChanged -= FooterViewLayoutChanged;
}

_headerUIView = null;
_headerViewFormsElement = null;
_footerUIView = null;
Expand Down Expand Up @@ -125,36 +115,16 @@ public override void ViewWillLayoutSubviews()

internal void UpdateFooterView()
{
if (_footerUIView is MauiView mvPrevious)
{
mvPrevious.LayoutChanged -= FooterViewLayoutChanged;
}

UpdateSubview(ItemsView?.Footer, ItemsView?.FooterTemplate, FooterTag,
ref _footerUIView, ref _footerViewFormsElement);
UpdateHeaderFooterPosition();

if (_footerUIView is MauiView mv)
{
mv.LayoutChanged += FooterViewLayoutChanged;
}
}

internal void UpdateHeaderView()
{
if (_headerUIView is MauiView mvPrevious)
{
mvPrevious.LayoutChanged -= HeaderViewLayoutChanged;
}

UpdateSubview(ItemsView?.Header, ItemsView?.HeaderTemplate, HeaderTag,
ref _headerUIView, ref _headerViewFormsElement);
UpdateHeaderFooterPosition();

if (_headerUIView is MauiView mv)
{
mv.LayoutChanged += HeaderViewLayoutChanged;
}
}


Expand Down Expand Up @@ -200,8 +170,8 @@ void UpdateHeaderFooterPosition()
{
var currentInset = CollectionView.ContentInset;

nfloat headerWidth = _headerUIView?.Frame.Width ?? 0f;
nfloat footerWidth = _footerUIView?.Frame.Width ?? 0f;
nfloat headerWidth = _headerViewFormsElement?.ToPlatform()?.Frame.Width ?? 0f;
nfloat footerWidth = _footerViewFormsElement?.ToPlatform()?.Frame.Width ?? 0f;
nfloat emptyWidth = emptyView?.Frame.Width ?? 0f;

if (_headerUIView != null && _headerUIView.Frame.X != headerWidth)
Expand Down Expand Up @@ -230,8 +200,8 @@ void UpdateHeaderFooterPosition()
else
{
var currentInset = CollectionView.ContentInset;
nfloat headerHeight = _headerUIView?.Frame.Height ?? 0f;
nfloat footerHeight = _footerUIView?.Frame.Height ?? 0f;
nfloat headerHeight = _headerViewFormsElement?.ToPlatform()?.Frame.Height ?? 0f;
nfloat footerHeight = _footerViewFormsElement?.ToPlatform()?.Frame.Height ?? 0f;
nfloat emptyHeight = emptyView?.Frame.Height ?? 0f;

if (CollectionView.ContentInset.Top != headerHeight || CollectionView.ContentInset.Bottom != footerHeight)
Expand Down Expand Up @@ -283,15 +253,5 @@ internal void UpdateLayoutMeasurements()
if (_footerViewFormsElement != null)
HandleFormsElementMeasureInvalidated(_footerViewFormsElement);
}

void HeaderViewLayoutChanged(object sender, EventArgs e)
{
HandleFormsElementMeasureInvalidated(_headerViewFormsElement);
}

void FooterViewLayoutChanged(object sender, EventArgs e)
{
HandleFormsElementMeasureInvalidated(_footerViewFormsElement);
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25362.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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.Issue25362"
x:Name="Self"
Title="Issue25362">
<Grid RowDefinitions="Auto,*">
<HorizontalStackLayout Grid.Row="0">
<Button
Command="{Binding AddCommand}"
HorizontalOptions="Center"
AutomationId="button"
Text="Add" />
</HorizontalStackLayout>

<CollectionView
Grid.Row="1"
ItemsSource="{Binding ItemList}">

<CollectionView.Header>
<VerticalStackLayout>
<VerticalStackLayout BindableLayout.ItemsSource="{Binding BindingContext.ItemListHeader, Source={x:Reference Self}}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Label Padding="10" Text="{Binding .}" />
</DataTemplate>
</BindableLayout.ItemTemplate>
</VerticalStackLayout>
<BoxView
Margin="0,5"
HeightRequest="2"
Color="Black" />
</VerticalStackLayout>
</CollectionView.Header>

<CollectionView.ItemTemplate>
<DataTemplate>
<Label Padding="10" Text="{Binding .}" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</Grid>
</ContentPage>
24 changes: 24 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25362.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.ObjectModel;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;

namespace Maui.Controls.Sample.Issues;

[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 25362, "[iOS] CollectionView Items display issue when Header is resized", PlatformAffected.iOS)]

public partial class Issue25362 : ContentPage
{
public ObservableCollection<string> ItemList { get; }
public ObservableCollection<string> ItemListHeader { get; }

public Command AddCommand => new(() => ItemListHeader.Add($"HeaderItem{ItemListHeader.Count + 1}"));

public Issue25362()
{
InitializeComponent();
ItemList = new() { "Item1", "Item2", "Itme3" };
ItemListHeader = new() { "HeaderItem1" };
BindingContext = this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue25362 : _IssuesUITest
{
public override string Issue => "[iOS] CollectionView Items display issue when Header is resized";

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

[Test]
[Category(UITestCategories.CollectionView)]
public void HeaderShouldNotCollapseWithItems()
{
App.WaitForElement("button");
App.Click("button");
App.Click("button");
App.Click("button");

//The test passes of header has 4 elements that don't overlap with the collection view's items
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.
9 changes: 0 additions & 9 deletions src/Core/src/Platform/iOS/MauiView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public override void LayoutSubviews()
}

CrossPlatformArrange(bounds);
OnLayoutChanged();
rmarinho marked this conversation as resolved.
Show resolved Hide resolved
}

public override void SetNeedsLayout()
Expand Down Expand Up @@ -199,13 +198,5 @@ public override void MovedToWindow()
_movedToWindow?.Invoke(this, EventArgs.Empty);
TryToInvalidateSuperView(true);
}

[UnconditionalSuppressMessage("Memory", "MEM0001", Justification = IUIViewLifeCycleEvents.UnconditionalSuppressMessage)]
internal event EventHandler? LayoutChanged;

private void OnLayoutChanged()
{
LayoutChanged?.Invoke(this, EventArgs.Empty);
}
}
}