Skip to content

Commit 89a2772

Browse files
committed
fix android
1 parent 009077c commit 89a2772

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

SampleApp/Views/MainPage.xaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@
2121

2222
<Grid>
2323
<Image Source="sakura.jpg" Aspect="AspectFit" />
24-
25-
<Label FontSize="40"
24+
25+
<Label FontSize="40"
2626
HorizontalTextAlignment="Center"
2727
VerticalOptions="Center"
2828
TextColor="Aquamarine"
2929
stroked:StrokedLabel.StrokeColor="Black"
3030
stroked:StrokedLabel.StrokeWidth="4"
3131
Text="Stroked text is much more readable when over a background image" />
3232
</Grid>
33-
34-
<Label FontSize="20"
33+
34+
<Label FontSize="20"
3535
HorizontalTextAlignment="Center"
3636
TextColor="DarkRed"
3737
stroked:StrokedLabel.StrokeColor="Red"
3838
stroked:StrokedLabel.StrokeWidth="1"
3939
Text="Stroked text can be emphasized without needing bold" />
40-
41-
<Label FontSize="24"
40+
41+
<Label FontSize="24"
4242
HorizontalTextAlignment="Center"
4343
TextColor="LightGoldenrodYellow"
4444
stroked:StrokedLabel.StrokeColor="LightCoral"

Vapolia.StrokedLabels/StrokedLabelInternals.cs

+15-3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ internal class StrokedTextView(Context context) : MauiTextView(context), IStroke
107107
private bool isDrawing;
108108
private int strokeWidth;
109109

110+
private bool HasStroke => !Equals(StrokeColor, KnownColor.Default) && !Equals(StrokeColor, KnownColor.Transparent) && strokeWidth > 0;
111+
110112
public Color StrokeColor { get; set; } = (Color)StrokedLabel.StrokeColorProperty.DefaultValue;
111113
public int StrokeWidth
112114
{
@@ -119,8 +121,16 @@ public int StrokeWidth
119121
var p = Paint;
120122
if (p != null)
121123
{
122-
p.SetStyle(Android.Graphics.Paint.Style.Stroke);
123-
p.StrokeWidth = StrokeWidth;
124+
if (HasStroke)
125+
{
126+
p.SetStyle(Android.Graphics.Paint.Style.Stroke);
127+
p.StrokeWidth = StrokeWidth;
128+
}
129+
else
130+
{
131+
p.SetStyle(Android.Graphics.Paint.Style.Fill);
132+
p.StrokeWidth = 0;
133+
}
124134
}
125135
}
126136
}
@@ -130,12 +140,14 @@ public override void Invalidate()
130140
// Ignore invalidate() calls triggered by setTextColor(color) calls
131141
if(isDrawing)
132142
return;
143+
144+
base.RequestLayout();
133145
base.Invalidate();
134146
}
135147

136148
protected override void OnDraw(Canvas canvas)
137149
{
138-
if (Equals(StrokeColor, KnownColor.Default) || Equals(StrokeColor, KnownColor.Transparent))
150+
if (!HasStroke)
139151
{
140152
base.OnDraw(canvas);
141153
return;

Vapolia.StrokedLabels/Vapolia.StrokedLabels.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
5454
<PackageProjectUrl>https://github.com/vapolia/StrokedLabel</PackageProjectUrl>
5555
<PackageReleaseNotes>
56+
1.0.1: Fix android
5657
1.0.0: Initial release
5758
</PackageReleaseNotes>
5859
</PropertyGroup>

0 commit comments

Comments
 (0)