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

[macOS] Fix usage of FormattedText #13529

Merged
merged 3 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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,34 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

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

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.ManualReview)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 12259, "App crash when rendering label with FormattedText", PlatformAffected.macOS)]
public class Issue12259 : TestContentPage // or TestFlyoutPage, etc ...
{
protected override void Init()
{
var label = new Label();

var fs = new FormattedString();

fs.Spans.Add(new Span { Text = "Learn more at " });

fs.Spans.Add(new Span { Text = "https://aka.ms/xamarin-quickstart ", FontAttributes = FontAttributes.Bold });

label.FormattedText = fs;

Content = label;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,7 @@
<Compile Include="$(MSBuildThisFileDirectory)ShellFlyoutContentOffest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ShellFlyoutContentWithZeroMargin.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13436.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12259.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,17 @@ internal static NSAttributedString ToAttributed(this Span span, BindableObject o
if (owner is Entry && !fgcolor.IsDefault)
fgcolor = defaultForegroundColor;

#if __MOBILE__
if (fgcolor.IsDefault)
fgcolor = ColorExtensions.LabelColor.ToColor();
#if __MOBILE__
UIColor spanFgColor;
UIColor spanBgColor;
spanFgColor = fgcolor.ToUIColor();
spanBgColor = span.BackgroundColor.ToUIColor();
#else

if (fgcolor.IsDefault)
fgcolor = ColorExtensions.LabelColor.ToColor(NSColorSpace.GenericRGBColorSpace);
NSColor spanFgColor;
NSColor spanBgColor;
spanFgColor = fgcolor.ToNSColor();
Expand Down