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

Commit 032dae2

Browse files
authored
[macOS] Fix usage of FormattedText (#13529) fixes #12259
* [Controls] Add repo for issue #12259 * [macOS] Fix usage of color extension with ColorSpace
1 parent 109bc1a commit 032dae2

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Xamarin.Forms.CustomAttributes;
2+
using Xamarin.Forms.Internals;
3+
4+
#if UITEST
5+
using Xamarin.Forms.Core.UITests;
6+
using Xamarin.UITest;
7+
using NUnit.Framework;
8+
#endif
9+
10+
namespace Xamarin.Forms.Controls.Issues
11+
{
12+
#if UITEST
13+
[Category(UITestCategories.ManualReview)]
14+
#endif
15+
[Preserve(AllMembers = true)]
16+
[Issue(IssueTracker.Github, 12259, "App crash when rendering label with FormattedText", PlatformAffected.macOS)]
17+
public class Issue12259 : TestContentPage // or TestFlyoutPage, etc ...
18+
{
19+
protected override void Init()
20+
{
21+
var label = new Label();
22+
23+
var fs = new FormattedString();
24+
25+
fs.Spans.Add(new Span { Text = "Learn more at " });
26+
27+
fs.Spans.Add(new Span { Text = "https://aka.ms/xamarin-quickstart ", FontAttributes = FontAttributes.Bold });
28+
29+
label.FormattedText = fs;
30+
31+
Content = label;
32+
}
33+
}
34+
}

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,7 @@
17201720
<Compile Include="$(MSBuildThisFileDirectory)ShellFlyoutContentWithZeroMargin.cs" />
17211721
<Compile Include="$(MSBuildThisFileDirectory)LabelFormattedTextHtmlPadding.cs" />
17221722
<Compile Include="$(MSBuildThisFileDirectory)Issue13436.xaml.cs" />
1723+
<Compile Include="$(MSBuildThisFileDirectory)Issue12259.cs" />
17231724
<Compile Include="$(MSBuildThisFileDirectory)Issue13476.cs" />
17241725
<Compile Include="$(MSBuildThisFileDirectory)ShellFlyoutHeaderBehavior.cs" />
17251726
<Compile Include="$(MSBuildThisFileDirectory)Issue8701.cs" />

Xamarin.Forms.Platform.iOS/Renderers/FormattedStringExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,17 @@ internal static NSAttributedString ToAttributed(this Span span, BindableObject o
109109
if (owner is Entry && !fgcolor.IsDefault)
110110
fgcolor = defaultForegroundColor;
111111

112+
#if __MOBILE__
112113
if (fgcolor.IsDefault)
113114
fgcolor = ColorExtensions.LabelColor.ToColor();
114-
#if __MOBILE__
115115
UIColor spanFgColor;
116116
UIColor spanBgColor;
117117
spanFgColor = fgcolor.ToUIColor();
118118
spanBgColor = span.BackgroundColor.ToUIColor();
119119
#else
120+
121+
if (fgcolor.IsDefault)
122+
fgcolor = ColorExtensions.LabelColor.ToColor(NSColorSpace.GenericRGBColorSpace);
120123
NSColor spanFgColor;
121124
NSColor spanBgColor;
122125
spanFgColor = fgcolor.ToNSColor();

0 commit comments

Comments
 (0)