forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement] Allow underline and strikethrough text decorations on l…
…abels and spans (xamarin#2221) * Fixes xamarin#1632 * Allow underline and strikethrought text decorations on labels and spans * revert some files * pr feedback adjustments * remove docs * rename interface * reorder enum * clean up whitespace * adjust tizen renderer * add gallery demo for setting both underline and strike * allow multiple values of enum to be set in xaml/css * use normal null check * use nameof * include paragraph style * tab alignment * rebase from upstream * pass control to update method on UWP * correct text decorations type converter * reset run text instead of label text on UWP when spans are used * add tests for text decoration converter
- Loading branch information
Showing
19 changed files
with
361 additions
and
18 deletions.
There are no files selected for viewing
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,28 @@ | ||
using System.Globalization; | ||
|
||
using NUnit.Framework; | ||
|
||
|
||
namespace Xamarin.Forms.Core.UnitTests | ||
{ | ||
[TestFixture] | ||
public class TextDecorationUnitTests : BaseTestFixture | ||
{ | ||
[Test] | ||
public void TestTextDecorationConverter() | ||
{ | ||
var converter = new TextDecorationConverter(); | ||
TextDecorations both = TextDecorations.Strikethrough; | ||
both |= TextDecorations.Underline; | ||
Assert.True(converter.CanConvertFrom(typeof(string))); | ||
Assert.AreEqual(TextDecorations.Strikethrough, converter.ConvertFromInvariantString("strikethrough")); | ||
Assert.AreEqual(TextDecorations.Underline, converter.ConvertFromInvariantString("underline")); | ||
Assert.AreEqual(TextDecorations.Strikethrough, converter.ConvertFromInvariantString("line-through")); | ||
Assert.AreEqual(TextDecorations.None, converter.ConvertFromInvariantString("none")); | ||
Assert.AreEqual(both, converter.ConvertFromInvariantString("strikethrough underline")); | ||
Assert.AreEqual(both, converter.ConvertFromInvariantString("underline strikethrough")); | ||
Assert.AreEqual(both, converter.ConvertFromInvariantString("underline line-through")); | ||
Assert.AreEqual(both, converter.ConvertFromInvariantString("line-through underline")); | ||
} | ||
} | ||
} |
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,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Xamarin.Forms | ||
{ | ||
[Flags] | ||
[TypeConverter(typeof(TextDecorationConverter))] | ||
public enum TextDecorations | ||
{ | ||
None = 0, | ||
Underline = 1 << 0, | ||
Strikethrough = 1 << 1, | ||
} | ||
static class DecorableTextElement | ||
{ | ||
public static readonly BindableProperty TextDecorationsProperty = BindableProperty.Create(nameof(IDecorableTextElement.TextDecorations), typeof(TextDecorations), typeof(IDecorableTextElement), TextDecorations.None); | ||
} | ||
|
||
[Xaml.TypeConversion(typeof(TextDecorations))] | ||
public class TextDecorationConverter : TypeConverter | ||
{ | ||
public override object ConvertFromInvariantString(string value) | ||
{ | ||
TextDecorations result = TextDecorations.None; | ||
if (value == null) | ||
throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(TextDecorations))); | ||
|
||
var valueArr = value.Split(','); | ||
|
||
if (valueArr.Length <= 1) | ||
valueArr = value.Split(' '); | ||
|
||
foreach (var item in valueArr) | ||
{ | ||
if (Enum.TryParse(item.Trim(), true, out TextDecorations textDecorations)) | ||
result |= textDecorations; | ||
else if (item.Equals("line-through", StringComparison.OrdinalIgnoreCase)) | ||
result |= TextDecorations.Strikethrough; | ||
else | ||
throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", item, typeof(TextDecorations))); | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
|
||
} | ||
|
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,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Xamarin.Forms | ||
{ | ||
public interface IDecorableTextElement | ||
{ | ||
TextDecorations TextDecorations { get; set; } | ||
} | ||
} |
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
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.