diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ShouldUpdateButtonShadowWithTransparentColor.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ShouldUpdateButtonShadowWithTransparentColor.png new file mode 100644 index 000000000000..0b0a20f21c8d Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ShouldUpdateButtonShadowWithTransparentColor.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue29325.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue29325.cs new file mode 100644 index 000000000000..f9ef82fb9a60 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue29325.cs @@ -0,0 +1,80 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 29325, "Button Shadow Color Transparency Not Applied Correctly", PlatformAffected.Android)] +public class Issue29325 : ContentPage +{ + public Issue29325() + { + var verticalStackLayout = new VerticalStackLayout(); + + var withoutAlphaOpacityButton = new Button + { + AutomationId = "withoutAlphaOpacityButton", + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center, + Text = "Button shadow color no Alpha nor opacity", + Shadow = new Shadow + { + Brush = Colors.Blue, + Offset = new Point(0, 12), + Radius = 12, + } + }; + + var alphaButton = new Button + { + AutomationId = "alphaButton", + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center, + Text = "Button shadow color with Alpha", + Margin = new Thickness(0, 50, 0, 0), + Shadow = new Shadow + { + Brush = Colors.Blue.WithAlpha(0.4f), + Offset = new Point(0, 12), + Radius = 12, + } + }; + + var opacityButton = new Button + { + AutomationId = "opacityButton", + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center, + Text = "Button shadow color with opacity", + Margin = new Thickness(0, 50, 0, 0), + Shadow = new Shadow + { + Brush = Colors.Blue, + Offset = new Point(0, 12), + Radius = 12, + Opacity = 0.4f + } + }; + + var alphaOpacityButton = new Button + { + AutomationId = "alphaOpacityButton", + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center, + Text = "Button shadow color with alpha and opacity", + Margin = new Thickness(0, 50, 0, 0), + Shadow = new Shadow + { + Brush = Colors.Blue.WithAlpha(0.4f), + Offset = new Point(0, 12), + Radius = 12, + Opacity = 0.4f + } + }; + + // Add the Button to the VerticalStackLayout + verticalStackLayout.Children.Add(withoutAlphaOpacityButton); + verticalStackLayout.Children.Add(alphaButton); + verticalStackLayout.Children.Add(opacityButton); + verticalStackLayout.Children.Add(alphaOpacityButton); + + // Set the Content of the page + Content = verticalStackLayout; + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ShouldUpdateButtonShadowWithTransparentColor.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ShouldUpdateButtonShadowWithTransparentColor.png new file mode 100644 index 000000000000..bfe0a412263e Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ShouldUpdateButtonShadowWithTransparentColor.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29325.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29325.cs new file mode 100644 index 000000000000..dfd8fcdd1385 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29325.cs @@ -0,0 +1,23 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue29325 : _IssuesUITest +{ + public Issue29325(TestDevice device) : base(device) { } + + public override string Issue => "Button Shadow Color Transparency Not Applied Correctly"; + + [Test] + [Category(UITestCategories.Button)] + public void ShouldUpdateButtonShadowWithTransparentColor() + { + App.WaitForElement("withoutAlphaOpacityButton"); + App.WaitForElement("alphaButton"); + App.WaitForElement("opacityButton"); + App.WaitForElement("alphaOpacityButton"); + VerifyScreenshot(); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ShouldUpdateButtonShadowWithTransparentColor.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ShouldUpdateButtonShadowWithTransparentColor.png new file mode 100644 index 000000000000..3f055d1db343 Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ShouldUpdateButtonShadowWithTransparentColor.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ShouldUpdateButtonShadowWithTransparentColor.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ShouldUpdateButtonShadowWithTransparentColor.png new file mode 100644 index 000000000000..cea0fcf3d426 Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ShouldUpdateButtonShadowWithTransparentColor.png differ diff --git a/src/Core/src/Platform/Android/WrapperView.cs b/src/Core/src/Platform/Android/WrapperView.cs index 17a911049883..d426a3a28eee 100644 --- a/src/Core/src/Platform/Android/WrapperView.cs +++ b/src/Core/src/Platform/Android/WrapperView.cs @@ -90,7 +90,10 @@ partial void ShadowChanged() break; case SolidPaint solidPaint: paintType = PlatformPaintType.Solid; - colors = [solidPaint.Color.WithAlpha(shadowOpacity).ToPlatform().ToArgb()]; + // If the alpha is set in the color value, the shadow transparency is applied based on that alpha. + // If the Opacity property is set directly, the shadow transparency is applied based on the Opacity. + // If both values are provided, the color alpha is combined with the Opacity to apply a unified transparency effect to the shadow, ensuring consistent behavior across platforms. + colors = [solidPaint.Color.WithAlpha(solidPaint.Color.Alpha * shadowOpacity).ToPlatform().ToArgb()]; positions = null; bounds = null; break;