diff --git a/ReactWindows/ReactNative.Net46/ReactNative.Net46.csproj b/ReactWindows/ReactNative.Net46/ReactNative.Net46.csproj index 214e74d4943..2e7cadf8a34 100644 --- a/ReactWindows/ReactNative.Net46/ReactNative.Net46.csproj +++ b/ReactWindows/ReactNative.Net46/ReactNative.Net46.csproj @@ -107,6 +107,7 @@ $(SolutionDir)\packages\System.Reactive.Windows.Threading.3.1.1\lib\net45\System.Reactive.Windows.Threading.dll True + diff --git a/ReactWindows/ReactNative.Net46/Views/Text/ReactTextViewManager.cs b/ReactWindows/ReactNative.Net46/Views/Text/ReactTextViewManager.cs index ddfb691e93f..6c442affa82 100644 --- a/ReactWindows/ReactNative.Net46/Views/Text/ReactTextViewManager.cs +++ b/ReactWindows/ReactNative.Net46/Views/Text/ReactTextViewManager.cs @@ -1,7 +1,10 @@ -using ReactNative.UIManager; +using ReactNative.Reflection; +using ReactNative.UIManager; using ReactNative.UIManager.Annotations; using System; using System.Collections; +using System.Collections.Generic; +using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; @@ -40,6 +43,33 @@ public void SetColor(TextBlock view, uint? color) : null; } + /// + /// Sets the TextDecorationLine for the node. + /// + /// The view. + /// The TextDecorationLine value. + [ReactProp(ViewProps.TextDecorationLine)] + public void SetTextDecorationLine(TextBlock view, string textDecorationLineValue) + { + var textDecorationLine = EnumHelpers.ParseNullable(textDecorationLineValue) ?? TextDecorationLine.None; + switch (textDecorationLine) + { + case TextDecorationLine.Underline: + view.TextDecorations = TextDecorations.Underline; + break; + case TextDecorationLine.LineThrough: + view.TextDecorations = TextDecorations.Strikethrough; + break; + case TextDecorationLine.UnderlineLineThrough: + view.TextDecorations = new TextDecorationCollection(TextDecorations.Underline.Concat(TextDecorations.Strikethrough)); + break; + case TextDecorationLine.None: + default: + view.TextDecorations = null; + break; + } + } + /// /// Sets whether or not the text is selectable. /// diff --git a/ReactWindows/ReactNative.Shared/ReactNative.Shared.projitems b/ReactWindows/ReactNative.Shared/ReactNative.Shared.projitems index 7f2468883e7..016b19f019a 100644 --- a/ReactWindows/ReactNative.Shared/ReactNative.Shared.projitems +++ b/ReactWindows/ReactNative.Shared/ReactNative.Shared.projitems @@ -231,6 +231,7 @@ + diff --git a/ReactWindows/ReactNative.Shared/Reflection/EnumHelpers.cs b/ReactWindows/ReactNative.Shared/Reflection/EnumHelpers.cs index a489cb0e7ab..b24165f1efb 100644 --- a/ReactWindows/ReactNative.Shared/Reflection/EnumHelpers.cs +++ b/ReactWindows/ReactNative.Shared/Reflection/EnumHelpers.cs @@ -2,6 +2,8 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; +using System.Reflection; +using System.Runtime.Serialization; using static System.FormattableString; namespace ReactNative.Reflection @@ -15,11 +17,7 @@ public static T Parse(string value) { var lookup = s_enumCache.GetOrAdd( typeof(T), - type => Enum.GetValues(type) - .Cast() - .ToDictionary( - e => Normalize(e.ToString()), - e => e)); + type => EnumToDictionary(type)); var result = default(object); if (!lookup.TryGetValue(Normalize(value), out result)) @@ -41,6 +39,30 @@ public static T Parse(string value) return Parse(value); } + private static Dictionary EnumToDictionary(Type type) + { + var result = new Dictionary(); + + var names = Enum.GetNames(type); + var values = Enum.GetValues(type); + + for (int i = 0; i < values.Length; ++i) + { + string name = names[i]; + object value = values.GetValue(i); + + result.Add(Normalize(name), value); + + var enumMemberAttribute = type.GetField(name).GetCustomAttribute(typeof(EnumMemberAttribute), false); + if (enumMemberAttribute != null) + { + result.Add(Normalize(((EnumMemberAttribute)enumMemberAttribute).Value), value); + } + } + + return result; + } + private static string Normalize(string value) { return value.ToLowerInvariant().Replace("-", ""); diff --git a/ReactWindows/ReactNative.Shared/Views/Text/ReactSpanViewManager.cs b/ReactWindows/ReactNative.Shared/Views/Text/ReactSpanViewManager.cs index 73d0d46828a..ecfd1390773 100644 --- a/ReactWindows/ReactNative.Shared/Views/Text/ReactSpanViewManager.cs +++ b/ReactWindows/ReactNative.Shared/Views/Text/ReactSpanViewManager.cs @@ -1,7 +1,11 @@ -using ReactNative.UIManager; +using ReactNative.Reflection; +using ReactNative.UIManager; using ReactNative.UIManager.Annotations; using System; using System.Collections; +using System.Collections.Generic; +using System.Linq; + #if WINDOWS_UWP using Windows.UI.Xaml; using Windows.UI.Xaml.Documents; @@ -55,6 +59,36 @@ public void SetColor(Span view, uint? color) : null; } +#if !WINDOWS_UWP + /// + /// Sets the TextDecorationLine for the node. + /// + /// The view. + /// The TextDecorationLine value. + [ReactProp(ViewProps.TextDecorationLine)] + public void SetTextDecorationLine(Span view, string textDecorationLineValue) + { + var textDecorationLine = EnumHelpers.ParseNullable(textDecorationLineValue) ?? TextDecorationLine.None; + + switch (textDecorationLine) + { + case TextDecorationLine.Underline: + view.TextDecorations = TextDecorations.Underline; + break; + case TextDecorationLine.LineThrough: + view.TextDecorations = TextDecorations.Strikethrough; + break; + case TextDecorationLine.UnderlineLineThrough: + view.TextDecorations = new TextDecorationCollection(TextDecorations.Underline.Concat(TextDecorations.Strikethrough)); + break; + case TextDecorationLine.None: + default: + view.TextDecorations = null; + break; + } + } +#endif + /// /// Adds a child at the given index. /// diff --git a/ReactWindows/ReactNative.Shared/Views/Text/TextDecorationLine.cs b/ReactWindows/ReactNative.Shared/Views/Text/TextDecorationLine.cs new file mode 100644 index 00000000000..94575ed88ce --- /dev/null +++ b/ReactWindows/ReactNative.Shared/Views/Text/TextDecorationLine.cs @@ -0,0 +1,28 @@ +using System.Runtime.Serialization; + +namespace ReactNative.Views.Text +{ + /// + /// TextDecorationLine values. + /// + public enum TextDecorationLine + { + /// + /// Text has no line decoration. + /// + None, + /// + /// Text is Underlined. + /// + Underline, + /// + /// Text is Stroke out. + /// + LineThrough, + /// + /// Text is both Underlined and Stroke out. + /// + [EnumMember(Value = "underline line-through")] + UnderlineLineThrough + } +}