Skip to content
Merged
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 @@ -199,6 +199,12 @@ public override void ViewWillAppear(bool animated)
public override void ViewWillLayoutSubviews()
{
ConstrainItemsToBounds();

if (CollectionView is Items.MauiCollectionView { NeedsCellLayout: true } collectionView)
{
collectionView.NeedsCellLayout = false;
}

base.ViewWillLayoutSubviews();
InvalidateMeasureIfContentSizeChanged();
LayoutEmptyView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ internal class MauiCollectionView : UICollectionView, IUIViewLifeCycleEvents, IP
bool _invalidateParentWhenMovedToWindow;

WeakReference<ICustomMauiCollectionViewDelegate>? _customDelegate;

internal bool NeedsCellLayout { get; set; }

public MauiCollectionView(CGRect frame, UICollectionViewLayout layout) : base(frame, layout)
{
}
Expand All @@ -27,10 +30,11 @@ void IPlatformMeasureInvalidationController.InvalidateAncestorsMeasuresWhenMoved

void IPlatformMeasureInvalidationController.InvalidateMeasure(bool isPropagating)
{
if (!isPropagating)
if (isPropagating)
{
SetNeedsLayout();
NeedsCellLayout = true;
}
SetNeedsLayout();
}

[UnconditionalSuppressMessage("Memory", "MEM0002", Justification = IUIViewLifeCycleEvents.UnconditionalSuppressMessage)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,23 @@ protected override CGRect DetermineEmptyViewFrame()

public override void ViewWillLayoutSubviews()
{
base.ViewWillLayoutSubviews();

// 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)
var hasHeaderOrFooter = _footerViewFormsElement is not null || _headerViewFormsElement is not null;
if (hasHeaderOrFooter && CollectionView is MauiCollectionView { NeedsCellLayout: true } collectionView)
{
var emptyView = CollectionView.ViewWithTag(EmptyTag);

if (IsHorizontal)
if (_headerViewFormsElement is not null)
{
if (_footerUIView.Frame.X != ItemsViewLayout.CollectionViewContentSize.Width ||
_footerUIView.Frame.X < emptyView?.Frame.X)
UpdateHeaderFooterPosition();
RemeasureLayout(_headerViewFormsElement);
}
else

if (_footerViewFormsElement is not null)
{
if (_footerUIView.Frame.Y != ItemsViewLayout.CollectionViewContentSize.Height ||
_footerUIView.Frame.Y < (emptyView?.Frame.Y + emptyView?.Frame.Height))
UpdateHeaderFooterPosition();
RemeasureLayout(_footerViewFormsElement);
}

UpdateHeaderFooterPosition();
}

base.ViewWillLayoutSubviews();
}

internal void UpdateFooterView()
Expand Down