[Android] Enable MaxLines and TextDecorations on fast renderers (#3878)

* enable MaxLines on fast renderers

* added text decoration functionality

* include test in project
This commit is contained in:
adrianknight89 2018-09-24 15:26:07 -05:00 коммит произвёл kingces95
Родитель e02542411f
Коммит 27d92537fc
4 изменённых файлов: 78 добавлений и 12 удалений

Просмотреть файл

@ -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;
}
}
}

Просмотреть файл

@ -9,6 +9,7 @@
<Import_RootNamespace>Xamarin.Forms.Controls.Issues</Import_RootNamespace> <Import_RootNamespace>Xamarin.Forms.Controls.Issues</Import_RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Github3856.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue3788.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue3788.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue2894.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue2894.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue3524.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue3524.cs" />

Просмотреть файл

@ -220,11 +220,13 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
SkipNextInvalidate(); SkipNextInvalidate();
UpdateText(); UpdateText();
UpdateLineHeight(); UpdateLineHeight();
UpdateTextDecorations();
if (e.OldElement?.LineBreakMode != e.NewElement.LineBreakMode) if (e.OldElement?.LineBreakMode != e.NewElement.LineBreakMode)
UpdateLineBreakMode(); UpdateLineBreakMode();
if (e.OldElement?.HorizontalTextAlignment != e.NewElement.HorizontalTextAlignment if (e.OldElement?.HorizontalTextAlignment != e.NewElement.HorizontalTextAlignment || e.OldElement?.VerticalTextAlignment != e.NewElement.VerticalTextAlignment)
|| e.OldElement?.VerticalTextAlignment != e.NewElement.VerticalTextAlignment)
UpdateGravity(); UpdateGravity();
if (e.OldElement?.MaxLines != e.NewElement.MaxLines)
UpdateMaxLines();
ElevationHelper.SetElevation(this, e.NewElement); ElevationHelper.SetElevation(this, e.NewElement);
} }
@ -242,10 +244,14 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
UpdateText(); UpdateText();
else if (e.PropertyName == Label.LineBreakModeProperty.PropertyName) else if (e.PropertyName == Label.LineBreakModeProperty.PropertyName)
UpdateLineBreakMode(); UpdateLineBreakMode();
else if (e.PropertyName == Label.TextDecorationsProperty.PropertyName)
UpdateTextDecorations();
else if (e.PropertyName == Label.TextProperty.PropertyName || e.PropertyName == Label.FormattedTextProperty.PropertyName) else if (e.PropertyName == Label.TextProperty.PropertyName || e.PropertyName == Label.FormattedTextProperty.PropertyName)
UpdateText(); UpdateText();
else if (e.PropertyName == Label.LineHeightProperty.PropertyName) else if (e.PropertyName == Label.LineHeightProperty.PropertyName)
UpdateLineHeight(); UpdateLineHeight();
else if (e.PropertyName == Label.MaxLinesProperty.PropertyName)
UpdateMaxLines();
} }
void UpdateColor() void UpdateColor()
@ -315,6 +321,12 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers
_lastSizeRequest = null; _lastSizeRequest = null;
} }
void UpdateMaxLines()
{
SetSingleLine(Element.MaxLines == 1);
SetMaxLines(Element.MaxLines > 0 ? Element.MaxLines : 1);
}
void UpdateText() void UpdateText()
{ {
if (Element.FormattedText != null) if (Element.FormattedText != null)

Просмотреть файл

@ -226,16 +226,8 @@ namespace Xamarin.Forms.Platform.Android
void UpdateMaxLines() void UpdateMaxLines()
{ {
if (Element.MaxLines > 0) Control.SetSingleLine(Element.MaxLines == 1);
{ Control.SetMaxLines(Element.MaxLines > 0 ? Element.MaxLines : 1);
Control.SetSingleLine(Element.MaxLines == 1);
Control.SetMaxLines(Element.MaxLines);
}
else
{
Control.SetSingleLine(false);
Control.SetMaxLines(1);
}
} }
void UpdateText() void UpdateText()