-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Fix LinearGradientBrush rendering as opaque black box #35299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+218 KB
...ests/snapshots/android/LinearGradientBrushTransparentStopsShouldNotBeOpaque.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-817 Bytes
(99%)
...tCases.Android.Tests/snapshots/android/VerifyLinearGradientBrushWithOpacity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-27 KB
(84%)
...droid.Tests/snapshots/android/VerifyLinearGradientBrushWithShadowAndOpacity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-183 Bytes
(100%)
...droid.Tests/snapshots/android/VerifyLinearGradientBrushWithStrokeAndOpacity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-26.8 KB
(83%)
...tCases.Android.Tests/snapshots/android/VerifyRadialGradientBrushWithOpacity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-32.9 KB
(81%)
...droid.Tests/snapshots/android/VerifyRadialGradientBrushWithShadowAndOpacity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
128 changes: 128 additions & 0 deletions
128
src/Controls/tests/TestCases.HostApp/Issues/Issue35280.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| using Microsoft.Maui.Controls; | ||
| using Microsoft.Maui.Controls.Shapes; | ||
| using Microsoft.Maui.Graphics; | ||
|
|
||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 35280, "LinearGradientBrush with transparent stops renders as opaque black box on Android", PlatformAffected.Android)] | ||
| public class Issue35280 : ContentPage | ||
| { | ||
| public Issue35280() | ||
| { | ||
| Label label = new Label | ||
| { | ||
| AutomationId = "DescriptionLabel", | ||
| Text = "The image below should have a gradient overlay that fades from black to transparent. If the image is completely covered by a black box, then the test has failed." | ||
| }; | ||
|
|
||
| var border = new Border | ||
| { | ||
| Stroke = Colors.Transparent, | ||
| Margin = new Thickness(5, 0, 0, 0), | ||
| WidthRequest = 250, | ||
| StrokeShape = new RoundRectangle | ||
| { | ||
| CornerRadius = new CornerRadius(10) | ||
| }, | ||
| Content = new Grid | ||
| { | ||
| Children = | ||
| { | ||
| new Image | ||
| { | ||
| Source = "dotnet_bot.png", | ||
| Aspect = Aspect.AspectFill | ||
| }, | ||
| new VerticalStackLayout | ||
| { | ||
| VerticalOptions = LayoutOptions.End, | ||
| Padding = 10, | ||
| Background = new LinearGradientBrush | ||
| { | ||
| StartPoint = new Point(0, 1), | ||
| EndPoint = new Point(1, 0), | ||
| GradientStops = new GradientStopCollection | ||
| { | ||
| new GradientStop { Color = Colors.Black, Offset = 0.0f }, | ||
| new GradientStop { Color = Color.FromArgb("#80000000"), Offset = 0.5f }, | ||
| new GradientStop { Color = Colors.Transparent, Offset = 1.0f } | ||
| } | ||
| }, | ||
| Children = | ||
| { | ||
| new Label | ||
| { | ||
| Text = "Title", | ||
| TextColor = Colors.White | ||
| }, | ||
| new Label | ||
| { | ||
| Text = "Subtitle", | ||
| TextColor = Colors.White | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| // Radial gradient with transparent stops — exercises SetBackground(RadialGradientPaint) | ||
| var radialGradientBox = new BoxView | ||
| { | ||
| AutomationId = "RadialGradientBox", | ||
| WidthRequest = 250, | ||
| HeightRequest = 100, | ||
| Background = new RadialGradientBrush | ||
| { | ||
| GradientStops = new GradientStopCollection | ||
| { | ||
| new GradientStop { Color = Colors.Transparent, Offset = 0.0f }, | ||
| new GradientStop { Color = Color.FromArgb("#80000000"), Offset = 0.5f }, | ||
| new GradientStop { Color = Colors.Blue, Offset = 1.0f } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| // Border with a LinearGradientBrush Stroke that fades to transparent — exercises SetBorderBrush(LinearGradientPaint) | ||
| var borderGradientBox = new Border | ||
| { | ||
| AutomationId = "BorderGradientBox", | ||
| WidthRequest = 250, | ||
| HeightRequest = 100, | ||
| StrokeThickness = 10, | ||
| StrokeShape = new RoundRectangle | ||
| { | ||
| CornerRadius = new CornerRadius(10) | ||
| }, | ||
| Stroke = new LinearGradientBrush | ||
| { | ||
| StartPoint = new Point(0, 0), | ||
| EndPoint = new Point(1, 1), | ||
| GradientStops = new GradientStopCollection | ||
| { | ||
| new GradientStop { Color = Colors.Purple, Offset = 0.0f }, | ||
| new GradientStop { Color = Color.FromArgb("#80000000"), Offset = 0.5f }, | ||
| new GradientStop { Color = Colors.Transparent, Offset = 1.0f } | ||
| } | ||
| }, | ||
| Content = new Label | ||
| { | ||
| Text = "Gradient border", | ||
| HorizontalOptions = LayoutOptions.Center, | ||
| VerticalOptions = LayoutOptions.Center | ||
| } | ||
| }; | ||
|
|
||
| Content = new VerticalStackLayout | ||
| { | ||
| Padding = 20, | ||
| Children = | ||
| { | ||
| label, | ||
| border, | ||
| radialGradientBox, | ||
| borderGradientBox | ||
| } | ||
| }; | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue35280.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue35280 : _IssuesUITest | ||
| { | ||
| public Issue35280(TestDevice device) : base(device) { } | ||
|
|
||
| public override string Issue => "LinearGradientBrush with transparent stops renders as opaque black box on Android"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Brush)] | ||
| public void LinearGradientBrushTransparentStopsShouldNotBeOpaque() | ||
| { | ||
| // Wait for the gradient container to be visible | ||
| App.WaitForElement("DescriptionLabel"); | ||
|
|
||
| // The gradient has transparent/semi-transparent stops. | ||
| // With the bug (GetGradientData(1.0f)), all stops are forced fully opaque → solid black box. | ||
| // With the fix (GetGradientData(null)), per-stop alpha is preserved → the dotnet_bot.png image shows through. | ||
| VerifyScreenshot(retryTimeout: TimeSpan.FromSeconds(2)); | ||
| } | ||
| } |
Binary file added
BIN
+369 KB
...Tests/snapshots/ios-26/LinearGradientBrushTransparentStopsShouldNotBeOpaque.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+369 KB
...OS.Tests/snapshots/ios/LinearGradientBrushTransparentStopsShouldNotBeOpaque.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.