From fa703174531ecb97ac4c61d9933a9f04408c617e Mon Sep 17 00:00:00 2001 From: Jakub Florkowski Date: Sat, 13 Apr 2024 17:23:14 +0200 Subject: [PATCH] Fix #12429 --- .../iOS/StructuredItemsViewController.cs | 31 +++++++++++++++++++ src/Core/src/Platform/iOS/MauiView.cs | 9 ++++++ 2 files changed, 40 insertions(+) diff --git a/src/Controls/src/Core/Handlers/Items/iOS/StructuredItemsViewController.cs b/src/Controls/src/Core/Handlers/Items/iOS/StructuredItemsViewController.cs index 62116b468264..e84a62b14422 100644 --- a/src/Controls/src/Core/Handlers/Items/iOS/StructuredItemsViewController.cs +++ b/src/Controls/src/Core/Handlers/Items/iOS/StructuredItemsViewController.cs @@ -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; @@ -105,6 +115,11 @@ 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() @@ -112,8 +127,14 @@ 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(); @@ -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); + } } } \ No newline at end of file diff --git a/src/Core/src/Platform/iOS/MauiView.cs b/src/Core/src/Platform/iOS/MauiView.cs index e125a46f5586..d9a12470f51b 100644 --- a/src/Core/src/Platform/iOS/MauiView.cs +++ b/src/Core/src/Platform/iOS/MauiView.cs @@ -134,6 +134,7 @@ public override void LayoutSubviews() } CrossPlatformArrange(bounds); + OnLayoutChanged(); } public override void SetNeedsLayout() @@ -174,5 +175,13 @@ public override void MovedToWindow() base.MovedToWindow(); _movedToWindow?.Invoke(this, EventArgs.Empty); } + + [UnconditionalSuppressMessage("Memory", "MEM0001", Justification = IUIViewLifeCycleEvents.UnconditionalSuppressMessage)] + internal event EventHandler? LayoutChanged; + + private void OnLayoutChanged() + { + LayoutChanged?.Invoke(this, EventArgs.Empty); + } } }