Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue29325.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/Core/src/Platform/Android/WrapperView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down