Skip to content

Commit

Permalink
Don’t call NSAttributedString with HTML from a background thread
Browse files Browse the repository at this point in the history
  • Loading branch information
kubaflo committed Dec 10, 2024
1 parent 94f6c92 commit b515625
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
7 changes: 0 additions & 7 deletions src/Controls/src/Core/Label/Label.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ public static void MapMaxLines(ILabelHandler handler, Label label)

static void MapFormatting(ILabelHandler handler, Label label)
{
// we need to re-apply color and font for HTML labels
if (!label.HasFormattedTextSpans && label.TextType == TextType.Html)
{
handler.UpdateValue(nameof(ILabel.TextColor));
handler.UpdateValue(nameof(ILabel.Font));
}

if (!IsPlainText(label))
return;

Expand Down
13 changes: 10 additions & 3 deletions src/Core/src/Platform/iOS/LabelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,16 @@ internal static void UpdateTextHtml(this UILabel platformLabel, ILabel label)
};

NSError nsError = new();
#pragma warning disable CS8601
platformLabel.AttributedText = new NSAttributedString(text, attr, ref nsError);
#pragma warning restore CS8601
CoreFoundation.DispatchQueue.MainQueue.DispatchAsync(() =>
{
platformLabel.AttributedText = new NSAttributedString(text, attr, ref nsError);
if (label.Handler is ILabelHandler labelHandler)
{
labelHandler.UpdateValue(nameof(ILabel.TextColor));
labelHandler.UpdateValue(nameof(ILabel.Font));
}
label.InvalidateMeasure();
});
}

internal static void UpdateTextPlainText(this UILabel platformLabel, IText label)
Expand Down

0 comments on commit b515625

Please sign in to comment.