Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Fix Border clipping issues #18134

Closed
wants to merge 8 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<?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.BorderWithDifferentShapes"
Title="Border Shape Test">
<ContentPage.Resources>
<ResourceDictionary>

<Style TargetType="Label">
<Setter Property="FontSize" Value="10" />
</Style>

<Style TargetType="Border">
<Setter Property="Stroke" Value="Red" />
<Setter Property="HeightRequest" Value="80" />
<Setter Property="WidthRequest" Value="80" />
</Style>

<Style TargetType="Image">
<Setter Property="Aspect" Value="AspectFill" />
</Style>

</ResourceDictionary>
</ContentPage.Resources>
<Grid
Padding="12"
ColumnDefinitions="*, *, *"
RowDefinitions="Auto, Auto, Auto, *">
<!-- NO STROKE -->
<StackLayout>
<Label
AutomationId="WaitForStubControl"
Text="Rectangle without Stroke"/>
<Border
StrokeShape="Rectangle"
StrokeThickness="0">
<Image
Source="oasis.jpg"/>
</Border>
</StackLayout>
<StackLayout
Grid.Column="1">
<Label
Text="RoundRectangle without Stroke"/>
<Border
StrokeShape="RoundRectangle 12, 0, 0, 12"
StrokeThickness="0">
<Image
Source="oasis.jpg"/>
</Border>
</StackLayout>
<StackLayout
Grid.Column="2">
<Label
Text="Ellipse without Stroke"/>
<Border
StrokeShape="Ellipse"
StrokeThickness="0">
<Image
Source="oasis.jpg"/>
</Border>
</StackLayout>
<!-- SMALL STROKE -->
<StackLayout
Grid.Row="1">
<Label
Text="Rectangle with Stroke"/>
<Border
StrokeShape="Rectangle"
StrokeThickness="1">
<Image
Source="oasis.jpg"/>
</Border>
</StackLayout>
<StackLayout
Grid.Column="1"
Grid.Row="1">
<Label
Text="RoundRectangle with Stroke"/>
<Border
StrokeShape="RoundRectangle 12, 0, 0, 12"
StrokeThickness="1">
<Image
Source="oasis.jpg"/>
</Border>
</StackLayout>
<StackLayout
Grid.Column="2"
Grid.Row="1">
<Label
Text="Ellipse with Stroke"/>
<Border
StrokeShape="Ellipse"
StrokeThickness="1">
<Image
Source="oasis.jpg"/>
</Border>
</StackLayout>
<!-- BIG STROKE -->
<StackLayout
Grid.Row="2">
<Label
Text="Rectangle with Stroke"/>
<Border
StrokeShape="Rectangle"
StrokeThickness="10">
<Image
Source="oasis.jpg"/>
</Border>
</StackLayout>
<StackLayout
Grid.Column="1"
Grid.Row="2">
<Label
Text="RoundRectangle with Stroke"/>
<Border
StrokeShape="RoundRectangle 12, 0, 0, 12"
StrokeThickness="10">
<Image
Source="oasis.jpg"/>
</Border>
</StackLayout>
<StackLayout
Grid.Column="2"
Grid.Row="2">
<Label
Text="Ellipse with Stroke"/>
<Border
StrokeShape="Ellipse"
StrokeThickness="10">
<Image
Source="oasis.jpg"/>
</Border>
</StackLayout>
<!-- STROKEDASHARRAY -->
<StackLayout
Grid.Row="3">
<Label
Text="Rectangle with StrokeDashArray"/>
<Border
StrokeShape="Rectangle"
StrokeThickness="4"
StrokeDashArray="1, 1">
<Image
Source="oasis.jpg"/>
</Border>
</StackLayout>
<StackLayout
Grid.Column="1"
Grid.Row="3">
<Label
Text="RoundRectangle with StrokeDashArray"/>
<Border
StrokeShape="RoundRectangle 12, 0, 0, 12"
StrokeThickness="4"
StrokeDashArray="1, 1">
<Image
Source="oasis.jpg"/>
</Border>
</StackLayout>
<StackLayout
Grid.Column="2"
Grid.Row="3">
<Label
Text="Ellipse with StrokeDashArray"/>
<Border
StrokeShape="Ellipse"
StrokeThickness="4"
StrokeDashArray="1, 1">
<Image
Source="oasis.jpg"/>
</Border>
</StackLayout>
</Grid>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;
using Microsoft.Maui.Platform;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.None, 018071, "Validate Border using different shapes",
PlatformAffected.Android | PlatformAffected.iOS | PlatformAffected.UWP)]
public partial class BorderWithDifferentShapes : ContentPage
{
public BorderWithDifferentShapes()
{
InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Controls.Shapes;

namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 18071, "Windows and Android no longer draw Borders/clipping correctly", PlatformAffected.Android | PlatformAffected.UWP)]
public class Issue18071 : TestContentPage
{
protected override void Init()
{
Title = "Issue 18071";
BackgroundColor = Colors.CornflowerBlue;

VerticalStackLayout verticalLayout = new VerticalStackLayout();
Content = verticalLayout;

var infoLabel = new Label
{
AutomationId = "WaitForStubControl",
Text = "Without weird clipping image, the test has passed."
};
verticalLayout.Add(infoLabel);

Border border = new Border
{
Background = Colors.Yellow,
Stroke = Colors.Red,
StrokeThickness = 10
};
verticalLayout.Add(border);

AbsoluteLayout abs = new AbsoluteLayout();
border.Content = abs;

Image image = new Image
{
Source = "oasis.jpg",
Aspect = Aspect.AspectFill
};
abs.Add(image);

SizeChanged += delegate
{
if (Width > 0)
{
int width = (int)Width;
border.WidthRequest = border.HeightRequest = width * 0.5;
image.WidthRequest = image.HeightRequest = width * 0.5;
border.StrokeShape = new RoundRectangle() { CornerRadius = width * 0.25 };
}
};
}
}
}
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,22 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

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

public override string Issue => "Validate Border using different shapes";

[Test]
public void BorderWithDifferentShapesTest()
{
App.WaitForElement("WaitForStubControl");
VerifyScreenshot();
}
}
}
23 changes: 23 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue18071.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

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

public override string Issue => "Windows and Android no longer draw Borders/clipping correctly";

[Test]
public void Issue18071Test()
{
this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.iOS },
"Currently fails on Android and Windows; see https://github.com/dotnet/maui/issues/17125");

App.WaitForElement("WaitForStubControl");
VerifyScreenshot();
}
}
}
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 6 additions & 5 deletions src/Core/src/Platform/Android/ContentViewGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,14 @@ internal IBorderStroke? Clip
if (Clip is null || Clip?.Shape is null)
return null;

IShape clipShape = Clip.Shape;
bool isRoundRectangle = clipShape is IRoundRectangle;
float density = _context.GetDisplayDensity();
float strokeThickness = (float)Clip.StrokeThickness;
float w = (width / density) - strokeThickness;
float h = (height / density) - strokeThickness;
float x = strokeThickness / 2;
float y = strokeThickness / 2;
IShape clipShape = Clip.Shape;
float w = (width / density) - (isRoundRectangle ? (strokeThickness * 2) : strokeThickness);
float h = (height / density) - (isRoundRectangle ? (strokeThickness * 2) : strokeThickness);
float x = isRoundRectangle ? strokeThickness : strokeThickness / 2;
float y = isRoundRectangle ? strokeThickness : strokeThickness / 2;

var bounds = new Graphics.RectF(x, y, w, h);

Expand Down
Loading