Skip to content

Commit d6d17bd

Browse files
kubafloPureWeen
authored andcommitted
TextTransform Property Does Not Apply at Runtime When TextType="Html" Is Set on Label (#29700)
1 parent c019ba3 commit d6d17bd

File tree

9 files changed

+83
-12
lines changed

9 files changed

+83
-12
lines changed

src/Controls/src/Core/Platform/Android/Extensions/TextViewExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ public static class TextViewExtensions
1111
{
1212
public static void UpdateText(this TextView textView, Label label)
1313
{
14+
string text = TextTransformUtilites.GetTransformedText(label.Text, label.TextTransform);
1415
switch (label.TextType)
1516
{
1617
case TextType.Text:
1718
if (label.FormattedText != null)
1819
textView.TextFormatted = label.ToSpannableString();
1920
else
20-
textView.Text = TextTransformUtilites.GetTransformedText(label.Text, label.TextTransform);
21+
textView.Text = text;
2122
break;
2223
case TextType.Html:
23-
textView.UpdateTextHtml(label);
24+
textView.UpdateTextHtml(text);
2425
break;
2526
}
2627
}

src/Controls/src/Core/Platform/Windows/Extensions/TextBlockExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ static void DetermineTruncatedTextWrapping(TextBlock textBlock) =>
2424

2525
public static void UpdateText(this TextBlock platformControl, Label label)
2626
{
27+
string text = TextTransformUtilites.GetTransformedText(label.Text, label.TextTransform);
28+
2729
switch (label.TextType)
2830
{
2931
case TextType.Html:
30-
platformControl.UpdateTextHtml(label);
32+
platformControl.UpdateTextHtml(label, text);
3133
break;
3234

3335
default:
@@ -39,7 +41,7 @@ public static void UpdateText(this TextBlock platformControl, Label label)
3941
{
4042
platformControl.TextHighlighters.Clear();
4143
}
42-
platformControl.Text = TextTransformUtilites.GetTransformedText(label.Text, label.TextTransform);
44+
platformControl.Text = text;
4345
}
4446
break;
4547
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public static class LabelExtensions
1111
{
1212
public static void UpdateText(this UILabel platformLabel, Label label)
1313
{
14+
var text = TextTransformUtilites.GetTransformedText(label.Text, label.TextTransform);
15+
1416
switch (label.TextType)
1517
{
1618
case TextType.Html:
@@ -21,7 +23,7 @@ public static void UpdateText(this UILabel platformLabel, Label label)
2123
// will be just disappear once we switch.
2224
CoreFoundation.DispatchQueue.MainQueue.DispatchAsync(() =>
2325
{
24-
platformLabel.UpdateTextHtml(label);
26+
platformLabel.UpdateTextHtml(text);
2527

2628
if (label.Handler is LabelHandler labelHandler)
2729
Label.MapFormatting(labelHandler, label);
@@ -42,7 +44,7 @@ public static void UpdateText(this UILabel platformLabel, Label label)
4244
platformLabel.AttributedText = null;
4345
}
4446

45-
platformLabel.Text = TextTransformUtilites.GetTransformedText(label.Text, label.TextTransform);
47+
platformLabel.Text = text;
4648
}
4749
break;
4850
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Maui.Controls.Sample.Issues.Issue29700"
5+
Title="29700">
6+
<VerticalStackLayout>
7+
<Label Text="Hello, World"
8+
AutomationId="TestLabel"
9+
x:Name="TestLabel"
10+
TextType="Html"/>
11+
<Button Text="Change text transform"
12+
AutomationId="ChangeTextTransformButton"
13+
Clicked="Button_Clicked"/>
14+
</VerticalStackLayout>
15+
</ContentPage>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
3+
[Issue(IssueTracker.Github, 29700, "TextTransform Property Does Not Apply at Runtime When TextType='Html'")]
4+
public partial class Issue29700 : ContentPage
5+
{
6+
public Issue29700()
7+
{
8+
InitializeComponent();
9+
}
10+
11+
private void Button_Clicked(object sender, EventArgs e)
12+
{
13+
if (TestLabel.TextTransform == TextTransform.Default)
14+
TestLabel.TextTransform = TextTransform.Uppercase;
15+
else if (TestLabel.TextTransform == TextTransform.Uppercase)
16+
TestLabel.TextTransform = TextTransform.Lowercase;
17+
else
18+
TestLabel.TextTransform = TextTransform.None;
19+
}
20+
21+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues
6+
{
7+
public class Issue29700 : _IssuesUITest
8+
{
9+
public Issue29700(TestDevice testDevice) : base(testDevice)
10+
{
11+
}
12+
13+
public override string Issue => "TextTransform Property Does Not Apply at Runtime When TextType='Html'";
14+
15+
[Test]
16+
[Category(UITestCategories.Label)]
17+
public void TextTransformPropertyAppliesAtRuntime()
18+
{
19+
var label = App.WaitForElement("TestLabel");
20+
Assert.That(label.GetText(), Is.EqualTo("Hello, World"));
21+
App.Tap("ChangeTextTransformButton");
22+
Assert.That(label.GetText(), Is.EqualTo("HELLO, WORLD"));
23+
App.Tap("ChangeTextTransformButton");
24+
Assert.That(label.GetText(), Is.EqualTo("hello, world"));
25+
App.Tap("ChangeTextTransformButton");
26+
Assert.That(label.GetText(), Is.EqualTo("Hello, World"));
27+
}
28+
}
29+
}

src/Core/src/Platform/Android/TextViewExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public static void UpdateTextPlainText(this TextView textView, IText label)
1919
public static void UpdateTextHtml(this TextView textView, ILabel label)
2020
{
2121
var text = label.Text ?? string.Empty;
22+
textView.UpdateTextHtml(text);
23+
}
24+
25+
internal static void UpdateTextHtml(this TextView textView, string text)
26+
{
2227
var htmlText = WebUtility.HtmlDecode(text);
2328

2429
if (OperatingSystem.IsAndroidVersionAtLeast(24))

src/Core/src/Platform/Windows/TextBlockExtensions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,8 @@ public static void UpdateVerticalTextAlignment(this TextBlock platformControl, I
8585
platformControl.VerticalAlignment = label.VerticalTextAlignment.ToPlatformVerticalAlignment();
8686
}
8787

88-
internal static void UpdateTextHtml(this TextBlock platformControl, ILabel label)
88+
internal static void UpdateTextHtml(this TextBlock platformControl, ILabel label, string text)
8989
{
90-
var text = label.Text ?? string.Empty;
91-
9290
// Just in case we are not given text with elements.
9391
var modifiedText = string.Format("<div>{0}</div>", text);
9492
modifiedText = Regex.Replace(modifiedText, "<br>", "<br></br>", RegexOptions.IgnoreCase);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,8 @@ public static void UpdateLineHeight(this UILabel platformLabel, ILabel label)
7373
platformLabel.AttributedText = modAttrText;
7474
}
7575

76-
internal static void UpdateTextHtml(this UILabel platformLabel, ILabel label)
76+
internal static void UpdateTextHtml(this UILabel platformLabel, string text)
7777
{
78-
string text = label.Text ?? string.Empty;
79-
8078
var attr = new NSAttributedStringDocumentAttributes
8179
{
8280
DocumentType = NSDocumentType.HTML,

0 commit comments

Comments
 (0)