Skip to content

Commit bbc42d1

Browse files
kubaflojfversluis
authored andcommitted
[Android] BackgroundColor for GraphicsView
1 parent 5e6175f commit bbc42d1

File tree

6 files changed

+83
-2
lines changed

6 files changed

+83
-2
lines changed
2.78 KB
Loading
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
namespace Maui.Controls.Sample.Issues
2+
{
3+
4+
[Issue(IssueTracker.Github, 19568, "GraphicsView does not change the Background/BackgroundColor on Android", PlatformAffected.Android)]
5+
public class Issue19568 : ContentPage
6+
{
7+
public Issue19568()
8+
{
9+
var graphicsView = new GraphicsView()
10+
{
11+
HeightRequest = 300,
12+
WidthRequest = 300,
13+
AutomationId = "graphicsView",
14+
BackgroundColor = Colors.Red,
15+
Drawable = new MyDrawable()
16+
};
17+
18+
Content =
19+
new VerticalStackLayout()
20+
{
21+
new Grid
22+
{
23+
Children = {
24+
new Label() { Text = "The GraphicsView should have a blue background color" },
25+
graphicsView
26+
}
27+
},
28+
new Button
29+
{
30+
Text = "Change BackgroundColor & opacity",
31+
AutomationId = "ChangeBackgroundColorButton",
32+
Command = new Command(() =>
33+
{
34+
graphicsView.BackgroundColor = Colors.Blue;
35+
graphicsView.Opacity = 0.1;
36+
})
37+
}
38+
};
39+
}
40+
41+
class MyDrawable : IDrawable
42+
{
43+
public void Draw(ICanvas canvas, RectF dirtyRect) { }
44+
}
45+
}
46+
}
47+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues
6+
{
7+
public class Issue19568 : _IssuesUITest
8+
{
9+
const string Success = "Success";
10+
11+
public Issue19568(TestDevice testDevice) : base(testDevice)
12+
{
13+
}
14+
15+
public override string Issue => "GraphicsView does not change the Background/BackgroundColor on Android";
16+
17+
[Test]
18+
[Category(UITestCategories.GraphicsView)]
19+
public void GraphicsViewShouldHaveBackgroundColor()
20+
{
21+
App.WaitForElement("ChangeBackgroundColorButton");
22+
App.Click("ChangeBackgroundColorButton");
23+
VerifyScreenshot();
24+
}
25+
}
26+
}
1.19 KB
Loading

src/Core/src/Handlers/GraphicsView/GraphicsViewHandler.Android.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.Maui.Graphics.Platform;
1+
using Microsoft.Maui.Graphics;
2+
using Microsoft.Maui.Graphics.Platform;
23

34
namespace Microsoft.Maui.Handlers
45
{
@@ -11,6 +12,7 @@ internal static void MapBackground(IGraphicsViewHandler handler, IGraphicsView g
1112
{
1213
if (graphicsView.Background is not null)
1314
{
15+
handler.PlatformView?.UpdateBackground(graphicsView);
1416
handler.PlatformView?.Invalidate();
1517
}
1618
}

src/Core/src/Platform/Android/GraphicsViewExtensions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.Maui.Graphics.Platform;
1+
using Microsoft.Maui.Graphics;
2+
using Microsoft.Maui.Graphics.Platform;
23

34
namespace Microsoft.Maui.Platform
45
{
@@ -8,5 +9,10 @@ public static void UpdateDrawable(this PlatformGraphicsView PlatformGraphicsView
89
{
910
PlatformGraphicsView.Drawable = graphicsView.Drawable;
1011
}
12+
13+
internal static void UpdateBackground(this PlatformGraphicsView PlatformGraphicsView, IGraphicsView graphicsView)
14+
{
15+
PlatformGraphicsView.BackgroundColor = graphicsView.Background?.ToColor();
16+
}
1117
}
1218
}

0 commit comments

Comments
 (0)