Skip to content

Commit

Permalink
[net6.0]Fix Managing Layout Children (#12125)
Browse files Browse the repository at this point in the history
### Description of Change

This PR backports #11581 to `net6.0`
  • Loading branch information
rmarinho committed Dec 15, 2022
2 parents 1eecae5 + ec108b9 commit dfd7fc5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Core/src/Handlers/Layout/LayoutHandler.Tizen.cs
@@ -1,11 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NView = Tizen.NUI.BaseComponents.View;

namespace Microsoft.Maui.Handlers
{
public partial class LayoutHandler : ViewHandler<ILayout, LayoutViewGroup>
{
List<IView> _children = new List<IView>();

public override bool NeedsContainer =>
VirtualView?.Background != null ||
VirtualView?.Clip != null ||
Expand Down Expand Up @@ -39,10 +42,12 @@ public override void SetVirtualView(IView view)
PlatformView.CrossPlatformArrange = VirtualView.CrossPlatformArrange;

PlatformView.Children.Clear();
_children.Clear();

foreach (var child in VirtualView.OrderByZIndex())
{
PlatformView.Children.Add(child.ToPlatform(MauiContext));
_children.Add(child);
}
}

Expand All @@ -54,6 +59,7 @@ public void Add(IView child)

var targetIndex = VirtualView.GetLayoutHandlerIndex(child);
PlatformView.Children.Insert(targetIndex, child.ToPlatform(MauiContext));
_children.Insert(targetIndex, child);
EnsureZIndexOrder(child);
PlatformView.SetNeedMeasureUpdate();
}
Expand All @@ -66,6 +72,7 @@ public void Remove(IView child)
if (child.Handler is IPlatformViewHandler thandler && child?.ToPlatform() is NView childView)
{
PlatformView.Children.Remove(childView);
_children.Remove(child);
thandler.Dispose();
}
PlatformView.MarkChanged();
Expand All @@ -83,6 +90,13 @@ public void Clear()
{
child.Dispose();
}

foreach (var child in _children)
{
(child.Handler as IPlatformViewHandler)?.Dispose();
}
_children.Clear();

PlatformView.SetNeedMeasureUpdate();
}

Expand All @@ -94,6 +108,7 @@ public void Insert(int index, IView child)

var targetIndex = VirtualView.GetLayoutHandlerIndex(child);
PlatformView.Children.Insert(targetIndex, child.ToPlatform(MauiContext));
_children.Insert(targetIndex, child);
EnsureZIndexOrder(child);
PlatformView.SetNeedMeasureUpdate();
}
Expand All @@ -107,9 +122,13 @@ public void Update(int index, IView child)
var toBeRemoved = PlatformView.Children[index];
PlatformView.Children.RemoveAt(index);
toBeRemoved.Dispose();
var childToBeRemoved = _children[index];
_children.RemoveAt(index);
(childToBeRemoved as IPlatformViewHandler)?.Dispose();

var targetIndex = VirtualView.GetLayoutHandlerIndex(child);
PlatformView.Children.Insert(targetIndex, child.ToPlatform(MauiContext));
_children.Insert(targetIndex, child);
EnsureZIndexOrder(child);
PlatformView.SetNeedMeasureUpdate();
}
Expand Down

0 comments on commit dfd7fc5

Please sign in to comment.