Skip to content

Commit 27e23fe

Browse files
committed
add more comments and move to Controls
1 parent c9ca5f7 commit 27e23fe

File tree

4 files changed

+37
-20
lines changed

4 files changed

+37
-20
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,17 @@ public static void MapMaxLines(ILabelHandler handler, Label label)
3636
handler.PlatformView?.UpdateMaxLines(label);
3737
}
3838

39-
static void MapFormatting(ILabelHandler handler, Label label)
39+
internal static void MapFormatting(ILabelHandler handler, Label label)
4040
{
41-
if (!IsPlainText(label))
42-
return;
43-
44-
LabelHandler.MapFormatting(handler, label);
41+
if (IsPlainText(label))
42+
{
43+
LabelHandler.MapFormatting(handler, label);
44+
}
45+
else
46+
{
47+
handler.UpdateValue(nameof(ILabel.TextColor));
48+
handler.UpdateValue(nameof(ILabel.Font));
49+
}
4550
}
4651

4752
void RecalculateSpanPositions(Size size)

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,22 @@ public static void UpdateText(this UILabel platformLabel, Label label)
1414
switch (label.TextType)
1515
{
1616
case TextType.Html:
17-
platformLabel.UpdateTextHtml(label);
17+
// NOTE: Setting HTML text this will crash with some sort of consistency error.
18+
// https://github.com/dotnet/maui/issues/25946
19+
// Here we have to dispatch back the the main queue to avoid the crash.
20+
// This is observed with CarouselView 1 but not with 2, so hopefully this
21+
// will be just disappear once we switch.
22+
CoreFoundation.DispatchQueue.MainQueue.DispatchAsync(() =>
23+
{
24+
platformLabel.UpdateTextHtml(label);
25+
26+
if (label.Handler is LabelHandler labelHandler)
27+
Label.MapFormatting(labelHandler, label);
28+
29+
// NOTE: Because we are updating text outside the normal layout
30+
// pass, we need to invalidate the measure for the next pass.
31+
label.InvalidateMeasure();
32+
});
1833
break;
1934

2035
default:

src/Core/src/Handlers/Label/LabelHandler.iOS.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,5 @@ public static void MapFormatting(ILabelHandler handler, ILabel label)
8181
// so we need to make sure those are applied, too
8282
handler.UpdateValue(nameof(ILabel.HorizontalTextAlignment));
8383
}
84-
85-
internal static void ReapplyFormattingForHTMLLabel(ILabelHandler handler, ILabel label)
86-
{
87-
handler.UpdateValue(nameof(ILabel.TextColor));
88-
handler.UpdateValue(nameof(ILabel.Font));
89-
}
9084
}
9185
}

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,17 @@ internal static void UpdateTextHtml(this UILabel platformLabel, ILabel label)
8888
};
8989

9090
NSError nsError = new();
91-
CoreFoundation.DispatchQueue.MainQueue.DispatchAsync(() =>
92-
{
93-
platformLabel.AttributedText = new NSAttributedString(text, attr, ref nsError);
94-
if (label.Handler is ILabelHandler labelHandler)
95-
LabelHandler.ReapplyFormattingForHTMLLabel(labelHandler, label);
96-
97-
label.InvalidateMeasure();
98-
});
91+
92+
// NOTE: Sometimes this will crash with some sort of consistency error.
93+
// https://github.com/dotnet/maui/issues/25946
94+
// The caller should ensure that this extension is dispatched. We cannot
95+
// do it here as we need to re-apply the formatting and we cannot call
96+
// into Controls from Core.
97+
// This is observed with CarouselView 1 but not with 2, so hopefully this
98+
// will be just disappear once we switch.
99+
#pragma warning disable CS8601
100+
platformLabel.AttributedText = new NSAttributedString(text, attr, ref nsError);
101+
#pragma warning restore CS8601
99102
}
100103

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

0 commit comments

Comments
 (0)