diff --git a/src/Compatibility/Core/src/RendererToHandlerShim.Tizen.cs b/src/Compatibility/Core/src/RendererToHandlerShim.Tizen.cs index 06de675595f5..af6ee8f02603 100644 --- a/src/Compatibility/Core/src/RendererToHandlerShim.Tizen.cs +++ b/src/Compatibility/Core/src/RendererToHandlerShim.Tizen.cs @@ -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() { @@ -16,6 +17,15 @@ IVisualElementRenderer CreateRenderer(IView view) return Internals.Registrar.Registered.GetHandlerForObject(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); @@ -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); + } } } diff --git a/src/Compatibility/Core/src/Tizen/Cells/EntryCellRenderer.cs b/src/Compatibility/Core/src/Tizen/Cells/EntryCellRenderer.cs index 62f4ecd19e71..09ec0de3e810 100644 --- a/src/Compatibility/Core/src/Tizen/Cells/EntryCellRenderer.cs +++ b/src/Compatibility/Core/src/Tizen/Cells/EntryCellRenderer.cs @@ -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) diff --git a/src/Compatibility/Core/src/Tizen/HandlerToRendererShim.cs b/src/Compatibility/Core/src/Tizen/HandlerToRendererShim.cs index 74185fe40c26..ee12b4dbfad4 100644 --- a/src/Compatibility/Core/src/Tizen/HandlerToRendererShim.cs +++ b/src/Compatibility/Core/src/Tizen/HandlerToRendererShim.cs @@ -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) @@ -27,7 +42,7 @@ public HandlerToRendererShim(IViewHandler vh) public void Dispose() { - ViewHandler.DisconnectHandler(); + (ViewHandler as INativeViewHandler)?.Dispose(); } public void SetElement(VisualElement element) @@ -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; @@ -119,7 +134,6 @@ public void DisconnectHandler() { } public void Dispose() { - throw new NotImplementedException(); } public Size GetDesiredSize(double widthConstraint, double heightConstraint) @@ -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) diff --git a/src/Compatibility/Core/src/Tizen/Platform.cs b/src/Compatibility/Core/src/Tizen/Platform.cs index 662de0f8d9d2..d37f84de8498 100644 --- a/src/Compatibility/Core/src/Tizen/Platform.cs +++ b/src/Compatibility/Core/src/Tizen/Platform.cs @@ -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")] @@ -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); } diff --git a/src/Compatibility/Core/src/Tizen/Resource/arrow_left.png b/src/Compatibility/Core/src/Tizen/Resources/arrow_left.png similarity index 100% rename from src/Compatibility/Core/src/Tizen/Resource/arrow_left.png rename to src/Compatibility/Core/src/Tizen/Resources/arrow_left.png diff --git a/src/Compatibility/Core/src/Tizen/Resource/dots_horizontal.png b/src/Compatibility/Core/src/Tizen/Resources/dots_horizontal.png similarity index 100% rename from src/Compatibility/Core/src/Tizen/Resource/dots_horizontal.png rename to src/Compatibility/Core/src/Tizen/Resources/dots_horizontal.png diff --git a/src/Compatibility/Core/src/Tizen/Resource/menu.png b/src/Compatibility/Core/src/Tizen/Resources/menu.png similarity index 100% rename from src/Compatibility/Core/src/Tizen/Resource/menu.png rename to src/Compatibility/Core/src/Tizen/Resources/menu.png diff --git a/src/Compatibility/Core/src/Tizen/Resource/refresh_48dp.png b/src/Compatibility/Core/src/Tizen/Resources/refresh_48dp.png similarity index 100% rename from src/Compatibility/Core/src/Tizen/Resource/refresh_48dp.png rename to src/Compatibility/Core/src/Tizen/Resources/refresh_48dp.png diff --git a/src/Compatibility/Core/src/Tizen/Resource/wc_visual_cue.png b/src/Compatibility/Core/src/Tizen/Resources/wc_visual_cue.png similarity index 100% rename from src/Compatibility/Core/src/Tizen/Resource/wc_visual_cue.png rename to src/Compatibility/Core/src/Tizen/Resources/wc_visual_cue.png diff --git a/src/Compatibility/Core/src/Tizen/ThemeConstants.cs b/src/Compatibility/Core/src/Tizen/ThemeConstants.cs index ca27f130bb28..18c47ae7656c 100644 --- a/src/Compatibility/Core/src/Tizen/ThemeConstants.cs +++ b/src/Compatibility/Core/src/Tizen/ThemeConstants.cs @@ -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 @@ -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 @@ -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 diff --git a/src/Core/src/Handlers/Layout/LayoutHandler.Tizen.cs b/src/Core/src/Handlers/Layout/LayoutHandler.Tizen.cs index d96ce340bd9a..e73b0973d715 100644 --- a/src/Core/src/Handlers/Layout/LayoutHandler.Tizen.cs +++ b/src/Core/src/Handlers/Layout/LayoutHandler.Tizen.cs @@ -5,8 +5,14 @@ namespace Microsoft.Maui.Handlers { - public partial class LayoutHandler : ViewHandler + public interface IRegisterLayoutUpdate { + void RegisterOnLayoutUpdated(); + } + + public partial class LayoutHandler : ViewHandler, IRegisterLayoutUpdate + { + bool _layoutUpdatedRegistered; Graphics.Rectangle _arrangeCache; public override bool NeedsContainer => @@ -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); @@ -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; + } } }