-
Notifications
You must be signed in to change notification settings - Fork 691
/
ThemeShadowManager.iOSmacOS.cs
54 lines (49 loc) · 1.37 KB
/
ThemeShadowManager.iOSmacOS.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
using System;
using Windows.UI.Xaml;
namespace Uno.UI.Xaml.Media
{
internal static partial class ThemeShadowManager
{
static partial void UnsetShadow(UIElement uiElement)
{
var translation = uiElement.Translation;
#if __MACOS__
if (uiElement is AppKit.NSView view)
#else
if (uiElement is UIKit.UIView view)
#endif
{
view.Layer.ShadowOpacity = 0;
}
}
static partial void SetShadow(UIElement uiElement)
{
var translation = uiElement.Translation;
#if __MACOS__
if (uiElement is AppKit.NSView view)
#else
if (uiElement is UIKit.UIView view)
#endif
{
// Values for 1dp elevation according to https://material.io/guidelines/resources/shadows.html#shadows-illustrator
const float x = 0.25f;
const float y = 0.92f * 0.5f; // Looks more accurate than the recommended 0.92f.
const float blur = 0.5f;
#if __MACOS__
view.WantsLayer = true;
view.Shadow ??= new AppKit.NSShadow();
#endif
view.Layer.MasksToBounds = false;
view.Layer.ShadowOpacity = 1;
#if __MACOS__
view.Layer.ShadowColor = AppKit.NSColor.Black.CGColor;
#else
view.Layer.ShadowColor = UIKit.UIColor.Black.CGColor;
#endif
view.Layer.ShadowRadius = (nfloat)(blur * translation.Z);
view.Layer.ShadowOffset = new CoreGraphics.CGSize(x * translation.Z, y * translation.Z);
//view.Layer.ShadowPath = path; - needed for rounded corners?
}
}
}
}