Skip to content

Commit

Permalink
feat(elevatedview): Added support for macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
carldebilly committed Jul 17, 2020
1 parent cc8cf32 commit df31c10
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/Uno.UI.Toolkit/ElevatedView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,13 @@ private void UpdateElevation()
#if __WASM__
this.SetElevationInternal(Elevation, ShadowColor);
this.SetCornerRadius(CornerRadius);
#elif __IOS__
#elif __IOS__ || __MACOS__
this.SetElevationInternal(Elevation, ShadowColor, _border.BoundsPath);
#elif __ANDROID__
_border.SetElevationInternal(Elevation, ShadowColor);
#elif NETFX_CORE
(ElevatedContent as DependencyObject).SetElevationInternal(Elevation, ShadowColor, _shadowHost as DependencyObject, CornerRadius);
#endif
// TODO: MacOS
}
}

Expand Down
22 changes: 17 additions & 5 deletions src/Uno.UI.Toolkit/UIElementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static double GetElevation(this UIElement element)
}
}

#if __IOS__
#if __IOS__ || __MACOS__
internal static void SetElevationInternal(this DependencyObject element, double elevation, Color shadowColor, CGPath path = null)
#elif NETFX_CORE
internal static void SetElevationInternal(this DependencyObject element, double elevation, Color shadowColor, DependencyObject host = null, CornerRadius cornerRadius = default(CornerRadius))
Expand All @@ -72,8 +72,12 @@ internal static void SetElevationInternal(this DependencyObject element, double
view.SetOutlineSpotShadowColor(shadowColor);
#endif
}
#elif __IOS__
#elif __IOS__ || __MACOS__
#if __MACOS__
if (element is AppKit.NSView view)
#else
if (element is UIKit.UIView view)
#endif
{
if (elevation > 0)
{
Expand All @@ -82,14 +86,22 @@ internal static void SetElevationInternal(this DependencyObject element, double
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 = shadowColor.A / 255f;
#if __MACOS__
view.Layer.ShadowColor = AppKit.NSColor.FromRgb(shadowColor.R, shadowColor.G, shadowColor.B).CGColor;
#else
view.Layer.ShadowColor = UIKit.UIColor.FromRGB(shadowColor.R, shadowColor.G, shadowColor.B).CGColor;
#endif
view.Layer.ShadowRadius = (nfloat)(blur * elevation);
view.Layer.ShadowOffset = new CoreGraphics.CGSize(x * elevation, y * elevation);
view.Layer.ShadowPath = path;
}
else
else if(view.Layer != null)
{
view.Layer.ShadowOpacity = 0;
}
Expand Down Expand Up @@ -170,9 +182,9 @@ internal static void SetElevationInternal(this DependencyObject element, double
ElementCompositionPreview.SetElementChildVisual(uiHost, spriteVisual);
}
#endif
}
}

#endregion
#endregion

internal static Thickness GetPadding(this UIElement uiElement)
{
Expand Down

0 comments on commit df31c10

Please sign in to comment.