Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate layout requests up the tree for Content/Layout Views #7297

Merged
merged 1 commit into from May 18, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -33,11 +33,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