This repository has been archived by the owner on May 1, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Label display HTML from a string (#4527)
* Use UpdateText * Added missing helper method and UI test * Added missing helper for UWP * Added csproj entry for helper * Resolved rebase conflicts * Update LabelRenderer.cs * Update LabelRenderer.cs * Update LabelRenderer.cs * iOS Merge error fix * Feedback * - uwp fixes * - android fix empty text * - ios fix null and setting text when texttype starts as html * - set _perfectSizeValid = false; after changed AttributedText Setting the AttributedText causes GetDesiredSize to get called which sets _perfectSizeValid to true but at this point this frame still hasn't adjusted to any size change from *LayoutSubViews*. This resets _perfectSizeValid so after the AttributedText set the desiredsize can get pulled again * Renamed PlainText to Text * Fixed initial no HTML styling
- Loading branch information
1 parent
c0a681e
commit 938a840
Showing
13 changed files
with
414 additions
and
18 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/LabelTextType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
|
||
#if UITEST | ||
using Xamarin.Forms.Core.UITests; | ||
using Xamarin.UITest; | ||
using NUnit.Framework; | ||
using System.Linq; | ||
#endif | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
#if UITEST | ||
[Category(UITestCategories.Label)] | ||
#endif | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.None, 0, "Implementation of Label TextType", PlatformAffected.All)] | ||
public class LabelTextType : TestContentPage | ||
{ | ||
protected override void Init() | ||
{ | ||
var label = new Label | ||
{ | ||
AutomationId = "TextTypeLabel", | ||
Text = "<h1>Hello World!</h1>" | ||
}; | ||
|
||
var button = new Button | ||
{ | ||
AutomationId = "ToggleTextTypeButton", | ||
Text = "Toggle HTML/Plain" | ||
}; | ||
|
||
button.Clicked += (s, a) => | ||
{ | ||
label.TextType = label.TextType == TextType.Html ? TextType.Text : TextType.Html; | ||
}; | ||
|
||
|
||
Label htmlLabel = new Label() { TextType = TextType.Html }; | ||
Label normalLabel = new Label(); | ||
Label nullLabel = new Label() { TextType = TextType.Html }; | ||
|
||
Button toggle = new Button() | ||
{ | ||
Text = "Toggle some more things", | ||
Command = new Command(() => | ||
{ | ||
htmlLabel.Text = $"<b>{DateTime.UtcNow}</b>"; | ||
normalLabel.Text = $"<b>{DateTime.UtcNow}</b>"; | ||
if (String.IsNullOrWhiteSpace(nullLabel.Text)) | ||
nullLabel.Text = "hi there"; | ||
else | ||
nullLabel.Text = null; | ||
}) | ||
}; | ||
|
||
|
||
var stacklayout = new StackLayout(); | ||
stacklayout.Children.Add(label); | ||
stacklayout.Children.Add(button); | ||
stacklayout.Children.Add(htmlLabel); | ||
stacklayout.Children.Add(normalLabel); | ||
stacklayout.Children.Add(nullLabel); | ||
stacklayout.Children.Add(toggle); | ||
|
||
Content = stacklayout; | ||
} | ||
|
||
#if UITEST | ||
[Test] | ||
public void LabelToggleHtmlAndPlainTextTest() | ||
{ | ||
RunningApp.WaitForElement ("TextTypeLabel"); | ||
RunningApp.Screenshot ("I see plain text"); | ||
|
||
Assert.IsTrue(RunningApp.Query("TextTypeLabel").FirstOrDefault()?.Text == "<h1>Hello World!</h1>"); | ||
|
||
RunningApp.Tap("ToggleTextTypeButton"); | ||
RunningApp.Screenshot ("I see HTML text"); | ||
|
||
Assert.IsFalse(RunningApp.Query("TextTypeLabel").FirstOrDefault()?.Text.Contains("<h1>") ?? true); | ||
} | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Xamarin.Forms | ||
{ | ||
public enum TextType | ||
{ | ||
Text, | ||
Html | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.