diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Github3856.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Github3856.cs new file mode 100644 index 000000000..c77527291 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Github3856.cs @@ -0,0 +1,61 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using Xamarin.Forms.Core.UITests; +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ +#if UITEST + [Category(UITestCategories.ManualReview)] +#endif + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 3856, "[Android] MaxLines on Label not working with FastRenderers 3.3.0-pre1", PlatformAffected.Android)] + public class Github3856 : TestContentPage // or TestMasterDetailPage, etc ... + { + protected override void Init() + { + var label1 = new Label + { + MaxLines = 4, + LineBreakMode = LineBreakMode.TailTruncation, + Text = "You should see 4 lines of text and truncation at the end. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam mattis quam non enim pellentesque, ut placerat purus finibus. Nulla quis tincidunt ante. Ut mauris lectus, aliquam a sagittis vitae, consequat eget elit. Interdum et malesuada fames ac ante ipsum primis in faucibus. Pellentesque convallis nunc nisi, a imperdiet elit efficitur et. Duis in lectus mollis, interdum ipsum et, tincidunt orci. Fusce ipsum metus, imperdiet non lacus vitae, facilisis feugiat magna. Nulla volutpat nisl tortor, a consectetur felis consectetur non. Curabitur in enim vulputate sem volutpat bibendum id nec lorem. Mauris laoreet lacus ac volutpat tempus." + }; + + var label2 = new Label + { + TextDecorations = TextDecorations.Underline, + Text = "Label/Span Underline" + }; + + var label3 = new Label + { + TextDecorations = TextDecorations.Strikethrough, + Text = "Label/Span Strikethrough" + }; + + var label4 = new Label + { + TextDecorations = TextDecorations.Underline | TextDecorations.Strikethrough, + Text = "Label/Span Underline and Strikethrough" + }; + + var stackLayout = new StackLayout + { + Spacing = 10, + Orientation = StackOrientation.Vertical, + HorizontalOptions = LayoutOptions.CenterAndExpand, + VerticalOptions = LayoutOptions.CenterAndExpand + }; + stackLayout.Children.Add(label1); + stackLayout.Children.Add(label2); + stackLayout.Children.Add(label3); + stackLayout.Children.Add(label4); + + Content = stackLayout; + } + } +} \ No newline at end of file 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 449e6e787..e8a376da8 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 @@ -9,6 +9,7 @@ Xamarin.Forms.Controls.Issues + diff --git a/Xamarin.Forms.Platform.Android/FastRenderers/LabelRenderer.cs b/Xamarin.Forms.Platform.Android/FastRenderers/LabelRenderer.cs index a5aabf5f3..42a10f4ab 100644 --- a/Xamarin.Forms.Platform.Android/FastRenderers/LabelRenderer.cs +++ b/Xamarin.Forms.Platform.Android/FastRenderers/LabelRenderer.cs @@ -220,11 +220,13 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers SkipNextInvalidate(); UpdateText(); UpdateLineHeight(); + UpdateTextDecorations(); if (e.OldElement?.LineBreakMode != e.NewElement.LineBreakMode) UpdateLineBreakMode(); - if (e.OldElement?.HorizontalTextAlignment != e.NewElement.HorizontalTextAlignment - || e.OldElement?.VerticalTextAlignment != e.NewElement.VerticalTextAlignment) + if (e.OldElement?.HorizontalTextAlignment != e.NewElement.HorizontalTextAlignment || e.OldElement?.VerticalTextAlignment != e.NewElement.VerticalTextAlignment) UpdateGravity(); + if (e.OldElement?.MaxLines != e.NewElement.MaxLines) + UpdateMaxLines(); ElevationHelper.SetElevation(this, e.NewElement); } @@ -242,10 +244,14 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers UpdateText(); else if (e.PropertyName == Label.LineBreakModeProperty.PropertyName) UpdateLineBreakMode(); + else if (e.PropertyName == Label.TextDecorationsProperty.PropertyName) + UpdateTextDecorations(); else if (e.PropertyName == Label.TextProperty.PropertyName || e.PropertyName == Label.FormattedTextProperty.PropertyName) UpdateText(); else if (e.PropertyName == Label.LineHeightProperty.PropertyName) UpdateLineHeight(); + else if (e.PropertyName == Label.MaxLinesProperty.PropertyName) + UpdateMaxLines(); } void UpdateColor() @@ -315,6 +321,12 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers _lastSizeRequest = null; } + void UpdateMaxLines() + { + SetSingleLine(Element.MaxLines == 1); + SetMaxLines(Element.MaxLines > 0 ? Element.MaxLines : 1); + } + void UpdateText() { if (Element.FormattedText != null) diff --git a/Xamarin.Forms.Platform.Android/Renderers/LabelRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/LabelRenderer.cs index 97dc6b152..bd03f49bf 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/LabelRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/LabelRenderer.cs @@ -226,16 +226,8 @@ namespace Xamarin.Forms.Platform.Android void UpdateMaxLines() { - if (Element.MaxLines > 0) - { - Control.SetSingleLine(Element.MaxLines == 1); - Control.SetMaxLines(Element.MaxLines); - } - else - { - Control.SetSingleLine(false); - Control.SetMaxLines(1); - } + Control.SetSingleLine(Element.MaxLines == 1); + Control.SetMaxLines(Element.MaxLines > 0 ? Element.MaxLines : 1); } void UpdateText()