-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
ShadowEffect.cs
51 lines (44 loc) · 1.57 KB
/
ShadowEffect.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
using System;
using System.ComponentModel;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Graphics;
using UIKit;
using PlatformElement = Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.VisualElement;
namespace Microsoft.Maui.Controls.Compatibility.Platform.iOS
{
[Preserve(AllMembers = true)]
internal class ShadowEffect : PlatformEffect
{
UIView ShadowView => Control ?? Container;
protected override void OnAttached() => UpdateShadow();
protected override void OnDetached()
{
var layer = ShadowView.Layer;
if (layer != null)
{
layer.ShadowColor = Colors.Transparent.ToCGColor();
layer.ShadowOpacity = 0;
}
}
protected override void OnElementPropertyChanged(PropertyChangedEventArgs args)
{
if (args.PropertyName == PlatformElement.IsShadowEnabledProperty.PropertyName ||
args.PropertyName == PlatformElement.ShadowColorProperty.PropertyName ||
args.PropertyName == PlatformElement.ShadowOffsetProperty.PropertyName ||
args.PropertyName == PlatformElement.ShadowRadiusProperty.PropertyName ||
args.PropertyName == PlatformElement.ShadowOpacityProperty.PropertyName)
{
UpdateShadow();
}
}
private void UpdateShadow()
{
var layer = ShadowView.Layer;
layer.ShadowColor = PlatformElement.GetShadowColor(Element).ToCGColor();
layer.ShadowOffset = PlatformElement.GetShadowOffset(Element).ToSizeF();
layer.ShadowRadius = (nfloat)PlatformElement.GetShadowRadius(Element);
layer.ShadowOpacity = (float)PlatformElement.GetShadowOpacity(Element);
}
}
}