Skip to content

Commit

Permalink
Fixed the issue dotnet#22042 & added a UITest
Browse files Browse the repository at this point in the history
  • Loading branch information
kubaflo committed May 2, 2024
1 parent ab80939 commit 4593254
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue22042"
Title="Issue22042">

<ContentPage.Resources>
<RadialGradientBrush x:Key="PurpleGradiant"
Center="0.8,0.5">
<GradientStop Color="#AD27FF"
Offset="0.25" />
<GradientStop Color="#4447FE"
Offset="0.75" />
</RadialGradientBrush>
</ContentPage.Resources>

<Border x:Name="border"
VerticalOptions="Center"
AutomationId="border"
StrokeThickness="2">
<Label Text="Hello, World!" />
<Border.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
</Border.GestureRecognizers>
</Border>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;
using Microsoft.Maui.Graphics;

namespace Maui.Controls.Sample.Issues;

[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 22042, "[Android] Border Stroke GradiantBrush can only switch to another gradiantbrush", PlatformAffected.Android)]

public partial class Issue22042 : ContentPage
{
private Brush _gradiantPurpleBrush => Resources.TryGetValue("PurpleGradiant", out object laColor) ? (Brush)laColor : null;

public Issue22042()
{
InitializeComponent();
}

private void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
{
if (border.Stroke == _gradiantPurpleBrush)
border.Stroke = Colors.Red;
else
border.Stroke = _gradiantPurpleBrush;
}
}
31 changes: 31 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue22042.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.AppiumTests.Issues
{
public class Issue22042 : _IssuesUITest
{
public Issue22042(TestDevice device) : base(device)
{
}

public override string Issue => "[Android] Border Stroke GradiantBrush can only switch to another gradiantbrush";

[Test]
public void BorderCollorShouldChange()
{
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.iOS, TestDevice.Mac, TestDevice.Windows });

App.WaitForElement("border");

//Applies a gradient
App.Click("border");

//Applies a solid color
App.Click("border");

VerifyScreenshot();
}
}
}
2 changes: 2 additions & 0 deletions src/Core/src/Graphics/MauiDrawable.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public void SetBorderColor(AColor? borderColor)

_borderColor = borderColor;

InitializeBorderIfNeeded();
InvalidateSelf();
}

Expand Down Expand Up @@ -183,6 +184,7 @@ public void SetBorderBrush(SolidPaint solidPaint)
{
_invalidatePath = true;
_borderColor = null;
_borderPaint = null;

var borderColor = solidPaint.Color == null
? (AColor?)null
Expand Down

0 comments on commit 4593254

Please sign in to comment.