Skip to content

Commit

Permalink
Propagate layout requests up the tree for Content/Layout Views (#7297)
Browse files Browse the repository at this point in the history
Remove unnecessary SetNeedsLayout call when switching visibility
Fixes #6420; Fixes #7217
  • Loading branch information
hartez committed May 18, 2022
1 parent b8727a4 commit 4b833b0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
Expand Up @@ -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
{
Expand Down
6 changes: 6 additions & 0 deletions src/Core/src/Platform/iOS/ContentView.cs
Expand Up @@ -31,6 +31,12 @@ public override void LayoutSubviews()
CrossPlatformArrange?.Invoke(bounds);
}

public override void SetNeedsLayout()
{
base.SetNeedsLayout();
Superview?.SetNeedsLayout();
}

internal Func<double, double, Size>? CrossPlatformMeasure { get; set; }
internal Func<Rect, Size>? CrossPlatformArrange { get; set; }
}
Expand Down
7 changes: 6 additions & 1 deletion src/Core/src/Platform/iOS/LayoutView.cs
Expand Up @@ -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);
Expand Down
16 changes: 2 additions & 14 deletions src/Core/src/Platform/iOS/ViewExtensions.cs
Expand Up @@ -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)
Expand Down

0 comments on commit 4b833b0

Please sign in to comment.