Skip to content

Commit

Permalink
Fix issue not rendering Border background using a Shadow (#7695)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuarezruiz authored Jun 21, 2022
1 parent 3a609bf commit 630cdcd
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/Core/src/Handlers/Border/BorderHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ protected override ContentView CreatePlatformView()
};
}

protected override void ConnectHandler(ContentView platformView)
{
base.ConnectHandler(platformView);

platformView.LayoutSubviewsChanged += OnLayoutSubviewsChanged;
}

protected override void DisconnectHandler(ContentView platformView)
{
base.DisconnectHandler(platformView);

platformView.LayoutSubviewsChanged -= OnLayoutSubviewsChanged;
}

public override void SetVirtualView(IView view)
{
base.SetVirtualView(view);
Expand Down Expand Up @@ -47,5 +61,10 @@ public static void MapContent(IBorderHandler handler, IBorderView border)
{
UpdateContent(handler);
}

void OnLayoutSubviewsChanged(object? sender, EventArgs e)
{
PlatformView?.UpdateMauiCALayer();
}
}
}
4 changes: 4 additions & 0 deletions src/Core/src/Platform/iOS/ContentView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace Microsoft.Maui.Platform
{
public class ContentView : MauiView
{
internal event EventHandler? LayoutSubviewsChanged;

public override CGSize SizeThatFits(CGSize size)
{
if (CrossPlatformMeasure == null)
Expand All @@ -29,6 +31,8 @@ public override void LayoutSubviews()

CrossPlatformMeasure?.Invoke(bounds.Width, bounds.Height);
CrossPlatformArrange?.Invoke(bounds);

LayoutSubviewsChanged?.Invoke(this, EventArgs.Empty);
}

public override void SetNeedsLayout()
Expand Down
34 changes: 31 additions & 3 deletions src/Core/src/Platform/iOS/StrokeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Linq;
using CoreAnimation;
using Microsoft.Maui.Graphics;
using ObjCRuntime;
using CoreGraphics;
using UIKit;

namespace Microsoft.Maui.Platform
Expand Down Expand Up @@ -125,21 +125,49 @@ internal static void UpdateMauiCALayer(this UIView platformView, IBorderStroke?
if (backgroundLayer is MauiCALayer mauiCALayer)
{
backgroundLayer.Frame = platformView.Bounds;
if (border is IView v)
mauiCALayer.SetBackground(v.Background);

if (border is IView view)
mauiCALayer.SetBackground(view.Background);
else
mauiCALayer.SetBackground(new SolidPaint(Colors.Transparent));

mauiCALayer.SetBorderBrush(border?.Stroke);
mauiCALayer.SetBorderWidth(border?.StrokeThickness ?? 0);
mauiCALayer.SetBorderDash(border?.StrokeDashPattern, border?.StrokeDashOffset ?? 0);
mauiCALayer.SetBorderMiterLimit(border?.StrokeMiterLimit ?? 0);

if (border != null)
{
mauiCALayer.SetBorderLineJoin(border.StrokeLineJoin);
mauiCALayer.SetBorderLineCap(border.StrokeLineCap);
}

mauiCALayer.SetBorderShape(border?.Shape);
}
}

internal static void UpdateMauiCALayer(this UIView view)
{
if (view == null || view.Frame.IsEmpty)
return;

var layer = view.Layer;

UpdateBackgroundLayer(layer, view.Bounds);
}

static void UpdateBackgroundLayer(this CALayer layer, CGRect bounds)
{
if (layer != null && layer.Sublayers != null)
{
foreach (var sublayer in layer.Sublayers)
{
UpdateBackgroundLayer(sublayer, bounds);

if (sublayer.Name == ViewExtensions.BackgroundLayerName && sublayer.Frame != bounds)
sublayer.Frame = bounds;
}
}
}
}
}
2 changes: 2 additions & 0 deletions src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#nullable enable
override Microsoft.Maui.Handlers.BorderHandler.ConnectHandler(Microsoft.Maui.Platform.ContentView! platformView) -> void
override Microsoft.Maui.Handlers.BorderHandler.DisconnectHandler(Microsoft.Maui.Platform.ContentView! platformView) -> void
override Microsoft.Maui.Platform.ContentView.SetNeedsLayout() -> void
override Microsoft.Maui.Platform.LayoutView.HitTest(CoreGraphics.CGPoint point, UIKit.UIEvent? uievent) -> UIKit.UIView!
override Microsoft.Maui.Platform.LayoutView.SetNeedsLayout() -> void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#nullable enable
override Microsoft.Maui.Handlers.BorderHandler.ConnectHandler(Microsoft.Maui.Platform.ContentView! platformView) -> void
override Microsoft.Maui.Handlers.BorderHandler.DisconnectHandler(Microsoft.Maui.Platform.ContentView! platformView) -> void
override Microsoft.Maui.Platform.ContentView.SetNeedsLayout() -> void
override Microsoft.Maui.Platform.LayoutView.HitTest(CoreGraphics.CGPoint point, UIKit.UIEvent? uievent) -> UIKit.UIView!
override Microsoft.Maui.Platform.LayoutView.SetNeedsLayout() -> void
Expand Down

0 comments on commit 630cdcd

Please sign in to comment.