Skip to content

Commit

Permalink
Remove code from iOS that short circuits propagation (#24477)
Browse files Browse the repository at this point in the history
* Remove code from iOS that short circuits propagation

* - fix
  • Loading branch information
PureWeen committed Aug 28, 2024
1 parent 84a6544 commit 944d860
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ protected override void Dispose(bool disposing)
public override void SetNeedsLayout()
{
base.SetNeedsLayout();
this.GetSuperViewIfWindowSet()?.SetNeedsLayout();
this.Superview?.SetNeedsLayout();
}

[Microsoft.Maui.Controls.Internals.Preserve(Conditional = true)]
Expand Down
47 changes: 47 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue24434.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Microsoft.Maui.Controls.Internals;

namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 24434, "Modifying a layout while view isn't part of the Window fails to update the layout visually",
PlatformAffected.iOS)]
public class Issue24434 : NavigationPage
{
public Issue24434() : base(new TestPage())
{

}

public class TestPage : ContentPage
{
public TestPage()
{
VerticalStackLayout vsl = new VerticalStackLayout();

vsl.Add(new Button()
{
Text = "Click me and you should see a label appear beneath me",
LineBreakMode = LineBreakMode.WordWrap,
AutomationId = "ClickMe",
Command = new Command(async () =>
{
TaskCompletionSource taskCompletionSource = new TaskCompletionSource();
vsl.Unloaded += (_, _) =>
{
vsl.Add(new Label { Text = "Hello, World!", AutomationId = "Success" });
taskCompletionSource.TrySetResult();
};
await Navigation.PushAsync(new ContentPage() { Content = new Label() { Text = "I should just disappear" } });
await Navigation.PushModalAsync(new ContentPage() { Content = new Label() { Text = "I should just disappear" } });
await taskCompletionSource.Task.WaitAsync(TimeSpan.FromSeconds(5));
await Navigation.PopModalAsync();
await Navigation.PopAsync();
})
});

Content = vsl;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue24434 : _IssuesUITest
{
public Issue24434(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Modifying a layout while view isn't part of the Window fails to update the layout visually";

[Test]
[Category(UITestCategories.Layout)]
public void ModifyingANonVisibleLayoutWorks()
{
App.WaitForElement("ClickMe");
App.Tap("ClickMe");
App.WaitForElement("Success");
}
}
}
4 changes: 2 additions & 2 deletions src/Core/src/Platform/iOS/LayoutView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ public override void SubviewAdded(UIView uiview)
{
InvalidateConstraintsCache();
base.SubviewAdded(uiview);
this.GetSuperViewIfWindowSet()?.SetNeedsLayout();
this.Superview?.SetNeedsLayout();
}

public override void WillRemoveSubview(UIView uiview)
{
InvalidateConstraintsCache();
base.WillRemoveSubview(uiview);
this.GetSuperViewIfWindowSet()?.SetNeedsLayout();
this.Superview?.SetNeedsLayout();
}

public override UIView? HitTest(CGPoint point, UIEvent? uievent)
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Platform/iOS/MauiView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public override void SetNeedsLayout()
{
InvalidateConstraintsCache();
base.SetNeedsLayout();
this.GetSuperViewIfWindowSet()?.SetNeedsLayout();
this.Superview?.SetNeedsLayout();
}

IVisualTreeElement? IVisualTreeElementProvidable.GetElement()
Expand Down
10 changes: 1 addition & 9 deletions src/Core/src/Platform/iOS/ViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,18 +264,10 @@ public static void UpdateBackgroundLayerFrame(this UIView view)
}
}

internal static UIView? GetSuperViewIfWindowSet(this UIView? view)
{
if (view?.Window is null)
return null;

return view.Superview;
}

public static void InvalidateMeasure(this UIView platformView, IView view)
{
platformView.SetNeedsLayout();
platformView.GetSuperViewIfWindowSet()?.SetNeedsLayout();
platformView.Superview?.SetNeedsLayout();
}

public static void UpdateWidth(this UIView platformView, IView view)
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Platform/iOS/WrapperView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public override void SetNeedsLayout()
{
base.SetNeedsLayout();

this.GetSuperViewIfWindowSet()?.SetNeedsLayout();
this.Superview?.SetNeedsLayout();
}

partial void ClipChanged()
Expand Down

0 comments on commit 944d860

Please sign in to comment.