Skip to content

Commit b515625

Browse files
committed
Don’t call NSAttributedString with HTML from a background thread
1 parent 94f6c92 commit b515625

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/Controls/src/Core/Label/Label.iOS.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ public static void MapMaxLines(ILabelHandler handler, Label label)
3838

3939
static void MapFormatting(ILabelHandler handler, Label label)
4040
{
41-
// we need to re-apply color and font for HTML labels
42-
if (!label.HasFormattedTextSpans && label.TextType == TextType.Html)
43-
{
44-
handler.UpdateValue(nameof(ILabel.TextColor));
45-
handler.UpdateValue(nameof(ILabel.Font));
46-
}
47-
4841
if (!IsPlainText(label))
4942
return;
5043

src/Core/src/Platform/iOS/LabelExtensions.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,16 @@ internal static void UpdateTextHtml(this UILabel platformLabel, ILabel label)
8888
};
8989

9090
NSError nsError = new();
91-
#pragma warning disable CS8601
92-
platformLabel.AttributedText = new NSAttributedString(text, attr, ref nsError);
93-
#pragma warning restore CS8601
91+
CoreFoundation.DispatchQueue.MainQueue.DispatchAsync(() =>
92+
{
93+
platformLabel.AttributedText = new NSAttributedString(text, attr, ref nsError);
94+
if (label.Handler is ILabelHandler labelHandler)
95+
{
96+
labelHandler.UpdateValue(nameof(ILabel.TextColor));
97+
labelHandler.UpdateValue(nameof(ILabel.Font));
98+
}
99+
label.InvalidateMeasure();
100+
});
94101
}
95102

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

0 commit comments

Comments
 (0)