Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25502.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
namespace Maui.Controls.Sample.Issues
{

[Issue(IssueTracker.Github, 25502, "Gray Line Appears on the Right Side of GraphicsView with Decimal WidthRequest on iOS Platform", PlatformAffected.iOS)]
public class Issue25502 : ContentPage
{
public Issue25502()
{
GraphicsView graphicsView = new GraphicsView
{
AutomationId = "GraphicsView",
HeightRequest = 200.25,
WidthRequest = 248.25,
BackgroundColor = Colors.White,
Margin = new Thickness(20),
};
graphicsView.Drawable = new GraphicsDrawable(graphicsView);

Button changeColorButton = new Button
{
Text = "Click to change Color",
AutomationId = "ChangeColorButton"
};

changeColorButton.Clicked += ChangeColorButton_Clicked;

Content = new StackLayout
{
Spacing = 10,
Children =
{
graphicsView,
changeColorButton
}
};

void ChangeColorButton_Clicked(object sender, EventArgs e)
{
graphicsView.BackgroundColor = Colors.Yellow;
}
}

public class GraphicsDrawable : IDrawable
{
GraphicsView _graphicsView;
public GraphicsDrawable(GraphicsView graphicsView)
{
_graphicsView = graphicsView;
}

public void Draw(ICanvas canvas, RectF dirtyRect)
{
canvas.FillColor = _graphicsView.BackgroundColor;
canvas.FillRectangle(new RectF(dirtyRect.X, dirtyRect.Y + 40, dirtyRect.Width - 40, dirtyRect.Height - 40));
}
}
}
}
120 changes: 0 additions & 120 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue31239.cs

This file was deleted.

Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue25502 : _IssuesUITest
{
public Issue25502(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Gray Line Appears on the Right Side of GraphicsView with Decimal WidthRequest on iOS Platform";

[Test]
[Category(UITestCategories.GraphicsView)]
public void VerifyGraphicsViewWithoutGrayLine()
{
App.WaitForElement("ChangeColorButton");
App.Click("ChangeColorButton");
VerifyScreenshot();
}
}
}

This file was deleted.

Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ public partial class GraphicsViewHandler : ViewHandler<IGraphicsView, PlatformTo

public static void MapBackground(IGraphicsViewHandler handler, IGraphicsView graphicsView)
{
handler.PlatformView?.UpdateBackground(graphicsView);
handler.PlatformView?.Invalidate();
if (graphicsView.Background is not null)
{
handler.PlatformView?.UpdateBackground(graphicsView);
handler.PlatformView?.Invalidate();
}
}

public static void MapDrawable(IGraphicsViewHandler handler, IGraphicsView graphicsView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ protected override PlatformTouchGraphicsView CreatePlatformView()
return new PlatformTouchGraphicsView();
}

// A container is needed when the GraphicsView has a background to ensure proper rendering,
// without it the background may not be drawn correctly on WinUI.
public override bool NeedsContainer => VirtualView?.Background is not null || base.NeedsContainer;

private protected override void OnConnectHandler(FrameworkElement platformView)
{
base.OnConnectHandler(platformView);
Expand All @@ -31,9 +27,10 @@ private protected override void OnDisconnectHandler(FrameworkElement platformVie

public static void MapBackground(IGraphicsViewHandler handler, IGraphicsView graphicsView)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));
handler.ToPlatform().UpdateBackground(graphicsView);
handler.PlatformView?.Invalidate();
if (graphicsView.Background is not null)
{
handler.PlatformView?.Invalidate();
}
}

public static void MapDrawable(IGraphicsViewHandler handler, IGraphicsView graphicsView)
Expand Down
6 changes: 4 additions & 2 deletions src/Core/src/Handlers/GraphicsView/GraphicsViewHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ protected override PlatformTouchGraphicsView CreatePlatformView()

public static void MapBackground(IGraphicsViewHandler handler, IGraphicsView graphicsView)
{
handler.PlatformView?.UpdateBackground(graphicsView);
handler.PlatformView?.InvalidateDrawable();
if (graphicsView.Background is not null)
{
handler.PlatformView?.InvalidateDrawable();
}
}

public static void MapDrawable(IGraphicsViewHandler handler, IGraphicsView graphicsView)
Expand Down
1 change: 0 additions & 1 deletion src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
#nullable enable
override Microsoft.Maui.Handlers.GraphicsViewHandler.NeedsContainer.get -> bool
Original file line number Diff line number Diff line change
@@ -1,82 +1,14 @@
using System;
using System.Threading.Tasks;
using Microsoft.Maui.DeviceTests.Stubs;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Graphics.Platform;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
using UIKit;
using Xunit;

namespace Microsoft.Maui.DeviceTests
{
public partial class GraphicsViewHandlerTests
{
PlatformGraphicsView GetPlatformGraphicsView(GraphicsViewHandler graphicsViewHandler) =>
graphicsViewHandler.PlatformView;

// Regression test for https://github.com/dotnet/maui/issues/31239
// Verifies that setting Background on GraphicsView applies the color to the platform layer.
[Fact(DisplayName = "GraphicsView applies Background color to platform layer")]
public async Task GraphicsViewAppliesBackgroundToLayer()
{
var expectedColor = Colors.Red;

var graphicsView = new GraphicsViewStub
{
Drawable = new TestDrawable(Colors.Blue),
Background = new SolidPaintStub(expectedColor),
Width = 100,
Height = 100,
};

var platformBackgroundColor = await GetValueAsync(graphicsView, (GraphicsViewHandler handler) =>
{
var nativeView = GetPlatformGraphicsView(handler);
return nativeView.BackgroundColor;
});

Assert.NotNull(platformBackgroundColor);

platformBackgroundColor.GetRGBA(out var r, out var g, out var b, out var a);

Assert.Equal(expectedColor.Red, (float)r, 2);
Assert.Equal(expectedColor.Green, (float)g, 2);
Assert.Equal(expectedColor.Blue, (float)b, 2);
}

// Regression test for https://github.com/dotnet/maui/issues/25502
// A GraphicsView with decimal WidthRequest/HeightRequest must have pixel-aligned Bounds
// to prevent the CALayer background from rendering a gray hairline at the sub-pixel edge.
[Fact(DisplayName = "GraphicsView Bounds are pixel-aligned when decimal dimensions are used")]
public async Task GraphicsViewBoundsArePixelAlignedWithDecimalDimensions()
{
var graphicsView = new GraphicsViewStub
{
Drawable = new TestDrawable(Colors.White),
Background = new SolidPaintStub(Colors.White),
Width = 248.25,
Height = 200.25,
};

var (bounds, scale) = await GetValueAsync(graphicsView, (GraphicsViewHandler handler) =>
{
var nativeView = GetPlatformGraphicsView(handler);
return (nativeView.Bounds, (double)UIScreen.MainScreen.Scale);
}, attachAndRun: true);

var widthInPixels = bounds.Width * scale;
var heightInPixels = bounds.Height * scale;

Assert.True(
Math.Abs(widthInPixels - Math.Round(widthInPixels)) < 0.01,
$"GraphicsView Bounds.Width ({bounds.Width}pt) is not pixel-aligned on a {scale}x display. " +
$"Physical width {widthInPixels}px must be an integer to prevent the gray hairline artifact.");

Assert.True(
Math.Abs(heightInPixels - Math.Round(heightInPixels)) < 0.01,
$"GraphicsView Bounds.Height ({bounds.Height}pt) is not pixel-aligned on a {scale}x display. " +
$"Physical height {heightInPixels}px must be an integer to prevent the gray hairline artifact.");
}
}
}
Loading
Loading