Skip to content

Commit 145b0cd

Browse files
NanthiniMahalingamPureWeen
authored andcommitted
[Android] Fixed Button Shadow Color Transparency Not Applied Correctly (#29371)
* Fixed the shadow transparent issue on android * Updated the fix. * Added the test case and updated the fix * Added the output images. * Updated the fix. * Updated the comment. * Added the output images for mac and Windows * Updated the test case and added output images. * Added the output images
1 parent 131c72b commit 145b0cd

File tree

7 files changed

+107
-1
lines changed

7 files changed

+107
-1
lines changed
108 KB
Loading
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
3+
[Issue(IssueTracker.Github, 29325, "Button Shadow Color Transparency Not Applied Correctly", PlatformAffected.Android)]
4+
public class Issue29325 : ContentPage
5+
{
6+
public Issue29325()
7+
{
8+
var verticalStackLayout = new VerticalStackLayout();
9+
10+
var withoutAlphaOpacityButton = new Button
11+
{
12+
AutomationId = "withoutAlphaOpacityButton",
13+
HorizontalOptions = LayoutOptions.Center,
14+
VerticalOptions = LayoutOptions.Center,
15+
Text = "Button shadow color no Alpha nor opacity",
16+
Shadow = new Shadow
17+
{
18+
Brush = Colors.Blue,
19+
Offset = new Point(0, 12),
20+
Radius = 12,
21+
}
22+
};
23+
24+
var alphaButton = new Button
25+
{
26+
AutomationId = "alphaButton",
27+
HorizontalOptions = LayoutOptions.Center,
28+
VerticalOptions = LayoutOptions.Center,
29+
Text = "Button shadow color with Alpha",
30+
Margin = new Thickness(0, 50, 0, 0),
31+
Shadow = new Shadow
32+
{
33+
Brush = Colors.Blue.WithAlpha(0.4f),
34+
Offset = new Point(0, 12),
35+
Radius = 12,
36+
}
37+
};
38+
39+
var opacityButton = new Button
40+
{
41+
AutomationId = "opacityButton",
42+
HorizontalOptions = LayoutOptions.Center,
43+
VerticalOptions = LayoutOptions.Center,
44+
Text = "Button shadow color with opacity",
45+
Margin = new Thickness(0, 50, 0, 0),
46+
Shadow = new Shadow
47+
{
48+
Brush = Colors.Blue,
49+
Offset = new Point(0, 12),
50+
Radius = 12,
51+
Opacity = 0.4f
52+
}
53+
};
54+
55+
var alphaOpacityButton = new Button
56+
{
57+
AutomationId = "alphaOpacityButton",
58+
HorizontalOptions = LayoutOptions.Center,
59+
VerticalOptions = LayoutOptions.Center,
60+
Text = "Button shadow color with alpha and opacity",
61+
Margin = new Thickness(0, 50, 0, 0),
62+
Shadow = new Shadow
63+
{
64+
Brush = Colors.Blue.WithAlpha(0.4f),
65+
Offset = new Point(0, 12),
66+
Radius = 12,
67+
Opacity = 0.4f
68+
}
69+
};
70+
71+
// Add the Button to the VerticalStackLayout
72+
verticalStackLayout.Children.Add(withoutAlphaOpacityButton);
73+
verticalStackLayout.Children.Add(alphaButton);
74+
verticalStackLayout.Children.Add(opacityButton);
75+
verticalStackLayout.Children.Add(alphaOpacityButton);
76+
77+
// Set the Content of the page
78+
Content = verticalStackLayout;
79+
}
80+
}
26.1 KB
Loading
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues;
6+
7+
public class Issue29325 : _IssuesUITest
8+
{
9+
public Issue29325(TestDevice device) : base(device) { }
10+
11+
public override string Issue => "Button Shadow Color Transparency Not Applied Correctly";
12+
13+
[Test]
14+
[Category(UITestCategories.Button)]
15+
public void ShouldUpdateButtonShadowWithTransparentColor()
16+
{
17+
App.WaitForElement("withoutAlphaOpacityButton");
18+
App.WaitForElement("alphaButton");
19+
App.WaitForElement("opacityButton");
20+
App.WaitForElement("alphaOpacityButton");
21+
VerifyScreenshot();
22+
}
23+
}
23.3 KB
Loading
82.8 KB
Loading

src/Core/src/Platform/Android/WrapperView.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ partial void ShadowChanged()
9090
break;
9191
case SolidPaint solidPaint:
9292
paintType = PlatformPaintType.Solid;
93-
colors = [solidPaint.Color.WithAlpha(shadowOpacity).ToPlatform().ToArgb()];
93+
// If the alpha is set in the color value, the shadow transparency is applied based on that alpha.
94+
// If the Opacity property is set directly, the shadow transparency is applied based on the Opacity.
95+
// 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.
96+
colors = [solidPaint.Color.WithAlpha(solidPaint.Color.Alpha * shadowOpacity).ToPlatform().ToArgb()];
9497
positions = null;
9598
bounds = null;
9699
break;

0 commit comments

Comments
 (0)