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

[net7.0] Fix Managing Layout Children #11963

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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