Skip to content

Obsolete TextType.Html for .NET 10 #29685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: net10.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/Controls/src/Core/Label/Label.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ 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
#pragma warning disable CS0612 // Type or member is obsolete
if (!label.HasFormattedTextSpans && label.TextType == TextType.Html)
#pragma warning restore CS0612 // Type or member is obsolete
{
handler.UpdateValue(nameof(ILabel.TextColor));
handler.UpdateValue(nameof(ILabel.Font));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public static void UpdateText(this TextView textView, Label label)
else
textView.Text = TextTransformUtilities.GetTransformedText(label.Text, label.TextTransform);
break;
#pragma warning disable CS0612 // Type or member is obsolete
case TextType.Html:
#pragma warning restore CS0612 // Type or member is obsolete
textView.UpdateTextHtml(label);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ internal static void RecalculateSpanPositions(this UILabel control, Label elemen
{
return;
}

#pragma warning disable CS0612 // Type or member is obsolete
if (element.TextType == TextType.Html)
#pragma warning restore CS0612 // Type or member is obsolete
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public static void UpdateText(this UILabel platformLabel, Label label)
{
switch (label.TextType)
{
#pragma warning disable CS0612 // Type or member is obsolete
case TextType.Html:
#pragma warning restore CS0612 // Type or member is obsolete
platformLabel.UpdateTextHtml(label);
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public async Task HtmlTextInitializesCorrectly()
var label = new Label()
{
Text = $"<b>{expected}</b>",
#pragma warning disable CS0612 // Type or member is obsolete
TextType = TextType.Html
#pragma warning restore CS0612 // Type or member is obsolete
};

var handler = await CreateHandlerAsync<LabelHandler>(label);
Expand Down
11 changes: 10 additions & 1 deletion src/Controls/tests/DeviceTests/Elements/Label/LabelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,9 @@ await AttachAndRun(layout, async (handler) =>
{
var platformView = handler.ToPlatform();
await platformView.AssertContainsColor(Colors.Red, MauiContext);

#pragma warning disable CS0612 // Type or member is obsolete
label.TextType = TextType.Html;
#pragma warning restore CS0612 // Type or member is obsolete

await platformView.AssertDoesNotContainColor(Colors.Red, MauiContext);
});
Expand Down Expand Up @@ -490,7 +491,9 @@ public async Task TextColorAppliesEvenInHtmlMode()

var label = new Label
{
#pragma warning disable CS0612 // Type or member is obsolete
TextType = TextType.Html,
#pragma warning restore CS0612 // Type or member is obsolete
TextColor = Colors.Red,
Text = "<p>Test</p>"
};
Expand All @@ -511,7 +514,9 @@ public async Task FontStuffAppliesEvenInHtmlMode()

var label = new Label
{
#pragma warning disable CS0612 // Type or member is obsolete
TextType = TextType.Html,
#pragma warning restore CS0612 // Type or member is obsolete
FontSize = 64,
FontFamily = "Baskerville",
Text = "<p>Test</p>"
Expand Down Expand Up @@ -697,7 +702,9 @@ public async Task TextTypeAfterFontStuffIsCorrect()
await InvokeOnMainThreadAsync(() =>
{
var handler = CreateHandler<LabelHandler>(label);
#pragma warning disable CS0612 // Type or member is obsolete
label.TextType = TextType.Html;
#pragma warning restore CS0612 // Type or member is obsolete
AssertEquivalentFont(handler, label.ToFont());
});
}
Expand All @@ -711,7 +718,9 @@ public async Task FontStuffAfterTextTypeIsCorrect()

var label = new Label
{
#pragma warning disable CS0612 // Type or member is obsolete
TextType = TextType.Html,
#pragma warning restore CS0612 // Type or member is obsolete
Text = "<p>Test</p>"
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ public static IEnumerable<object[]> GetCharacterSpacingWithLineHeightWithTextDec

var label4 = new Label()
{
#pragma warning disable CS0612 // Type or member is obsolete
TextType = TextType.Html,
#pragma warning restore CS0612 // Type or member is obsolete
Text = "<h1>This is label tests.</h1>",
CharacterSpacing = 5d,
LineHeight = 1.5d,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ protected override void Build()
var label = new Label
{
Text = "<h1>Hello world!</h1>",
#pragma warning disable CS0612 // Type or member is obsolete
TextType = TextType.Html
#pragma warning restore CS0612 // Type or member is obsolete
};
var htmlLabelContainer = new ViewContainer<Label>(Test.Label.HtmlTextType, label);
Add(htmlLabelContainer);
Expand All @@ -272,7 +274,9 @@ protected override void Build()
var label = new Label
{
Text = "<h1>Broken Html!<h1>",
#pragma warning disable CS0612 // Type or member is obsolete
TextType = TextType.Html
#pragma warning restore CS0612 // Type or member is obsolete
};
var htmlLabelContainer = new ViewContainer<Label>(Test.Label.BrokenHtmlTextType, label);
Add(htmlLabelContainer);
Expand All @@ -282,7 +286,9 @@ protected override void Build()
var label = new Label
{
Text = "<h1>Hello world!</h1><p>Lorem <strong>ipsum</strong> bla di bla <i>blabla</i> blablabl&nbsp;ablabla & blablablablabl ablabl ablablabl ablablabla blablablablablablab lablablabla blablab lablablabla blablabl ablablablab lablabla blab lablablabla blablab lablabla blablablablab lablabla blablab lablablabl ablablabla blablablablablabla blablabla</p>",
#pragma warning disable CS0612 // Type or member is obsolete
TextType = TextType.Html,
#pragma warning restore CS0612 // Type or member is obsolete
MaxLines = 3
};
var htmlLabelMultipleLinesContainer = new ViewContainer<Label>(Test.Label.HtmlTextTypeMultipleLines, label);
Expand All @@ -293,7 +299,9 @@ protected override void Build()
var label = new Label
{
Text = "<h1>End aligned. Green. ä</h1>",
#pragma warning disable CS0612 // Type or member is obsolete
TextType = TextType.Html,
#pragma warning restore CS0612 // Type or member is obsolete
HorizontalTextAlignment = TextAlignment.Center,
TextColor = Colors.Green,
};
Expand All @@ -304,14 +312,18 @@ protected override void Build()
{
var toggleLabel = new Label
{
#pragma warning disable CS0612 // Type or member is obsolete
TextType = TextType.Html,
#pragma warning restore CS0612 // Type or member is obsolete
Text = "<h1 style=\"color: red;\">Hello world!</h1><p>Lorem <strong>ipsum</strong></p>"

};
var gestureRecognizer = new TapGestureRecognizer();
gestureRecognizer.Tapped += (s, a) =>
{
#pragma warning disable CS0612 // Type or member is obsolete
toggleLabel.TextType = toggleLabel.TextType == TextType.Html ? TextType.Text : TextType.Html;
#pragma warning restore CS0612 // Type or member is obsolete
};
toggleLabel.GestureRecognizers.Add(gestureRecognizer);
var toggleHtmlPlainTextLabelContainer = new ViewContainer<Label>(Test.Label.TextTypeToggle, toggleLabel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public CarouselViewSetOrientation()
{
var label = new Label
{
#pragma warning disable CS0612 // Type or member is obsolete
TextType = TextType.Html,
#pragma warning restore CS0612 // Type or member is obsolete
Text = $"<p style='background-color:red;'>{HTML}</p>",
AutomationId = HTML
};
Expand Down
2 changes: 2 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue21711.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ Label NewLabel(int count) =>
Text = $"Item{count}",
AutomationId = $"Item{count}",
Background = Brush.Yellow,
#pragma warning disable CS0612 // Type or member is obsolete
TextType = TextType.Html
#pragma warning restore CS0612 // Type or member is obsolete
};
}
}
2 changes: 2 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue8870.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ protected override void Init()
{
var label = new Label
{
#pragma warning disable CS0612 // Type or member is obsolete
TextType = TextType.Html
#pragma warning restore CS0612 // Type or member is obsolete
};

label.SetBinding(Label.TextProperty, new Binding(".", stringFormat: "<p style='background-color:red;'>{0}</p>"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ protected override void Init()

button.Clicked += (s, a) =>
{
#pragma warning disable CS0612 // Type or member is obsolete
label.TextType = label.TextType == TextType.Html ? TextType.Text : TextType.Html;
#pragma warning restore CS0612 // Type or member is obsolete
};


#pragma warning disable CS0612 // Type or member is obsolete
Label htmlLabel = new Label() { TextType = TextType.Html };
Label normalLabel = new Label();
Label nullLabel = new Label() { TextType = TextType.Html };
#pragma warning restore CS0612 // Type or member is obsolete

Button toggle = new Button()
{
Expand Down
1 change: 1 addition & 0 deletions src/Core/src/Primitives/TextType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public enum TextType
/// The subset of supported HTML tags varies by platform. Each platform's native text rendering engine
/// determines which HTML tags and attributes are supported.
/// </remarks>
[System.Obsolete]
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider providing a message in the Obsolete attribute to guide developers on migration or alternative APIs (e.g., [Obsolete("Use CustomHtmlLabel instead.")]).

Suggested change
[System.Obsolete]
[System.Obsolete("The Html value is deprecated. Use Markdown or another supported format for rich text content.")]

Copilot uses AI. Check for mistakes.

Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the public XML documentation under /docs/ to reflect that TextType.Html is now obsolete and document the planned replacement or removal.

Copilot uses AI. Check for mistakes.

Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the Obsolete attribute to the public TextType.Html enum member changes the public API and may be considered a breaking change; please confirm this aligns with your versioning policy.

Copilot uses AI. Check for mistakes.

Html
}
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ public async Task HtmlTextInitializesCorrectly()
{
var label = new LabelStub()
{
#pragma warning disable CS0612 // Type or member is obsolete
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The inline #pragma warning directives add clutter to test code; consider using a global suppression file (e.g., GlobalSuppressions.cs) to clean up repeated suppressions.

Copilot uses AI. Check for mistakes.

TextType = TextType.Html,
#pragma warning restore CS0612 // Type or member is obsolete
Text = "<h2><strong>Test1&nbsp;</strong>Test2</h2>"
};

Expand Down
Loading