Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Fix an issue clipping directly a Label (#12482)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuarezruiz committed Oct 19, 2021
1 parent 7dd033f commit 930bb6c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<controls:TestContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:Xamarin.Forms.Controls"
x:Class="Xamarin.Forms.Controls.Issues.Issue12471"
Title="Issue 12471">
<StackLayout>
<Label
Padding="12"
BackgroundColor="Black"
TextColor="White"
Text="If the Label below has a circular clip applied, the test has passed."/>
<Grid>
<Label
Text="X"
TextColor="White"
FontSize="30"
HeightRequest="60"
WidthRequest="60"
HorizontalOptions="Center"
VerticalOptions="Center"
VerticalTextAlignment="Center"
HorizontalTextAlignment="Center"
BackgroundColor="Red">
<Label.Clip>
<EllipseGeometry
Center="30,30"
RadiusX="30"
RadiusY="30"/>
</Label.Clip>
</Label>
</Grid>
</StackLayout>
</controls:TestContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;


#if UITEST
using Xamarin.Forms.Core.UITests;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 12471, "[Bug] Label.Clip won't clip on Android", PlatformAffected.Android)]
public partial class Issue12471 : TestContentPage
{
public Issue12471()
{
#if APP
InitializeComponent();
#endif
}

protected override void Init()
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue11081.xaml.cs">
<DependentUpon>Issue11081.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue12471.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12380.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12372.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12374.xaml.cs" />
Expand Down Expand Up @@ -2139,6 +2140,9 @@
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue11081.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue12471.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue12518.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
Expand Down
7 changes: 7 additions & 0 deletions Xamarin.Forms.Platform.Android/FastRenderers/LabelRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ SizeRequest IVisualElementRenderer.GetDesiredSize(int widthConstraint, int heigh
return result;
}

public override void Draw(Canvas canvas)
{
canvas.ClipShape(Context, Element);

base.Draw(canvas);
}

protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
{
base.OnLayout(changed, left, top, right, bottom);
Expand Down

0 comments on commit 930bb6c

Please sign in to comment.