Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 19402d3

Browse files
Jon2Gjsuarezruizmattleibow
authored andcommitted
Fixes Setting BackgroundColor to null does not actually changes BackgroundColor #22914 (#22917)
* Fixes #22914 * Add tests Add tests for appium * Fix the build * Use VerifyScreenshot * @jsuarezruiz suggested changes --------- Co-authored-by: Javier Suárez <[email protected]> Co-authored-by: Matthew Leibowitz <[email protected]>
1 parent 66198f1 commit 19402d3

File tree

5 files changed

+85
-2
lines changed

5 files changed

+85
-2
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage
3+
x:Class="Maui.Controls.Sample.Issues.Issue22914"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
6+
<VerticalStackLayout x:Name="VerticalStackLayout1" BackgroundColor="Orange">
7+
8+
9+
<ContentView x:Name="ContentView1" BackgroundColor="Gray">
10+
<Label Text="You should be able to read after tapping the button" TextColor="Gray" />
11+
</ContentView>
12+
13+
<Label
14+
x:Name="Label1"
15+
BackgroundColor="Green"
16+
HeightRequest="100"
17+
Text="Sample label" />
18+
19+
<Button
20+
x:Name="Tap1Button"
21+
AutomationId="Tap1Button"
22+
BackgroundColor="Red"
23+
Text="Reset background color" />
24+
25+
</VerticalStackLayout>
26+
</ContentPage>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Microsoft.Maui.Controls;
2+
using Microsoft.Maui.Controls.Xaml;
3+
4+
namespace Maui.Controls.Sample.Issues
5+
{
6+
[XamlCompilation(XamlCompilationOptions.Compile)]
7+
[Issue(IssueTracker.Github, 22914, "Setting BackgroundColor to null does not actually changes BackgroundColor", PlatformAffected.iOS | PlatformAffected.Android)]
8+
public partial class Issue22914 : ContentPage
9+
{
10+
public Issue22914()
11+
{
12+
InitializeComponent();
13+
14+
var tapCommand = new Command(buttonTapped);
15+
this.Tap1Button.Command = tapCommand;
16+
}
17+
18+
void buttonTapped()
19+
{
20+
this.Tap1Button.BackgroundColor = null;
21+
this.ContentView1.BackgroundColor = null;
22+
this.Label1.BackgroundColor = null;
23+
this.VerticalStackLayout1.BackgroundColor = null;
24+
}
25+
}
26+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Drawing;
2+
using NUnit.Framework;
3+
using NUnit.Framework.Legacy;
4+
using UITest.Appium;
5+
using UITest.Core;
6+
7+
namespace Microsoft.Maui.TestCases.Tests.Issues
8+
{
9+
public class Issue22914 : _IssuesUITest
10+
{
11+
const string ButtonId = "Tap1Button";
12+
13+
readonly string[] _expectedNullBackgroundColorIds = [ButtonId, "ContentView1", "Label1", "VerticalStackLayout1"];
14+
15+
public Issue22914(TestDevice device) : base(device)
16+
{
17+
}
18+
19+
public override string Issue => "Setting BackgroundColor to null does not actually changes BackgroundColor";
20+
21+
[Test]
22+
[Category(UITestCategories.ViewBaseTests)]
23+
public void UpdateBackgroundColorToNull()
24+
{
25+
var tapAreaResult = App.WaitForElement(ButtonId, $"Timed out waiting for {ButtonId}");
26+
tapAreaResult.Tap();
27+
28+
VerifyScreenshot("Issue22914Test");
29+
}
30+
}
31+
}

src/Core/src/Platform/Android/ViewExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ internal static void UpdateBackground(this AView platformView, Paint? background
300300
platformView.Background = drawable;
301301
}
302302
}
303-
else if (platformView is LayoutViewGroup)
303+
else if (platformView is not null)
304304
{
305305
platformView.Background = null;
306306
}

src/Core/src/Platform/iOS/ViewExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static void UpdateBackground(this UIView platformView, Paint? paint, IBut
7777

7878
if (paint.IsNullOrEmpty())
7979
{
80-
if (platformView is LayoutView)
80+
if (platformView is not null)
8181
platformView.BackgroundColor = null;
8282
else
8383
return;

0 commit comments

Comments
 (0)