-
Notifications
You must be signed in to change notification settings - Fork 18
/
PinItemViewRenderer.cs
99 lines (88 loc) · 3.38 KB
/
PinItemViewRenderer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System.ComponentModel;
using CoreGraphics;
using FormsPinView.Core;
using FormsPinView.iOS;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(PinItemView), typeof(PinItemViewRenderer))]
namespace FormsPinView.iOS
{
/// <summary>
/// <see cref="PinItemView"/> renderer.
/// </summary>
public class PinItemViewRenderer : ViewRenderer<PinItemView, UIView>
{
private ZFRippleButton _button;
public static new void Init()
{
_ = typeof(PinItemViewRenderer);
_ = typeof(CircleViewRenderer);
}
protected override void OnElementChanged(ElementChangedEventArgs<PinItemView> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
}
if (e.NewElement != null)
{
if (Control == null)
{
_button = new ZFRippleButton(new CGRect(0, 0, 44, 44));
_button.BackgroundColor = UIColor.Clear;
_button.SetTitle(Element.Text, UIControlState.Normal);
_button.SetTitleColor(Element.Color.ToUIColor(), UIControlState.Normal);
_button.ClipsToBounds = true;
_button.Layer.CornerRadius = _button.Bounds.Size.Height / 2;
_button.Layer.BorderColor = Element.BorderColor.ToCGColor();
_button.Layer.BorderWidth = 1f;
_button.RippleColor
= _button.RippleBackgroundColor
= Element.RippleColor.ToUIColor();
_button.RippleOverBounds = true;
_button.ShadowRippleEnable = true;
_button.ShadowRippleRadius = 32;
_button.RipplePercent = 1;
_button.TouchUpInside += (sender, args) =>
{
Element?.Command?.Execute(Element?.CommandParameter);
};
UIView uiView = new UIView();
uiView.AddSubview(_button);
uiView.SizeToFit();
SetNativeControl(uiView);
}
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (_button != null)
{
if (e.PropertyName == PinItemView.ColorProperty.PropertyName)
{
_button.SetTitleColor(Element.Color.ToUIColor(), UIControlState.Normal);
return;
}
else if (e.PropertyName == PinItemView.BorderColorProperty.PropertyName)
{
_button.Layer.BorderColor = Element.BorderColor.ToCGColor();
return;
}
else if (e.PropertyName == PinItemView.RippleColorProperty.PropertyName)
{
_button.RippleColor
= _button.RippleBackgroundColor
= Element.RippleColor.ToUIColor();
return;
}
}
base.OnElementPropertyChanged(sender, e);
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
_button.Center = Control.Center;
}
}
}