From: Gerald Versluis Date: Wed, 28 Aug 2019 11:25:02 +0000 (+0200) Subject: Make Label display HTML from a string (#4527) X-Git-Tag: accepted/tizen/5.5/unified/20200421.150457~226 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=938a840e68bc6f1f26974ee8be0eb7a4ebcbeda2;p=platform%2Fcore%2Fcsapi%2Fxsf.git 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 --- diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/LabelTextType.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/LabelTextType.cs new file mode 100644 index 0000000..3590c08 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/LabelTextType.cs @@ -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 = "

Hello World!

" + }; + + 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 = $"{DateTime.UtcNow}"; + normalLabel.Text = $"{DateTime.UtcNow}"; + + 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 == "

Hello World!

"); + + RunningApp.Tap("ToggleTextTypeButton"); + RunningApp.Screenshot ("I see HTML text"); + + Assert.IsFalse(RunningApp.Query("TextTypeLabel").FirstOrDefault()?.Text.Contains("

") ?? true); + } +#endif + } +} diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 1711c8f..2fb5d14 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -1029,6 +1029,7 @@ + diff --git a/Xamarin.Forms.Controls/CoreGalleryPages/LabelCoreGalleryPage.cs b/Xamarin.Forms.Controls/CoreGalleryPages/LabelCoreGalleryPage.cs index e7d0c67..9d7bbeb 100644 --- a/Xamarin.Forms.Controls/CoreGalleryPages/LabelCoreGalleryPage.cs +++ b/Xamarin.Forms.Controls/CoreGalleryPages/LabelCoreGalleryPage.cs @@ -236,6 +236,40 @@ namespace Xamarin.Forms.Controls Padding = new Thickness(40, 20) } ); + + var htmlLabelContainer = new ViewContainer