Skip to content

Commit d30c1a3

Browse files
JoonghyunChorookiejava
authored andcommitted
Refactor WrapperView to draw drawable features (#186)
* Refactor WrapperView to draw drawable features * Update class names and devide files * Override NeesContainer to remove duplicated code * Update class names
1 parent 2ae5c7c commit d30c1a3

File tree

6 files changed

+115
-16
lines changed

6 files changed

+115
-16
lines changed

src/Core/src/Handlers/View/ViewHandlerOfT.Tizen.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ public abstract partial class ViewHandler<TVirtualView, TNativeView> : INativeVi
3636
Dispose(disposing: false);
3737
}
3838

39+
public override bool NeedsContainer =>
40+
VirtualView?.Background != null ||
41+
VirtualView?.Clip != null ||
42+
VirtualView?.Shadow != null ||
43+
base.NeedsContainer;
44+
3945
public override void NativeArrange(Rectangle frame)
4046
{
4147
if (NativeParent == null)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+

2+
namespace Microsoft.Maui
3+
{
4+
public interface IWrapperViewCanvas
5+
{
6+
public IWrapperViewDrawables Drawables { get; }
7+
}
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Microsoft.Maui.Graphics;
2+
3+
namespace Microsoft.Maui
4+
{
5+
public interface IWrapperViewDrawables : IDrawable
6+
{
7+
IDrawable? ShadowDrawable { get; set; }
8+
9+
IDrawable? BackgroundDrawable { get; set; }
10+
11+
IDrawable? BorderDrawable { get; set; }
12+
}
13+
}

src/Core/src/Platform/Tizen/ViewExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public static bool ToNativeVisibility(this Visibility visibility)
4040

4141
public static void UpdateBackground(this EvasObject nativeView, IView view)
4242
{
43-
if (nativeView is IBackgroundCanvas canvas)
43+
if (nativeView is IWrapperViewCanvas canvas)
4444
{
45-
canvas.BackgroundCanvas.Drawable = view.Background?.ToDrawable() ?? null;
45+
canvas.Drawables.BackgroundDrawable = view.Background?.ToDrawable() ?? null;
4646
}
4747
else
4848
{

src/Core/src/Platform/Tizen/WrapperView.cs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,23 @@
1010

1111
namespace Microsoft.Maui
1212
{
13-
public interface IBackgroundCanvas
13+
public partial class WrapperView : Canvas, IWrapperViewCanvas
1414
{
15-
public SkiaGraphicsView BackgroundCanvas { get; }
16-
}
17-
18-
public partial class WrapperView : Canvas, IBackgroundCanvas
19-
{
20-
Lazy<SkiaGraphicsView> _backgroundCanvas;
15+
Lazy<SkiaGraphicsView> _drawableCanvas;
2116
Lazy<SKClipperView> _clipperView;
2217
EvasObject? _content;
2318

2419
public WrapperView(EvasObject parent) : base(parent)
2520
{
26-
_backgroundCanvas = new Lazy<SkiaGraphicsView>(() =>
21+
_drawableCanvas = new Lazy<SkiaGraphicsView>(() =>
2722
{
2823
var view = new SkiaGraphicsView(parent);
24+
var _drawables = new WrapperViewDrawables();
25+
_drawables.Invalidated += (s, e) =>
26+
{
27+
view.Invalidate();
28+
};
29+
view.Drawable = _drawables;
2930
view.Show();
3031
Children.Add(view);
3132
view.Lower();
@@ -74,22 +75,22 @@ void OnClipPaint(object? sender, DrawClipEventArgs e)
7475

7576
canvas.FillPath(clipPath);
7677
Content?.SetClipperCanvas(_clipperView.Value);
77-
if (_backgroundCanvas.IsValueCreated)
78+
if (_drawableCanvas.IsValueCreated)
7879
{
79-
BackgroundCanvas.SetClipperCanvas(_clipperView.Value);
80+
_drawableCanvas.Value.SetClipperCanvas(_clipperView.Value);
8081
}
8182
}
8283

83-
void OnLayout(object? sender, Tizen.UIExtensions.Common.LayoutEventArgs e)
84+
void OnLayout(object? sender, LayoutEventArgs e)
8485
{
8586
if (Content != null)
8687
{
8788
Content.Geometry = Geometry;
8889
}
8990

90-
if (_backgroundCanvas.IsValueCreated)
91+
if (_drawableCanvas.IsValueCreated)
9192
{
92-
_backgroundCanvas.Value.Geometry = Geometry;
93+
_drawableCanvas.Value.Geometry = Geometry;
9394
}
9495

9596
if (_clipperView.IsValueCreated)
@@ -122,7 +123,13 @@ public EvasObject? Content
122123

123124
}
124125

125-
public SkiaGraphicsView BackgroundCanvas => _backgroundCanvas.Value;
126+
public IWrapperViewDrawables Drawables
127+
{
128+
get
129+
{
130+
return (_drawableCanvas.Value.Drawable as IWrapperViewDrawables)!;
131+
}
132+
}
126133
}
127134

128135
public class DrawClipEventArgs : EventArgs
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using Microsoft.Maui.Graphics;
3+
4+
namespace Microsoft.Maui
5+
{
6+
public class WrapperViewDrawables : IWrapperViewDrawables
7+
{
8+
public event EventHandler? Invalidated;
9+
10+
IDrawable? _shadowDrawable;
11+
IDrawable? _backgroundDrawable;
12+
IDrawable? _borderDrawable;
13+
14+
public IDrawable? ShadowDrawable
15+
{
16+
get
17+
{
18+
return _shadowDrawable;
19+
}
20+
set
21+
{
22+
_shadowDrawable = value;
23+
SendInvalidated();
24+
}
25+
}
26+
27+
public IDrawable? BackgroundDrawable
28+
{
29+
get
30+
{
31+
return _backgroundDrawable;
32+
}
33+
set
34+
{
35+
_backgroundDrawable = value;
36+
SendInvalidated();
37+
}
38+
}
39+
40+
public IDrawable? BorderDrawable
41+
{
42+
get
43+
{
44+
return _borderDrawable;
45+
}
46+
set
47+
{
48+
_borderDrawable = value;
49+
SendInvalidated();
50+
}
51+
}
52+
53+
public void Draw(ICanvas canvas, RectangleF dirtyRect)
54+
{
55+
_shadowDrawable?.Draw(canvas, dirtyRect);
56+
_backgroundDrawable?.Draw(canvas, dirtyRect);
57+
_borderDrawable?.Draw(canvas, dirtyRect);
58+
}
59+
60+
public void SendInvalidated()
61+
{
62+
Invalidated?.Invoke(this, EventArgs.Empty);
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)