diff --git a/src/Controls/src/Core/HandlerImpl/Label/Label.iOS.cs b/src/Controls/src/Core/HandlerImpl/Label/Label.iOS.cs index 7179fc780932..a26062932dad 100644 --- a/src/Controls/src/Core/HandlerImpl/Label/Label.iOS.cs +++ b/src/Controls/src/Core/HandlerImpl/Label/Label.iOS.cs @@ -68,8 +68,10 @@ public static void MapFont(ILabelHandler handler, Label label) if (label?.HasFormattedTextSpans ?? false) return; - if (label?.TextType == TextType.Html) + if (label?.TextType == TextType.Html && FontIsDefault(label)) { + // If no explicit font has been specified and we're displaying HTML, + // let the HTML determine the font return; } @@ -81,8 +83,10 @@ public static void MapTextColor(ILabelHandler handler, Label label) if (label?.HasFormattedTextSpans ?? false) return; - if (label?.TextType == TextType.Html) + if (label?.TextType == TextType.Html && label.GetValue(TextColorProperty) == null) { + // If no explicit text color has been specified and we're displaying HTML, + // let the HTML determine the colors return; } @@ -98,5 +102,25 @@ public static void MapMaxLines(ILabelHandler handler, Label label) { handler.PlatformView?.UpdateMaxLines(label); } + + static bool FontIsDefault(Label label) + { + if (label.IsSet(Label.FontAttributesProperty)) + { + return false; + } + + if (label.IsSet(Label.FontFamilyProperty)) + { + return false; + } + + if (label.IsSet(Label.FontSizeProperty)) + { + return false; + } + + return true; + } } } diff --git a/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.cs b/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.cs index 7cf5c51b5de7..c405d929ea84 100644 --- a/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.cs @@ -1,8 +1,12 @@ using System.Threading.Tasks; +#if __IOS__ +using Foundation; +#endif using Microsoft.Maui.Controls; using Microsoft.Maui.Controls.Platform; using Microsoft.Maui.Graphics; using Microsoft.Maui.Handlers; +using Microsoft.Maui.Platform; using Xunit; namespace Microsoft.Maui.DeviceTests @@ -362,5 +366,89 @@ await InvokeOnMainThreadAsync(async () => await normalBitmap.AssertEqual(formattedBitmap); }); } + + [Fact] + public async Task TextColorAppliesEvenInHtmlMode() + { + // Note: this is specifically a Controls-level rule that's inherited from Forms + // There's no reason other SDKs need to force a TextColor property when dealing + // with HTML text (since HTML text has its own color handling) + + var label = new Label + { + TextType = TextType.Html, + TextColor = Colors.Red, + Text = "
Test
" + }; + + await InvokeOnMainThreadAsync(() => + { + var handler = CreateHandlerTest
" + }; + + await InvokeOnMainThreadAsync(() => + { + var handler = CreateHandler