diff --git a/src/Controls/samples/Controls.Sample/Pages/Controls/ButtonPage.xaml b/src/Controls/samples/Controls.Sample/Pages/Controls/ButtonPage.xaml
index 7187ddd0ae0b..b27fc3614b97 100644
--- a/src/Controls/samples/Controls.Sample/Pages/Controls/ButtonPage.xaml
+++ b/src/Controls/samples/Controls.Sample/Pages/Controls/ButtonPage.xaml
@@ -57,6 +57,26 @@
+
+
diff --git a/src/Core/src/Handlers/View/ViewHandler.iOS.cs b/src/Core/src/Handlers/View/ViewHandler.iOS.cs
index 5cc4952e1078..5e7ce18bba75 100644
--- a/src/Core/src/Handlers/View/ViewHandler.iOS.cs
+++ b/src/Core/src/Handlers/View/ViewHandler.iOS.cs
@@ -55,7 +55,9 @@ internal static void MapContextFlyout(IElementHandler handler, IContextFlyoutEle
static partial void MappingFrame(IViewHandler handler, IView view)
{
UpdateTransformation(handler, view);
- handler.ToPlatform().UpdateBackgroundLayerFrame();
+
+ if (view.Background is not null)
+ handler.ToPlatform().UpdateBackgroundLayerFrame();
}
public static void MapTranslationX(IViewHandler handler, IView view)
diff --git a/src/Core/src/Platform/iOS/ViewExtensions.cs b/src/Core/src/Platform/iOS/ViewExtensions.cs
index 7c486f1ce997..d524d91b7838 100644
--- a/src/Core/src/Platform/iOS/ViewExtensions.cs
+++ b/src/Core/src/Platform/iOS/ViewExtensions.cs
@@ -268,15 +268,17 @@ public static void UpdateBackgroundLayerFrame(this UIView view)
var layer = view.Layer;
- UpdateBackgroundLayerFrame(layer, view.Bounds);
+ UpdateBackgroundLayerFrame(layer, view.Bounds, view is WrapperView);
}
- static void UpdateBackgroundLayerFrame(CALayer layer, CGRect bounds)
+ static void UpdateBackgroundLayerFrame(CALayer layer, CGRect bounds, bool getAllSubLayers)
{
if (layer == null || layer.Sublayers == null || layer.Sublayers.Length == 0)
return;
- foreach (var sublayer in layer.Sublayers)
+ IEnumerable subLayers = getAllSubLayers ? layer.GetLayers() : layer.Sublayers;
+
+ foreach (var sublayer in subLayers)
{
if (sublayer.Name == BackgroundLayerName && sublayer.Frame != bounds)
{
@@ -284,7 +286,25 @@ static void UpdateBackgroundLayerFrame(CALayer layer, CGRect bounds)
break;
}
- UpdateBackgroundLayerFrame(sublayer, bounds);
+ UpdateBackgroundLayerFrame(sublayer, bounds, getAllSubLayers);
+ }
+ }
+
+ static IEnumerable GetLayers(this CALayer root)
+ {
+ var stack = new Stack();
+ stack.Push(root);
+
+ while (stack.Count > 0)
+ {
+ var current = stack.Pop();
+ yield return current;
+
+ if (current.Sublayers is not null)
+ {
+ foreach (var child in current.Sublayers)
+ stack.Push(child);
+ }
}
}
diff --git a/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.iOS.cs b/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.iOS.cs
index 4faa5ca36d2e..ff792c8dec2e 100644
--- a/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.iOS.cs
+++ b/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.iOS.cs
@@ -57,6 +57,42 @@ public async Task ValidateDefaultAccessibilityTraits()
Assert.Equal(UIAccessibilityTrait.Button, trait);
}
+ [Theory]
+ [InlineData(null)]
+ [InlineData("#FF0000")]
+ [InlineData("#00FF00")]
+ [InlineData("#0000FF")]
+ [InlineData("#000000")]
+ public async Task BackgroundWithShadowRenderCorrectly(string colorHex)
+ {
+ var expectedColor = Color.FromArgb(colorHex);
+
+ var button = new ButtonStub
+ {
+ Text = "Test",
+ Background = new SolidPaintStub(expectedColor),
+ Shadow = new ShadowStub
+ {
+ Paint = new SolidPaintStub(Colors.Black),
+ Offset = new Point(10, 10),
+ Opacity = 1.0f,
+ Radius = 2.0f
+ }
+ };
+
+ var handler = await CreateHandlerAsync(button);
+
+ await InvokeOnMainThreadAsync(async () =>
+ {
+ await handler.PlatformView.AttachAndRun(async () =>
+ {
+ handler.UpdateValue(nameof(IButton.Background));
+
+ await handler.PlatformView.AssertContainsColor(expectedColor);
+ });
+ });
+ }
+
bool ImageSourceLoaded(ButtonHandler buttonHandler) =>
buttonHandler.PlatformView.ImageView.Image != null;