Skip to content

Commit

Permalink
Fix Managing Layout Children (dotnet#11581)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoonghyunCho authored and rookiejava committed Dec 15, 2022
1 parent 1eecae5 commit ec108b9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Core/src/Handlers/Layout/LayoutHandler.Tizen.cs
Original file line number Diff line number Diff line change
@@ -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 ec108b9

Please sign in to comment.