Skip to content

Commit

Permalink
Fix LayoutHandler Update issue (#103)
Browse files Browse the repository at this point in the history
* Fix LayoutHandler Update issue

* Implement InvalidateMeasure propagation

* Update MapBackground
  • Loading branch information
myroot authored and rookiejava committed Jan 27, 2022
1 parent 44de609 commit f3e4e98
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
18 changes: 11 additions & 7 deletions src/Core/src/Handlers/Layout/LayoutHandler.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ public partial class LayoutHandler : ViewHandler<ILayout, LayoutCanvas>
VirtualView?.Clip != null ||
base.NeedsContainer;

public static void MapBackground(LayoutHandler handler, ILayout layout)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));
handler.WrappedNativeView?.UpdateBackground(layout);
}

protected override LayoutCanvas CreateNativeView()
{
if (VirtualView == null)
Expand Down Expand Up @@ -93,7 +87,14 @@ public void Remove(IView child)

public void Clear()
{
NativeView?.Clear();
if (NativeView == null)
return;

foreach (var child in NativeView.Children)
{
child.Unrealize();
}
NativeView.Children.Clear();
}

public void Insert(int index, IView child)
Expand All @@ -115,7 +116,10 @@ public void Update(int index, IView child)
_ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class.");
_ = MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");

var toBeRemoved = NativeView.Children[index];
NativeView.Children.RemoveAt(index);
toBeRemoved.Unrealize();

NativeView.Children.Insert(index, child.ToNative(MauiContext));
if (child.Handler is INativeViewHandler childHandler)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Core/src/Handlers/View/ViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,12 @@ public static void MapVisibility(IViewHandler handler, IView view)

public static void MapBackground(IViewHandler handler, IView view)
{
#if TIZEN
handler.UpdateValue(nameof(IViewHandler.ContainerView));
handler.WrappedNativeView?.UpdateBackground(view);
#else
((NativeView?)handler.NativeView)?.UpdateBackground(view);
#endif
}

public static void MapFlowDirection(IViewHandler handler, IView view)
Expand Down
12 changes: 7 additions & 5 deletions src/Core/src/Platform/Tizen/LayoutCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ namespace Microsoft.Maui
{
public class LayoutCanvas : Canvas, IMeasurable
{
Rectangle _arrangeCache;
IView _virtualView;
Size _measureCache;

public LayoutCanvas(EvasObject parent, IView view) : base(parent)
{
_arrangeCache = default(Rectangle);
_virtualView = view;
LayoutUpdated += OnLayoutUpdated;
}
Expand All @@ -32,14 +31,17 @@ protected void OnLayoutUpdated(object? sender, LayoutEventArgs e)
{
var nativeGeometry = Geometry.ToDP();

if (_arrangeCache == nativeGeometry)
return;
var measured = CrossPlatformMeasure!(nativeGeometry.Width, nativeGeometry.Height);
if (measured != _measureCache)
{
_virtualView?.Parent?.InvalidateMeasure();
}
_measureCache = measured;

if (nativeGeometry.Width > 0 && nativeGeometry.Height > 0)
{
nativeGeometry.X = 0;
nativeGeometry.Y = 0;
CrossPlatformMeasure!(nativeGeometry.Width, nativeGeometry.Height);
CrossPlatformArrange!(nativeGeometry);
}
}
Expand Down

0 comments on commit f3e4e98

Please sign in to comment.