Skip to content

Commit

Permalink
Fix compatibility issue (#41)
Browse files Browse the repository at this point in the history
* Fix compatibility issue

* Fix Compatibility Resource path
  • Loading branch information
myroot authored and rookiejava committed Dec 27, 2021
1 parent 9220850 commit 5627567
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 17 deletions.
23 changes: 21 additions & 2 deletions src/Compatibility/Core/src/RendererToHandlerShim.Tizen.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Microsoft.Maui.Controls.Compatibility.Platform.Tizen;
using NativeView = ElmSharp.EvasObject;
using Microsoft.Maui.Graphics;
using ERect = ElmSharp.Rect;
using NativeView = ElmSharp.EvasObject;

namespace Microsoft.Maui.Controls.Compatibility
{
public partial class RendererToHandlerShim
public partial class RendererToHandlerShim : INativeViewHandler
{
protected override NativeView CreateNativeView()
{
Expand All @@ -16,6 +17,15 @@ IVisualElementRenderer CreateRenderer(IView view)
return Internals.Registrar.Registered.GetHandlerForObject<IVisualElementRenderer>(view) ?? new DefaultRenderer();
}

public override Size GetDesiredSize(double widthConstraint, double heightConstraint)
{
if (VisualElementRenderer == null)
return Size.Zero;

// TODO. It is workaroud code, Controls.VisualElement.MeasureOverride implementation is wrong. it does not apply Height/WidthRequest
return VisualElementRenderer.Element.Measure(widthConstraint, heightConstraint).Request;
}

public override void UpdateValue(string property)
{
base.UpdateValue(property);
Expand All @@ -29,5 +39,14 @@ public override ERect GetNativeContentGeometry()
{
return VisualElementRenderer?.GetNativeContentGeometry() ?? new ERect();
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
VisualElementRenderer?.Dispose();
}
base.Dispose(disposing);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class DefaultColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return ((Color)value).IsDefault ? ThemeConstants.EntryCell.ColorClass.DefaultLabelColor : value;
return (value == null || ((Color)value).IsDefault) ? ThemeConstants.EntryCell.ColorClass.DefaultLabelColor : value;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down
26 changes: 20 additions & 6 deletions src/Compatibility/Core/src/Tizen/HandlerToRendererShim.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
using System;
using System.ComponentModel;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Graphics;
using EvasObject = ElmSharp.EvasObject;
using Microsoft.Maui.Handlers;
using ERect = ElmSharp.Rect;
using EvasObject = ElmSharp.EvasObject;

namespace Microsoft.Maui.Controls.Compatibility.Platform.Tizen
{
public class LayoutHandlerToRendererShim : HandlerToRendererShim, ILayoutRenderer
{
LayoutHandler _layoutHandler;
public LayoutHandlerToRendererShim(LayoutHandler vh) : base(vh)
{
_layoutHandler = vh;
}

public void RegisterOnLayoutUpdated()
{
_layoutHandler.RegisterOnLayoutUpdated();
}
}

public class HandlerToRendererShim : IVisualElementRenderer
{
public HandlerToRendererShim(IViewHandler vh)
Expand All @@ -27,7 +42,7 @@ public HandlerToRendererShim(IViewHandler vh)

public void Dispose()
{
ViewHandler.DisconnectHandler();
(ViewHandler as INativeViewHandler)?.Dispose();
}

public void SetElement(VisualElement element)
Expand Down Expand Up @@ -97,7 +112,7 @@ public MockParentHandler(VisualElement parent)
}

VisualElement RealParent { get; }
IVisualElementRenderer Renderer => Platform.GetRenderer(RealParent);
IVisualElementRenderer Renderer => RealParent != null ? Platform.GetRenderer(RealParent) : null;
public EvasObject NativeView => Renderer.NativeView;

public EvasObject ContainerView => NativeView;
Expand All @@ -119,7 +134,6 @@ public void DisconnectHandler() { }

public void Dispose()
{
throw new NotImplementedException();
}

public Size GetDesiredSize(double widthConstraint, double heightConstraint)
Expand All @@ -129,7 +143,7 @@ public Size GetDesiredSize(double widthConstraint, double heightConstraint)

public ERect GetNativeContentGeometry()
{
return Renderer.GetNativeContentGeometry();
return Renderer?.GetNativeContentGeometry() ?? new ERect(0, 0, 0, 0);
}

public void NativeArrange(Rectangle frame)
Expand Down
12 changes: 11 additions & 1 deletion src/Compatibility/Core/src/Tizen/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using ElmSharp;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Handlers;

[assembly: InternalsVisibleTo("Microsoft.Maui.Controls.Material")]

Expand Down Expand Up @@ -84,7 +85,16 @@ internal static IVisualElementRenderer CreateRenderer(VisualElement element)
{
vh.SetParent(nvh);
}
renderer = new HandlerToRendererShim(vh);

if (handler is LayoutHandler layoutHandler)
{
renderer = new LayoutHandlerToRendererShim(layoutHandler);
}
else
{
renderer = new HandlerToRendererShim(vh);
}

element.Handler = handler;
SetRenderer(element, renderer);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Compatibility/Core/src/Tizen/ThemeConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public class RefreshView
public class Resources
{
public const int IconSize = 48;
public const string IconPath = "Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Resource.refresh_48dp.png";
public const string IconPath = "Microsoft.Maui.Controls.Compatibility.Resource.refresh_48dp.png";
}

public class ColorClass
Expand Down Expand Up @@ -575,7 +575,7 @@ public class Watch
public const int DefaultNavigationViewIconSize = 60;
public const int DefaultDrawerTouchWidth = 50;
public const int DefaultDrawerIconSize = 40;
public const string DefaultDrawerIcon = "Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Resource.wc_visual_cue.png";
public const string DefaultDrawerIcon = "Microsoft.Maui.Controls.Compatibility.Resource.wc_visual_cue.png";
}

public class TV
Expand Down Expand Up @@ -619,8 +619,8 @@ public class MediaPlayer
{
public class Resources
{
public const string PlayImagePath = "Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Resource.img_button_play.png";
public const string PauseImagePath = "Microsoft.Maui.Controls.Compatibility.Platform.Tizen.Resource.img_button_pause.png";
public const string PlayImagePath = "Microsoft.Maui.Controls.Compatibility.Resource.img_button_play.png";
public const string PauseImagePath = "Microsoft.Maui.Controls.Compatibility.Resource.img_button_pause.png";
}

public class ColorClass
Expand Down
28 changes: 25 additions & 3 deletions src/Core/src/Handlers/Layout/LayoutHandler.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@

namespace Microsoft.Maui.Handlers
{
public partial class LayoutHandler : ViewHandler<ILayout, Canvas>
public interface IRegisterLayoutUpdate
{
void RegisterOnLayoutUpdated();
}

public partial class LayoutHandler : ViewHandler<ILayout, Canvas>, IRegisterLayoutUpdate
{
bool _layoutUpdatedRegistered;
Graphics.Rectangle _arrangeCache;

public override bool NeedsContainer =>
Expand Down Expand Up @@ -87,6 +93,13 @@ public void Remove(IView child)
}
}

protected override Graphics.Point ComputeAbsolutePoint(Graphics.Rectangle frame)
{
if (_layoutUpdatedRegistered)
return frame.Location;
return base.ComputeAbsolutePoint(frame);
}

protected override void ConnectHandler(Canvas nativeView)
{
base.ConnectHandler(nativeView);
Expand Down Expand Up @@ -114,11 +127,20 @@ protected void OnLayoutUpdated(object? sender, LayoutEventArgs e)
VirtualView.InvalidateMeasure();
VirtualView.InvalidateArrange();
VirtualView.Measure(nativeGeometry.Width, nativeGeometry.Height);
nativeGeometry.X = VirtualView.Frame.X;
nativeGeometry.Y = VirtualView.Frame.Y;

if (!_layoutUpdatedRegistered)
{
nativeGeometry.X = VirtualView.Frame.X;
nativeGeometry.Y = VirtualView.Frame.Y;
}
VirtualView.Arrange(nativeGeometry);
}
}
}

public void RegisterOnLayoutUpdated()
{
_layoutUpdatedRegistered = true;
}
}
}

0 comments on commit 5627567

Please sign in to comment.