Skip to content

Commit

Permalink
Fix #12429
Browse files Browse the repository at this point in the history
  • Loading branch information
kubaflo authored and rmarinho committed Oct 18, 2024
1 parent b744c9d commit 9cb18cf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ protected override void Dispose(bool disposing)
_footerViewFormsElement.MeasureInvalidated -= OnFormsElementMeasureInvalidated;
}

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

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

_headerUIView = null;
_headerViewFormsElement = null;
_footerUIView = null;
Expand Down Expand Up @@ -105,15 +115,26 @@ internal void UpdateFooterView()
UpdateSubview(ItemsView?.Footer, ItemsView?.FooterTemplate, FooterTag,
ref _footerUIView, ref _footerViewFormsElement);
UpdateHeaderFooterPosition();

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

internal void UpdateHeaderView()
{
UpdateSubview(ItemsView?.Header, ItemsView?.HeaderTemplate, HeaderTag,
ref _headerUIView, ref _headerViewFormsElement);
UpdateHeaderFooterPosition();

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


internal void UpdateSubview(object view, DataTemplate viewTemplate, nint viewTag, ref UIView uiView, ref VisualElement formsElement)
{
uiView?.RemoveFromSuperview();
Expand Down Expand Up @@ -239,5 +260,15 @@ internal void UpdateLayoutMeasurements()
if (_footerViewFormsElement != null)
HandleFormsElementMeasureInvalidated(_footerViewFormsElement);
}

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

private void FooterView_LayoutChanged(object sender, EventArgs e)
{
HandleFormsElementMeasureInvalidated(_footerViewFormsElement);
}
}
}
9 changes: 9 additions & 0 deletions src/Core/src/Platform/iOS/MauiView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public override void LayoutSubviews()
}

CrossPlatformArrange(bounds);
OnLayoutChanged();
}

public override void SetNeedsLayout()
Expand Down Expand Up @@ -198,5 +199,13 @@ 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);
}
}
}

0 comments on commit 9cb18cf

Please sign in to comment.