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

CollectionView2 Items display issue when Header/Footer is resized on iOS #27076

Closed
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 @@ -14,6 +14,11 @@ public class StructuredItemsViewController2<TItemsView> : ItemsViewController2<T
public const int HeaderTag = 111;
public const int FooterTag = 222;

View _headerView;
View _footerView;
EventHandler _footerMeasureInvalidated;
EventHandler _headerMeasureInvalidated;

bool _disposed;

public StructuredItemsViewController2(TItemsView structuredItemsView, UICollectionViewLayout layout)
Expand All @@ -40,7 +45,11 @@ protected override void Dispose(bool disposing)

if (disposing)
{
if (_headerView != null)
_headerView.MeasureInvalidated -= _headerMeasureInvalidated;

if (_footerView != null)
_footerView.MeasureInvalidated -= _footerMeasureInvalidated;
}

base.Dispose(disposing);
Expand Down Expand Up @@ -115,26 +124,54 @@ void UpdateTemplatedSupplementaryView(TemplatedCell2 cell, NSString elementKind)

if (isHeader)
{
if (_headerView != null)
_headerView.MeasureInvalidated -= _headerMeasureInvalidated;

if (ItemsView.Header is View headerView)
{
_headerView = headerView;
cell.Bind(headerView, ItemsView);
}
else if (ItemsView.HeaderTemplate is not null)
{
_headerView = (View)ItemsView.HeaderTemplate.CreateContent();
cell.Bind(ItemsView.HeaderTemplate, ItemsView.Header, ItemsView);
}

_headerMeasureInvalidated = (s, e) =>
{
var indexPath = CollectionView.GetIndexPathForSupplementaryView(cell);
if (indexPath != null)
CollectionView.ReloadItems([indexPath]);
};

_headerView.MeasureInvalidated += _headerMeasureInvalidated;
cell.Tag = HeaderTag;
}
else
{
if (_footerView != null)
_footerView.MeasureInvalidated -= _footerMeasureInvalidated;

if (ItemsView.Footer is View footerView)
{
_footerView = footerView;
cell.Bind(footerView, ItemsView);
}
else if (ItemsView.FooterTemplate is not null)
{
_footerView = (View)ItemsView.FooterTemplate.CreateContent();
cell.Bind(ItemsView.FooterTemplate, ItemsView.Footer, ItemsView);
}

_footerMeasureInvalidated = (s, e) =>
{
var indexPath = CollectionView.GetIndexPathForSupplementaryView(cell);
if (indexPath != null)
CollectionView.ReloadItems([indexPath]);
};

_footerView.MeasureInvalidated += _footerMeasureInvalidated;
cell.Tag = FooterTag;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public Issue25362(TestDevice device) : base(device)

[Test]
[Category(UITestCategories.CollectionView)]
[FailsOnIOSWhenRunningOnXamarinUITest("This is not working for CV2 yet")]
[FailsOnMacWhenRunningOnXamarinUITest("This is not working for CV2 yet")]
public void HeaderShouldNotCollapseWithItems()
{
App.WaitForElement("button");
Expand Down
Loading