diff --git a/src/Core/src/Handlers/View/ViewHandlerOfT.Tizen.cs b/src/Core/src/Handlers/View/ViewHandlerOfT.Tizen.cs index c8c49fdfbf48..552bcf509e54 100644 --- a/src/Core/src/Handlers/View/ViewHandlerOfT.Tizen.cs +++ b/src/Core/src/Handlers/View/ViewHandlerOfT.Tizen.cs @@ -36,6 +36,12 @@ public abstract partial class ViewHandler : INativeVi Dispose(disposing: false); } + public override bool NeedsContainer => + VirtualView?.Background != null || + VirtualView?.Clip != null || + VirtualView?.Shadow != null || + base.NeedsContainer; + public override void NativeArrange(Rectangle frame) { if (NativeParent == null) diff --git a/src/Core/src/Platform/Tizen/IWrapperViewCanvas.cs b/src/Core/src/Platform/Tizen/IWrapperViewCanvas.cs new file mode 100644 index 000000000000..8c203a2666c4 --- /dev/null +++ b/src/Core/src/Platform/Tizen/IWrapperViewCanvas.cs @@ -0,0 +1,8 @@ + +namespace Microsoft.Maui +{ + public interface IWrapperViewCanvas + { + public IWrapperViewDrawables Drawables { get; } + } +} \ No newline at end of file diff --git a/src/Core/src/Platform/Tizen/IWrapperViewDrawables.cs b/src/Core/src/Platform/Tizen/IWrapperViewDrawables.cs new file mode 100644 index 000000000000..5e11b1cd66e8 --- /dev/null +++ b/src/Core/src/Platform/Tizen/IWrapperViewDrawables.cs @@ -0,0 +1,13 @@ +using Microsoft.Maui.Graphics; + +namespace Microsoft.Maui +{ + public interface IWrapperViewDrawables : IDrawable + { + IDrawable? ShadowDrawable { get; set; } + + IDrawable? BackgroundDrawable { get; set; } + + IDrawable? BorderDrawable { get; set; } + } +} diff --git a/src/Core/src/Platform/Tizen/ViewExtensions.cs b/src/Core/src/Platform/Tizen/ViewExtensions.cs index b7f400f0efb3..5e11dd9e4b7f 100644 --- a/src/Core/src/Platform/Tizen/ViewExtensions.cs +++ b/src/Core/src/Platform/Tizen/ViewExtensions.cs @@ -40,9 +40,9 @@ public static bool ToNativeVisibility(this Visibility visibility) public static void UpdateBackground(this EvasObject nativeView, IView view) { - if (nativeView is IBackgroundCanvas canvas) + if (nativeView is IWrapperViewCanvas canvas) { - canvas.BackgroundCanvas.Drawable = view.Background?.ToDrawable() ?? null; + canvas.Drawables.BackgroundDrawable = view.Background?.ToDrawable() ?? null; } else { diff --git a/src/Core/src/Platform/Tizen/WrapperView.cs b/src/Core/src/Platform/Tizen/WrapperView.cs index 65d2faf02527..bcf4379c507d 100644 --- a/src/Core/src/Platform/Tizen/WrapperView.cs +++ b/src/Core/src/Platform/Tizen/WrapperView.cs @@ -10,22 +10,23 @@ namespace Microsoft.Maui { - public interface IBackgroundCanvas + public partial class WrapperView : Canvas, IWrapperViewCanvas { - public SkiaGraphicsView BackgroundCanvas { get; } - } - - public partial class WrapperView : Canvas, IBackgroundCanvas - { - Lazy _backgroundCanvas; + Lazy _drawableCanvas; Lazy _clipperView; EvasObject? _content; public WrapperView(EvasObject parent) : base(parent) { - _backgroundCanvas = new Lazy(() => + _drawableCanvas = new Lazy(() => { var view = new SkiaGraphicsView(parent); + var _drawables = new WrapperViewDrawables(); + _drawables.Invalidated += (s, e) => + { + view.Invalidate(); + }; + view.Drawable = _drawables; view.Show(); Children.Add(view); view.Lower(); @@ -74,22 +75,22 @@ void OnClipPaint(object? sender, DrawClipEventArgs e) canvas.FillPath(clipPath); Content?.SetClipperCanvas(_clipperView.Value); - if (_backgroundCanvas.IsValueCreated) + if (_drawableCanvas.IsValueCreated) { - BackgroundCanvas.SetClipperCanvas(_clipperView.Value); + _drawableCanvas.Value.SetClipperCanvas(_clipperView.Value); } } - void OnLayout(object? sender, Tizen.UIExtensions.Common.LayoutEventArgs e) + void OnLayout(object? sender, LayoutEventArgs e) { if (Content != null) { Content.Geometry = Geometry; } - if (_backgroundCanvas.IsValueCreated) + if (_drawableCanvas.IsValueCreated) { - _backgroundCanvas.Value.Geometry = Geometry; + _drawableCanvas.Value.Geometry = Geometry; } if (_clipperView.IsValueCreated) @@ -122,7 +123,13 @@ void OnLayout(object? sender, Tizen.UIExtensions.Common.LayoutEventArgs e) } - public SkiaGraphicsView BackgroundCanvas => _backgroundCanvas.Value; + public IWrapperViewDrawables Drawables + { + get + { + return (_drawableCanvas.Value.Drawable as IWrapperViewDrawables)!; + } + } } public class DrawClipEventArgs : EventArgs diff --git a/src/Core/src/Platform/Tizen/WrapperViewDrawables.cs b/src/Core/src/Platform/Tizen/WrapperViewDrawables.cs new file mode 100644 index 000000000000..888ca9239f61 --- /dev/null +++ b/src/Core/src/Platform/Tizen/WrapperViewDrawables.cs @@ -0,0 +1,65 @@ +using System; +using Microsoft.Maui.Graphics; + +namespace Microsoft.Maui +{ + public class WrapperViewDrawables : IWrapperViewDrawables + { + public event EventHandler? Invalidated; + + IDrawable? _shadowDrawable; + IDrawable? _backgroundDrawable; + IDrawable? _borderDrawable; + + public IDrawable? ShadowDrawable + { + get + { + return _shadowDrawable; + } + set + { + _shadowDrawable = value; + SendInvalidated(); + } + } + + public IDrawable? BackgroundDrawable + { + get + { + return _backgroundDrawable; + } + set + { + _backgroundDrawable = value; + SendInvalidated(); + } + } + + public IDrawable? BorderDrawable + { + get + { + return _borderDrawable; + } + set + { + _borderDrawable = value; + SendInvalidated(); + } + } + + public void Draw(ICanvas canvas, RectangleF dirtyRect) + { + _shadowDrawable?.Draw(canvas, dirtyRect); + _backgroundDrawable?.Draw(canvas, dirtyRect); + _borderDrawable?.Draw(canvas, dirtyRect); + } + + public void SendInvalidated() + { + Invalidated?.Invoke(this, EventArgs.Empty); + } + } +}