From 4b833b0cd5f18eab9f3a679c41822010eddff452 Mon Sep 17 00:00:00 2001 From: "E.Z. Hart" Date: Wed, 18 May 2022 12:24:16 -0600 Subject: [PATCH] Propagate layout requests up the tree for Content/Layout Views (#7297) Remove unnecessary SetNeedsLayout call when switching visibility Fixes #6420; Fixes #7217 --- .../Compatibility/Handlers/iOS/FrameRenderer.cs | 6 ++++++ src/Core/src/Platform/iOS/ContentView.cs | 6 ++++++ src/Core/src/Platform/iOS/LayoutView.cs | 7 ++++++- src/Core/src/Platform/iOS/ViewExtensions.cs | 16 ++-------------- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/iOS/FrameRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/iOS/FrameRenderer.cs index 4143bf32ff74..e6546fa1ada6 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/iOS/FrameRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/iOS/FrameRenderer.cs @@ -173,6 +173,12 @@ protected override void Dispose(bool disposing) } } + public override void SetNeedsLayout() + { + base.SetNeedsLayout(); + Superview?.SetNeedsLayout(); + } + [Microsoft.Maui.Controls.Internals.Preserve(Conditional = true)] class FrameView : Microsoft.Maui.Platform.ContentView { diff --git a/src/Core/src/Platform/iOS/ContentView.cs b/src/Core/src/Platform/iOS/ContentView.cs index 703497815488..8e867638c2d1 100644 --- a/src/Core/src/Platform/iOS/ContentView.cs +++ b/src/Core/src/Platform/iOS/ContentView.cs @@ -31,6 +31,12 @@ public override void LayoutSubviews() CrossPlatformArrange?.Invoke(bounds); } + public override void SetNeedsLayout() + { + base.SetNeedsLayout(); + Superview?.SetNeedsLayout(); + } + internal Func? CrossPlatformMeasure { get; set; } internal Func? CrossPlatformArrange { get; set; } } diff --git a/src/Core/src/Platform/iOS/LayoutView.cs b/src/Core/src/Platform/iOS/LayoutView.cs index fd6d55fc0574..a09636fe2d21 100644 --- a/src/Core/src/Platform/iOS/LayoutView.cs +++ b/src/Core/src/Platform/iOS/LayoutView.cs @@ -35,11 +35,16 @@ public override void LayoutSubviews() base.LayoutSubviews(); var bounds = AdjustForSafeArea(Bounds).ToRectangle(); - CrossPlatformMeasure?.Invoke(bounds.Width, bounds.Height); CrossPlatformArrange?.Invoke(bounds); } + public override void SetNeedsLayout() + { + base.SetNeedsLayout(); + Superview?.SetNeedsLayout(); + } + public override void SubviewAdded(UIView uiview) { base.SubviewAdded(uiview); diff --git a/src/Core/src/Platform/iOS/ViewExtensions.cs b/src/Core/src/Platform/iOS/ViewExtensions.cs index 8299e1cb192c..b127581b064a 100644 --- a/src/Core/src/Platform/iOS/ViewExtensions.cs +++ b/src/Core/src/Platform/iOS/ViewExtensions.cs @@ -40,33 +40,21 @@ public static void Unfocus(this UIView platformView, IView view) public static void UpdateVisibility(this UIView platformView, Visibility visibility) { - var shouldLayout = false; - switch (visibility) { case Visibility.Visible: - shouldLayout = platformView.Inflate(); + platformView.Inflate(); platformView.Hidden = false; break; case Visibility.Hidden: - shouldLayout = platformView.Inflate(); + platformView.Inflate(); platformView.Hidden = true; break; case Visibility.Collapsed: platformView.Hidden = true; platformView.Collapse(); - shouldLayout = true; break; } - - // If the view is just switching between Visible and Hidden, then a re-layout isn't necessary. The return value - // from Inflate will tell us if the view was previously collapsed. If the view is switching to or from a collapsed - // state, then we'll have to ask for a re-layout. - - if (shouldLayout) - { - platformView.Superview?.SetNeedsLayout(); - } } public static void UpdateBackground(this ContentView platformView, IBorderStroke border)