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

[Android] Fix issue clipping a Label #12482

Merged
merged 5 commits into from
Oct 19, 2021
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
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 @@ -1714,6 +1714,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 @@ -2129,6 +2130,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