Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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.
79 changes: 79 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue35280.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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
}
}
}
}
}
};

Content = new VerticalStackLayout
{
Padding = 20,
Children =
{
label,
border
}
};
}
}
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 → red background shows through.
Comment thread
SubhikshaSf4851 marked this conversation as resolved.
Outdated
VerifyScreenshot(retryTimeout: TimeSpan.FromSeconds(2));
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions src/Core/src/Graphics/MauiDrawable.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void SetBackground(LinearGradientPaint linearGradientPaint)

_background = linearGradientPaint;

var gradientData = linearGradientPaint.GetGradientData(1.0f);
var gradientData = linearGradientPaint.GetGradientData(null);

SetLinearGradientBackground(gradientData.X1, gradientData.Y1, gradientData.X2, gradientData.Y2, gradientData.Colors, gradientData.Offsets);
}
Expand All @@ -126,7 +126,7 @@ public void SetBackground(RadialGradientPaint radialGradientPaint)

_background = radialGradientPaint;

var gradientData = radialGradientPaint.GetGradientData(1.0f);
var gradientData = radialGradientPaint.GetGradientData(null);
Comment thread
SubhikshaSf4851 marked this conversation as resolved.

SetRadialGradientBackground(gradientData.CenterX, gradientData.CenterY, gradientData.Radius, gradientData.Colors, gradientData.Offsets);
}
Expand Down Expand Up @@ -247,7 +247,7 @@ public void SetBorderBrush(LinearGradientPaint linearGradientPaint)

_stroke = linearGradientPaint;

var gradientData = linearGradientPaint.GetGradientData(1.0f);
var gradientData = linearGradientPaint.GetGradientData(null);
Comment thread
SubhikshaSf4851 marked this conversation as resolved.

SetLinearGradientBorder(gradientData.X1, gradientData.Y1, gradientData.X2, gradientData.Y2, gradientData.Colors, gradientData.Offsets);
}
Expand All @@ -261,7 +261,7 @@ public void SetBorderBrush(RadialGradientPaint radialGradientPaint)

_stroke = radialGradientPaint;

var gradientData = radialGradientPaint.GetGradientData(1.0f);
var gradientData = radialGradientPaint.GetGradientData(null);

SetRadialGradientBorder(gradientData.CenterX, gradientData.CenterY, gradientData.Radius, gradientData.Colors, gradientData.Offsets);
}
Expand Down
Loading