Skip to content

Commit

Permalink
Revert "Add some defensive code around layout propagation (#24217)"
Browse files Browse the repository at this point in the history
This reverts commit d85c05f.
  • Loading branch information
PureWeen committed Aug 26, 2024
1 parent 3bcd3eb commit 35e4957
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 89 deletions.
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project>
<PropertyGroup>
<!-- The .NET product branding version -->
<ProductVersion>8.0.81</ProductVersion>
<ProductVersion>8.0.82</ProductVersion>
<MajorVersion>8</MajorVersion>
<MinorVersion>0</MinorVersion>
<PatchVersion>81</PatchVersion>
<PatchVersion>82</PatchVersion>
<SdkBandVersion>8.0.100</SdkBandVersion>
<PreReleaseVersionLabel>servicing</PreReleaseVersionLabel>
<!-- Servicing builds have different characteristics for the way dependencies, baselines, and versions are handled. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,7 @@ protected virtual async Task<bool> OnPopViewAsync(Page page, bool animated)
var actuallyRemoved = poppedViewController == null ? true : !await task;
_ignorePopCall = false;

if (poppedViewController is ParentingViewController pvc)
pvc.Disconnect(false);
else
poppedViewController?.Dispose();
poppedViewController?.Dispose();

UpdateToolBarVisible();
return actuallyRemoved;
Expand Down Expand Up @@ -1145,9 +1142,7 @@ public Page Child
return;

if (child is not null)
{
child.PropertyChanged -= HandleChildPropertyChanged;
}

if (value is not null)
{
Expand Down Expand Up @@ -1277,69 +1272,45 @@ public override void WillMoveToParentViewController(UIViewController parent)
}
}

internal void Disconnect(bool dispose)
protected override void Dispose(bool disposing)
{
if (Child is Page child)
if (_disposed)
{
child.SendDisappearing();
child.PropertyChanged -= HandleChildPropertyChanged;
Child = null;
return;
}

if (_tracker is not null)
_disposed = true;

if (disposing)
{
if (Child is Page child)
{
child.SendDisappearing();
child.PropertyChanged -= HandleChildPropertyChanged;
Child = null;
}

_tracker.Target = null;
_tracker.CollectionChanged -= TrackerOnCollectionChanged;
_tracker = null;
}

if (NavigationItem.TitleView is not null)
{
if (dispose)
if (NavigationItem.TitleView != null)
{
NavigationItem.TitleView.Dispose();

NavigationItem.TitleView = null;
}

if (NavigationItem.RightBarButtonItems is not null && dispose)
{
for (var i = 0; i < NavigationItem.RightBarButtonItems.Length; i++)
NavigationItem.RightBarButtonItems[i].Dispose();
}

if (ToolbarItems is not null && dispose)
{
for (var i = 0; i < ToolbarItems.Length; i++)
ToolbarItems[i].Dispose();
}

for (int i = View.Subviews.Length - 1; i >= 0; i--)
{
View.Subviews[i].RemoveFromSuperview();
}


for (int i = ChildViewControllers.Length - 1; i >= 0; i--)
{
var childViewController = ChildViewControllers[i];
childViewController.View.RemoveFromSuperview();
childViewController.RemoveFromParentViewController();
}

}

protected override void Dispose(bool disposing)
{
if (_disposed)
{
return;
}
NavigationItem.TitleView = null;
}

_disposed = true;
if (NavigationItem.RightBarButtonItems != null)
{
for (var i = 0; i < NavigationItem.RightBarButtonItems.Length; i++)
NavigationItem.RightBarButtonItems[i].Dispose();
}

if (disposing)
{
Disconnect(true);
if (ToolbarItems != null)
{
for (var i = 0; i < ToolbarItems.Length; i++)
ToolbarItems[i].Dispose();
}
}

base.Dispose(disposing);
Expand Down Expand Up @@ -2000,7 +1971,7 @@ protected override void Dispose(bool disposing)

if (_child != null)
{
(_child.ContainerView ?? _child.PlatformView).RemoveFromSuperview();
_child.PlatformView.RemoveFromSuperview();
_child.DisconnectHandler();
_child = null;
}
Expand Down
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();
Superview?.SetNeedsLayout();
}

[Microsoft.Maui.Controls.Internals.Preserve(Conditional = true)]
Expand Down
2 changes: 0 additions & 2 deletions src/Controls/src/Core/NavigationPage/NavigationPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,6 @@ void FireAppearing(Page page)
void RemoveFromInnerChildren(Element page)
{
InternalChildren.Remove(page);

// TODO For NET9 we should remove this because the DisconnectHandlers will take care of it
page.Handler = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public static void UpdateContentLayout(this UIButton platformButton, Button butt
{
platformButton.ImageEdgeInsets = imageInsets;
platformButton.TitleEdgeInsets = titleInsets;
platformButton.GetSuperViewIfWindowSet()?.SetNeedsLayout();
platformButton.Superview?.SetNeedsLayout();
}
#pragma warning restore CA1416, CA1422
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/View/ViewHandlerOfT.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void CleanupContainerView(UIView? containerView)
if (containerView is WrapperView wrapperView)
{
wrapperView.RemoveFromSuperview();
wrapperView.Disconnect();
wrapperView.Dispose();
}
}
}
Expand Down
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();
Superview?.SetNeedsLayout();
}

public override void WillRemoveSubview(UIView uiview)
{
InvalidateConstraintsCache();
base.WillRemoveSubview(uiview);
this.GetSuperViewIfWindowSet()?.SetNeedsLayout();
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();
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
33 changes: 21 additions & 12 deletions src/Core/src/Platform/iOS/WrapperView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,12 @@ public override void LayoutSubviews()
SetBorder();
}

internal void Disconnect()
{
MaskLayer = null;
BackgroundMaskLayer = null;
ShadowLayer = null;
_borderView?.RemoveFromSuperview();
}


// TODO obsolete or delete this for NET9
public new void Dispose()
{
Disconnect();
DisposeClip();
DisposeShadow();
DisposeBorder();

base.Dispose();
}

Expand Down Expand Up @@ -165,7 +158,7 @@ public override void SetNeedsLayout()
{
base.SetNeedsLayout();

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

partial void ClipChanged()
Expand Down Expand Up @@ -207,6 +200,12 @@ void SetClip()
backgroundMask.Path = nativePath;
}

void DisposeClip()
{
MaskLayer = null;
BackgroundMaskLayer = null;
}

void SetShadow()
{
var shadowLayer = ShadowLayer;
Expand All @@ -231,6 +230,11 @@ void SetShadow()
shadowLayer.SetShadow(Shadow);
}

void DisposeShadow()
{
ShadowLayer = null;
}

void SetBorder()
{
if (Border == null)
Expand All @@ -247,6 +251,11 @@ void SetBorder()
_borderView.UpdateMauiCALayer(Border);
}

void DisposeBorder()
{
_borderView?.RemoveFromSuperview();
}

CALayer? GetLayer()
{
var sublayers = Layer?.Sublayers;
Expand Down

0 comments on commit 35e4957

Please sign in to comment.