Skip to content

Commit

Permalink
feat: ThemeShadow support on iOS/macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Feb 3, 2023
1 parent bfaca1f commit adfc824
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/Uno.UI/UI/Xaml/Media/ThemeShadowManager.iOSmacOS.cs
@@ -0,0 +1,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?
}
}
}
}

0 comments on commit adfc824

Please sign in to comment.