From 991250aecc0a6d028ab75e186c0a2d33e55c6ed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Sat, 13 Mar 2021 03:50:28 +0100 Subject: [PATCH] Implement LineBreakMode property in LabelHandlers (#458) --- .../Android/Extensions/TextViewExtensions.cs | 2 +- .../Android/FastRenderers/LabelRenderer.cs | 1 + .../Core/src/iOS/Renderers/LabelRenderer.cs | 1 + .../samples/Controls.Sample/Pages/MainPage.cs | 14 ++- src/Core/src/Core/ILabel.cs | 5 + .../Handlers/Label/LabelHandler.Android.cs | 5 + .../Handlers/Label/LabelHandler.Standard.cs | 1 + src/Core/src/Handlers/Label/LabelHandler.cs | 1 + .../src/Handlers/Label/LabelHandler.iOS.cs | 5 + .../src/Platform/Android/LabelExtensions.cs | 48 ++++++++ src/Core/src/Platform/iOS/LabelExtensions.cs | 40 +++++++ .../AssertionExtensions.Android.cs | 13 ++ .../DeviceTests/AssertionExtensions.iOS.cs | 12 ++ .../Label/LabelHandlerTests.Android.cs | 19 +++ .../Handlers/Label/LabelHandlerTests.cs | 111 ++++++++++++++++++ .../Handlers/Label/LabelHandlerTests.iOS.cs | 20 +++- src/Core/tests/DeviceTests/Stubs/LabelStub.cs | 2 + 17 files changed, 297 insertions(+), 3 deletions(-) diff --git a/src/Compatibility/Core/src/Android/Extensions/TextViewExtensions.cs b/src/Compatibility/Core/src/Android/Extensions/TextViewExtensions.cs index 63661919e5e3..157b71a99e0f 100644 --- a/src/Compatibility/Core/src/Android/Extensions/TextViewExtensions.cs +++ b/src/Compatibility/Core/src/Android/Extensions/TextViewExtensions.cs @@ -32,7 +32,7 @@ public static void SetLineBreakMode(this TextView textView, Label label) public static void SetLineBreakMode(this TextView textView, Button button) => SetLineBreak(textView, button.LineBreakMode); - + [PortHandler] public static int SetLineBreak(TextView textView, LineBreakMode lineBreakMode) { int maxLines = Int32.MaxValue; diff --git a/src/Compatibility/Core/src/Android/FastRenderers/LabelRenderer.cs b/src/Compatibility/Core/src/Android/FastRenderers/LabelRenderer.cs index 9edfa4f6cc8f..6b9fdbce1296 100644 --- a/src/Compatibility/Core/src/Android/FastRenderers/LabelRenderer.cs +++ b/src/Compatibility/Core/src/Android/FastRenderers/LabelRenderer.cs @@ -365,6 +365,7 @@ void UpdateCharacterSpacing() } } + [PortHandler] void UpdateLineBreakMode() { this.SetLineBreakMode(Element); diff --git a/src/Compatibility/Core/src/iOS/Renderers/LabelRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/LabelRenderer.cs index 699fdf2487f9..60f6867dae4b 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/LabelRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/LabelRenderer.cs @@ -354,6 +354,7 @@ void UpdateHorizontalTextAlignment() #endif } + [PortHandler] void UpdateLineBreakMode() { #if __MOBILE__ diff --git a/src/Controls/samples/Controls.Sample/Pages/MainPage.cs b/src/Controls/samples/Controls.Sample/Pages/MainPage.cs index a4c0f56b8d27..16901756e17a 100644 --- a/src/Controls/samples/Controls.Sample/Pages/MainPage.cs +++ b/src/Controls/samples/Controls.Sample/Pages/MainPage.cs @@ -5,7 +5,6 @@ namespace Maui.Controls.Sample.Pages { - public class MainPage : ContentPage, IPage { MainPageViewModel _viewModel; @@ -24,6 +23,15 @@ public MainPage(MainPageViewModel viewModel) void SetupMauiLayout() { + const string loremIpsum = + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " + + "Quisque ut dolor metus. Duis vel iaculis mauris, sit amet finibus mi. " + + "Etiam congue ornare risus, in facilisis libero tempor eget. " + + "Phasellus mattis mollis libero ut semper. In sit amet sapien odio. " + + "Sed interdum ullamcorper dui eu rutrum. Vestibulum non sagittis justo. " + + "Cras rutrum scelerisque elit, et porta est lobortis ac. " + + "Pellentesque eu ornare tortor. Sed bibendum a nisl at laoreet."; + var verticalStack = new VerticalStackLayout() { Spacing = 5, BackgroundColor = Color.AntiqueWhite }; var horizontalStack = new HorizontalStackLayout() { Spacing = 2, BackgroundColor = Color.CornflowerBlue }; @@ -35,6 +43,10 @@ void SetupMauiLayout() verticalStack.Add(new Label { Text = "This should be BOLD text!", FontAttributes = FontAttributes.Bold }); verticalStack.Add(new Label { Text = "This should be a CUSTOM font!", FontFamily = "Dokdo" }); verticalStack.Add(new Label { Text = "This should have padding", Padding = new Thickness(40), BackgroundColor = Color.LightBlue }); + verticalStack.Add(new Label { Text = loremIpsum }); + verticalStack.Add(new Label { Text = loremIpsum, MaxLines = 2 }); + verticalStack.Add(new Label { Text = loremIpsum, LineBreakMode = LineBreakMode.TailTruncation }); + verticalStack.Add(new Label { Text = loremIpsum, MaxLines = 2, LineBreakMode = LineBreakMode.TailTruncation }); var underlineLabel = new Label { Text = "underline", TextDecorations = TextDecorations.Underline }; verticalStack.Add(underlineLabel); diff --git a/src/Core/src/Core/ILabel.cs b/src/Core/src/Core/ILabel.cs index 59abb5ff5953..937cdc3a632b 100644 --- a/src/Core/src/Core/ILabel.cs +++ b/src/Core/src/Core/ILabel.cs @@ -5,6 +5,11 @@ namespace Microsoft.Maui /// public interface ILabel : IView, IText { + /// + /// Gets the option for line breaking. + /// + LineBreakMode LineBreakMode { get; } + /// /// Gets the maximum number of lines allowed in the Label. /// diff --git a/src/Core/src/Handlers/Label/LabelHandler.Android.cs b/src/Core/src/Handlers/Label/LabelHandler.Android.cs index 751501264dc9..e8cd3040fa03 100644 --- a/src/Core/src/Handlers/Label/LabelHandler.Android.cs +++ b/src/Core/src/Handlers/Label/LabelHandler.Android.cs @@ -37,6 +37,11 @@ public static void MapCharacterSpacing(LabelHandler handler, ILabel label) handler.TypedNativeView?.UpdateCharacterSpacing(label); } + public static void MapLineBreakMode(LabelHandler handler, ILabel label) + { + handler.TypedNativeView?.UpdateLineBreakMode(label); + } + public static void MapMaxLines(LabelHandler handler, ILabel label) { handler.TypedNativeView?.UpdateMaxLines(label); diff --git a/src/Core/src/Handlers/Label/LabelHandler.Standard.cs b/src/Core/src/Handlers/Label/LabelHandler.Standard.cs index 98b86dfbcf8c..54ef680043d4 100644 --- a/src/Core/src/Handlers/Label/LabelHandler.Standard.cs +++ b/src/Core/src/Handlers/Label/LabelHandler.Standard.cs @@ -10,6 +10,7 @@ public static void MapText(IViewHandler handler, ILabel label) { } public static void MapTextColor(IViewHandler handler, ILabel label) { } public static void MapCharacterSpacing(IViewHandler handler, ILabel label) { } public static void MapFont(LabelHandler handler, ILabel label) { } + public static void MapLineBreakMode(LabelHandler handler, ILabel label) { } public static void MapTextDecorations(LabelHandler handler, ILabel label) { } public static void MapMaxLines(IViewHandler handler, ILabel label) { } public static void MapPadding(LabelHandler handler, ILabel label) { } diff --git a/src/Core/src/Handlers/Label/LabelHandler.cs b/src/Core/src/Handlers/Label/LabelHandler.cs index d8f502f055a3..a73f787f17e6 100644 --- a/src/Core/src/Handlers/Label/LabelHandler.cs +++ b/src/Core/src/Handlers/Label/LabelHandler.cs @@ -9,6 +9,7 @@ public partial class LabelHandler [nameof(ILabel.CharacterSpacing)] = MapCharacterSpacing, [nameof(ILabel.MaxLines)] = MapMaxLines, [nameof(ILabel.Font)] = MapFont, + [nameof(ILabel.LineBreakMode)] = MapLineBreakMode, [nameof(ILabel.Padding)] = MapPadding, [nameof(ILabel.TextDecorations)] = MapTextDecorations }; diff --git a/src/Core/src/Handlers/Label/LabelHandler.iOS.cs b/src/Core/src/Handlers/Label/LabelHandler.iOS.cs index 75848d2f4507..a4645c2a0cbd 100644 --- a/src/Core/src/Handlers/Label/LabelHandler.iOS.cs +++ b/src/Core/src/Handlers/Label/LabelHandler.iOS.cs @@ -23,6 +23,11 @@ public static void MapCharacterSpacing(LabelHandler handler, ILabel label) handler.TypedNativeView?.UpdateCharacterSpacing(label); } + public static void MapLineBreakMode(LabelHandler handler, ILabel label) + { + handler.TypedNativeView?.UpdateLineBreakMode(label); + } + public static void MapMaxLines(LabelHandler handler, ILabel label) { handler.TypedNativeView?.UpdateMaxLines(label); diff --git a/src/Core/src/Platform/Android/LabelExtensions.cs b/src/Core/src/Platform/Android/LabelExtensions.cs index 17334407afff..33498ce14915 100644 --- a/src/Core/src/Platform/Android/LabelExtensions.cs +++ b/src/Core/src/Platform/Android/LabelExtensions.cs @@ -1,4 +1,5 @@ using Android.Graphics; +using Android.Text; using Android.Util; using Android.Widget; @@ -39,6 +40,11 @@ public static void UpdateFont(this TextView textView, ILabel label, IFontManager textView.SetTextSize(ComplexUnitType.Sp, sp); } + public static void UpdateLineBreakMode(this TextView textView, ILabel label) + { + textView.SetLineBreakMode(label); + } + public static void UpdateMaxLines(this TextView textView, ILabel label) { int maxLinex = label.MaxLines; @@ -76,5 +82,47 @@ public static void UpdateTextDecorations(this TextView textView, ILabel label) else textView.PaintFlags |= PaintFlags.UnderlineText; } + + internal static void SetLineBreakMode(this TextView textView, ILabel label) + { + var lineBreakMode = label.LineBreakMode; + + int maxLines = label.MaxLines; + if (maxLines <= 0) + maxLines = int.MaxValue; + + bool singleLine = false; + + switch (lineBreakMode) + { + case LineBreakMode.NoWrap: + maxLines = 1; + textView.Ellipsize = null; + break; + case LineBreakMode.WordWrap: + textView.Ellipsize = null; + break; + case LineBreakMode.CharacterWrap: + textView.Ellipsize = null; + break; + case LineBreakMode.HeadTruncation: + maxLines = 1; + singleLine = true; // Workaround for bug in older Android API versions (https://bugzilla.xamarin.com/show_bug.cgi?id=49069) + textView.Ellipsize = TextUtils.TruncateAt.Start; + break; + case LineBreakMode.TailTruncation: + maxLines = 1; + textView.Ellipsize = TextUtils.TruncateAt.End; + break; + case LineBreakMode.MiddleTruncation: + maxLines = 1; + singleLine = true; // Workaround for bug in older Android API versions (https://bugzilla.xamarin.com/show_bug.cgi?id=49069) + textView.Ellipsize = TextUtils.TruncateAt.Middle; + break; + } + + textView.SetSingleLine(singleLine); + textView.SetMaxLines(maxLines); + } } } \ No newline at end of file diff --git a/src/Core/src/Platform/iOS/LabelExtensions.cs b/src/Core/src/Platform/iOS/LabelExtensions.cs index aeb14cac1cf0..3aff5d641914 100644 --- a/src/Core/src/Platform/iOS/LabelExtensions.cs +++ b/src/Core/src/Platform/iOS/LabelExtensions.cs @@ -47,6 +47,11 @@ public static void UpdateFont(this UILabel nativeLabel, ILabel label, IFontManag nativeLabel.UpdateCharacterSpacing(label); } + public static void UpdateLineBreakMode(this UILabel nativeLabel, ILabel label) + { + SetLineBreakMode(nativeLabel, label); + } + public static void UpdateMaxLines(this UILabel nativeLabel, ILabel label) { int maxLines = label.MaxLines; @@ -66,6 +71,41 @@ public static void UpdatePadding(this MauiLabel nativeLabel, ILabel label) (float)label.Padding.Right); } + internal static void SetLineBreakMode(this UILabel nativeLabel, ILabel label) + { + int maxLines = label.MaxLines; + if (maxLines < 0) + maxLines = 0; + + switch (label.LineBreakMode) + { + case LineBreakMode.NoWrap: + nativeLabel.LineBreakMode = UILineBreakMode.Clip; + maxLines = 1; + break; + case LineBreakMode.WordWrap: + nativeLabel.LineBreakMode = UILineBreakMode.WordWrap; + break; + case LineBreakMode.CharacterWrap: + nativeLabel.LineBreakMode = UILineBreakMode.CharacterWrap; + break; + case LineBreakMode.HeadTruncation: + nativeLabel.LineBreakMode = UILineBreakMode.HeadTruncation; + maxLines = 1; + break; + case LineBreakMode.MiddleTruncation: + nativeLabel.LineBreakMode = UILineBreakMode.MiddleTruncation; + maxLines = 1; + break; + case LineBreakMode.TailTruncation: + nativeLabel.LineBreakMode = UILineBreakMode.TailTruncation; + maxLines = 1; + break; + } + + nativeLabel.Lines = maxLines; + } + public static void UpdateTextDecorations(this UILabel nativeLabel, ILabel label) { if (nativeLabel.AttributedText != null && !(nativeLabel.AttributedText?.Length > 0)) diff --git a/src/Core/tests/DeviceTests/AssertionExtensions.Android.cs b/src/Core/tests/DeviceTests/AssertionExtensions.Android.cs index 39f09bee3058..e9bd48341687 100644 --- a/src/Core/tests/DeviceTests/AssertionExtensions.Android.cs +++ b/src/Core/tests/DeviceTests/AssertionExtensions.Android.cs @@ -2,6 +2,7 @@ using System.IO; using System.Threading.Tasks; using Android.Graphics; +using Android.Text; using Android.Views; using Android.Widget; using Xunit; @@ -168,5 +169,17 @@ public static async Task AssertColorAtTopRight(this AView view, AColor e var bitmap = await view.ToBitmap(); return bitmap.AssertColorAtTopRight(expectedColor); } + + public static TextUtils.TruncateAt ToNative(this LineBreakMode mode) => + mode switch + { + LineBreakMode.NoWrap => null, + LineBreakMode.WordWrap => null, + LineBreakMode.CharacterWrap => null, + LineBreakMode.HeadTruncation => TextUtils.TruncateAt.Start, + LineBreakMode.TailTruncation => TextUtils.TruncateAt.End, + LineBreakMode.MiddleTruncation => TextUtils.TruncateAt.Middle, + _ => throw new ArgumentOutOfRangeException(nameof(mode)) + }; } } \ No newline at end of file diff --git a/src/Core/tests/DeviceTests/AssertionExtensions.iOS.cs b/src/Core/tests/DeviceTests/AssertionExtensions.iOS.cs index 5ef5fb2d7b5d..f5fefd065e62 100644 --- a/src/Core/tests/DeviceTests/AssertionExtensions.iOS.cs +++ b/src/Core/tests/DeviceTests/AssertionExtensions.iOS.cs @@ -183,5 +183,17 @@ public static UIImage AssertContainsColor(this UIImage bitmap, UIColor expectedC Assert.True(false, CreateColorError(bitmap, $"Color {expectedColor} not found.")); return bitmap; } + + public static UILineBreakMode ToNative(this LineBreakMode mode) => + mode switch + { + LineBreakMode.NoWrap => UILineBreakMode.Clip, + LineBreakMode.WordWrap => UILineBreakMode.WordWrap, + LineBreakMode.CharacterWrap => UILineBreakMode.CharacterWrap, + LineBreakMode.HeadTruncation => UILineBreakMode.HeadTruncation, + LineBreakMode.TailTruncation => UILineBreakMode.TailTruncation, + LineBreakMode.MiddleTruncation => UILineBreakMode.MiddleTruncation, + _ => throw new ArgumentOutOfRangeException(nameof(mode)) + }; } } \ No newline at end of file diff --git a/src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.Android.cs b/src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.Android.cs index 9c5234497de3..3944a676cdf0 100644 --- a/src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.Android.cs +++ b/src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.Android.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using Android.Graphics; +using Android.Text; using Android.Widget; using Microsoft.Extensions.DependencyInjection; using Microsoft.Maui.DeviceTests.Stubs; @@ -38,6 +39,21 @@ public async Task FontFamilyInitializesCorrectly(string family) Assert.NotEqual(fontManager.DefaultTypeface, nativeLabel.Typeface); } + [Fact(DisplayName = "Negative MaxLines value with wrap is correct")] + public async Task NegativeMaxValueWithWrapIsCorrect() + { + var label = new LabelStub() + { + Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit", + MaxLines = -1, + LineBreakMode = LineBreakMode.WordWrap + }; + + var nativeValue = await GetValueAsync(label, GetNativeMaxLines); + + Assert.Equal(int.MaxValue, nativeValue); + } + [Fact(DisplayName = "Padding Initializes Correctly")] public async Task PaddingInitializesCorrectly() { @@ -128,6 +144,9 @@ Task ValidateNativeBackgroundColor(ILabel label, Color color) double GetNativeCharacterSpacing(LabelHandler labelHandler) => Math.Round(GetNativeLabel(labelHandler).LetterSpacing / UnitExtensions.EmCoefficient, 4); + TextUtils.TruncateAt GetNativeLineBreakMode(LabelHandler labelHandler) => + GetNativeLabel(labelHandler).Ellipsize; + PaintFlags GetNativeTextDecorations(LabelHandler labelHandler) => GetNativeLabel(labelHandler).PaintFlags; } diff --git a/src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.cs index fa9ee3dd44b0..799fa190b8df 100644 --- a/src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.cs +++ b/src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.cs @@ -150,6 +150,117 @@ await ValidateUnrelatedPropertyUnaffected( () => label.Text = newText); } + [Fact(DisplayName = "LineBreakMode Initializes Correctly")] + public async Task LineBreakModeInitializesCorrectly() + { + var xplatLineBreakMode = LineBreakMode.TailTruncation; + + var label = new LabelStub() + { + LineBreakMode = xplatLineBreakMode + }; + + var expectedValue = xplatLineBreakMode.ToNative(); + + var values = await GetValueAsync(label, (handler) => + { + return new + { + ViewValue = label.LineBreakMode, + NativeViewValue = GetNativeLineBreakMode(handler) + }; + }); + + Assert.Equal(xplatLineBreakMode, values.ViewValue); + Assert.Equal(expectedValue, values.NativeViewValue); + } + + [Fact(DisplayName = "LineBreakMode does not affect to MaxLines")] + public async Task LineBreakModeDoesNotAffectMaxLines() + { + var label = new LabelStub() + { + Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit", + MaxLines = 3, + LineBreakMode = LineBreakMode.WordWrap, + }; + + var handler = await CreateHandlerAsync(label); + var nativeLabel = GetNativeLabel(handler); + + await InvokeOnMainThreadAsync(() => + { + Assert.Equal(3, GetNativeMaxLines(handler)); + Assert.Equal(LineBreakMode.WordWrap.ToNative(), GetNativeLineBreakMode(handler)); + + label.LineBreakMode = LineBreakMode.CharacterWrap; + nativeLabel.UpdateLineBreakMode(label); + + Assert.Equal(3, GetNativeMaxLines(handler)); + Assert.Equal(LineBreakMode.CharacterWrap.ToNative(), GetNativeLineBreakMode(handler)); + }); + } + + [Fact(DisplayName = "Single LineBreakMode changes MaxLines")] + public async Task SingleLineBreakModeChangesMaxLines() + { + var label = new LabelStub() + { + Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit", + MaxLines = 3, + LineBreakMode = LineBreakMode.WordWrap, + }; + + var handler = await CreateHandlerAsync(label); + var nativeLabel = GetNativeLabel(handler); + + await InvokeOnMainThreadAsync(() => + { + Assert.Equal(3, GetNativeMaxLines(handler)); + Assert.Equal(LineBreakMode.WordWrap.ToNative(), GetNativeLineBreakMode(handler)); + + label.LineBreakMode = LineBreakMode.HeadTruncation; + nativeLabel.UpdateLineBreakMode(label); + + Assert.Equal(1, GetNativeMaxLines(handler)); + Assert.Equal(LineBreakMode.HeadTruncation.ToNative(), GetNativeLineBreakMode(handler)); + }); + } + + [Theory(DisplayName = "Unsetting single LineBreakMode resets MaxLines")] + [InlineData(LineBreakMode.HeadTruncation)] + [InlineData(LineBreakMode.NoWrap)] + public async Task UnsettingSingleLineBreakModeResetsMaxLines(LineBreakMode newMode) + { + var label = new LabelStub() + { + Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit", + MaxLines = 3, + LineBreakMode = LineBreakMode.WordWrap, + }; + + var handler = await CreateHandlerAsync(label); + var nativeLabel = GetNativeLabel(handler); + + await InvokeOnMainThreadAsync(() => + { + Assert.Equal(3, GetNativeMaxLines(handler)); + Assert.Equal(LineBreakMode.WordWrap.ToNative(), GetNativeLineBreakMode(handler)); + + label.LineBreakMode = newMode; + nativeLabel.UpdateLineBreakMode(label); + + Assert.Equal(1, GetNativeMaxLines(handler)); + Assert.Equal(newMode.ToNative(), GetNativeLineBreakMode(handler)); + + label.LineBreakMode = LineBreakMode.WordWrap; + nativeLabel.UpdateLineBreakMode(label); + + Assert.Equal(3, GetNativeMaxLines(handler)); + Assert.Equal(LineBreakMode.WordWrap.ToNative(), GetNativeLineBreakMode(handler)); + }); + } + [Fact(DisplayName = "MaxLines Initializes Correctly")] public async Task MaxLinesInitializesCorrectly() { diff --git a/src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.iOS.cs b/src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.iOS.cs index b34111281e2b..fee3ff3c191c 100644 --- a/src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.iOS.cs +++ b/src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.iOS.cs @@ -36,7 +36,22 @@ public async Task FontFamilyInitializesCorrectly(string family) Assert.NotEqual(fontManager.DefaultFont.FamilyName, nativeFont.FamilyName); } - [Fact] + [Fact(DisplayName = "Negative MaxLines value with wrap is correct")] + public async Task NegativeMaxValueWithWrapIsCorrect() + { + var label = new LabelStub() + { + Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit", + MaxLines = -1, + LineBreakMode = LineBreakMode.WordWrap, + }; + + var nativeValue = await GetValueAsync(label, GetNativeMaxLines); + + Assert.Equal(0, nativeValue); + } + + [Fact(DisplayName = "Padding Initializes Correctly")] public async Task PaddingInitializesCorrectly() { var label = new LabelStub() @@ -124,6 +139,9 @@ Task ValidateNativeBackgroundColor(ILabel label, Color color) }); } + UILineBreakMode GetNativeLineBreakMode(LabelHandler labelHandler) => + GetNativeLabel(labelHandler).LineBreakMode; + NSAttributedString GetNativeTextDecorations(LabelHandler labelHandler) => GetNativeLabel(labelHandler).AttributedText; } diff --git a/src/Core/tests/DeviceTests/Stubs/LabelStub.cs b/src/Core/tests/DeviceTests/Stubs/LabelStub.cs index 77062f213852..695abc15a102 100644 --- a/src/Core/tests/DeviceTests/Stubs/LabelStub.cs +++ b/src/Core/tests/DeviceTests/Stubs/LabelStub.cs @@ -12,6 +12,8 @@ public partial class LabelStub : StubBase, ILabel public Font Font { get; set; } + public LineBreakMode LineBreakMode { get; set; } = LineBreakMode.WordWrap; + public TextDecorations TextDecorations { get; set; } public int MaxLines { get; set; } = -1;