From adb453930106461a6c1b43fbe8be43c5599081d5 Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Tue, 14 Aug 2018 10:14:11 -0400 Subject: [PATCH] Revert "prototype(FastText): Add option to use TextBlock for simple text (#1256)" (#1939) Reverts Microsoft/react-native-windows#1256. We need to update Text.windows.js to be in sync with the latest from react-native first. --- Libraries/Text/Text.windows.js | 275 ------------------ .../ReactNative.Net46.csproj | 1 - .../Shell/MainReactPackage.cs | 1 - .../Views/Text/ReactSimpleTextViewManager.cs | 42 --- .../Views/Text/ReactTextCompoundView.cs | 6 +- .../Views/Text/ReactTextShadowNode.cs | 24 +- .../UIManager/RootViewHelper.cs | 23 +- ReactWindows/ReactNative/ReactNative.csproj | 2 - .../ReactNative/Shell/MainReactPackage.cs | 1 - .../Views/Text/ReactSimpleTextShadowNode.cs | 273 ----------------- .../Views/Text/ReactSimpleTextViewManager.cs | 94 ------ 11 files changed, 9 insertions(+), 733 deletions(-) delete mode 100644 Libraries/Text/Text.windows.js delete mode 100644 ReactWindows/ReactNative.Net46/Views/Text/ReactSimpleTextViewManager.cs delete mode 100644 ReactWindows/ReactNative/Views/Text/ReactSimpleTextShadowNode.cs delete mode 100644 ReactWindows/ReactNative/Views/Text/ReactSimpleTextViewManager.cs diff --git a/Libraries/Text/Text.windows.js b/Libraries/Text/Text.windows.js deleted file mode 100644 index 585e43a5673..00000000000 --- a/Libraries/Text/Text.windows.js +++ /dev/null @@ -1,275 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @providesModule Text - * @flow - * @format - */ -'use strict'; - -const React = require('React'); -const ReactNative = require('ReactNative'); -const ReactNativeViewAttributes = require('ReactNativeViewAttributes'); -const TextPropTypes = require('TextPropTypes'); -const Touchable = require('Touchable'); -const UIManager = require('UIManager'); - -const createReactNativeComponentClass = require('createReactNativeComponentClass'); -const mergeFast = require('mergeFast'); -const processColor = require('processColor'); -const {ViewContextTypes} = require('ViewContext'); - -import type {PressEvent} from 'CoreEventTypes'; -import type {TextProps} from 'TextProps'; -import type {ViewChildContext} from 'ViewContext'; - -type State = { - isHighlighted: boolean, -}; - -type RectOffset = { - top: number, - left: number, - right: number, - bottom: number, -}; - -const PRESS_RECT_OFFSET = {top: 20, left: 20, right: 20, bottom: 30}; - -const viewConfig = { - validAttributes: mergeFast(ReactNativeViewAttributes.UIView, { - isHighlighted: true, - numberOfLines: true, - ellipsizeMode: true, - allowFontScaling: true, - disabled: true, - selectable: true, - selectionColor: true, - adjustsFontSizeToFit: true, - minimumFontScale: true, - textBreakStrategy: true, - }), - uiViewClassName: 'RCTText', -}; - -const simpleViewConfig = { - validAttributes: mergeFast(ReactNativeViewAttributes.UIView, { - isHighlighted: true, - numberOfLines: true, - ellipsizeMode: true, - allowFontScaling: true, - disabled: true, - selectable: true, - selectionColor: true, - adjustsFontSizeToFit: true, - minimumFontScale: true, - textBreakStrategy: true, - text: true, - }), - uiViewClassName: 'RCTSimpleText', -}; - -/** - * A React component for displaying text. - * - * See https://facebook.github.io/react-native/docs/text.html - */ -class Text extends ReactNative.NativeComponent { - static propTypes = TextPropTypes; - static childContextTypes = ViewContextTypes; - static contextTypes = ViewContextTypes; - - static defaultProps = { - accessible: true, - allowFontScaling: true, - ellipsizeMode: 'tail', - }; - - state = mergeFast(Touchable.Mixin.touchableGetInitialState(), { - isHighlighted: false, - }); - - viewConfig = viewConfig; - - getChildContext(): ViewChildContext { - return { - isInAParentText: true, - }; - } - - _handlers: ?Object; - - _hasPressHandler(): boolean { - return !!this.props.onPress || !!this.props.onLongPress; - } - /** - * These are assigned lazily the first time the responder is set to make plain - * text nodes as cheap as possible. - */ - touchableHandleActivePressIn: ?Function; - touchableHandleActivePressOut: ?Function; - touchableHandlePress: ?Function; - touchableHandleLongPress: ?Function; - touchableHandleResponderGrant: ?Function; - touchableHandleResponderMove: ?Function; - touchableHandleResponderRelease: ?Function; - touchableHandleResponderTerminate: ?Function; - touchableHandleResponderTerminationRequest: ?Function; - touchableGetPressRectOffset: ?Function; - - render(): React.Element { - let newProps = this.props; - if (this.props.onStartShouldSetResponder || this._hasPressHandler()) { - if (!this._handlers) { - this._handlers = { - onStartShouldSetResponder: (): boolean => { - const shouldSetFromProps = - this.props.onStartShouldSetResponder && - this.props.onStartShouldSetResponder(); - const setResponder = shouldSetFromProps || this._hasPressHandler(); - if (setResponder && !this.touchableHandleActivePressIn) { - // Attach and bind all the other handlers only the first time a touch - // actually happens. - for (const key in Touchable.Mixin) { - if (typeof Touchable.Mixin[key] === 'function') { - (this: any)[key] = Touchable.Mixin[key].bind(this); - } - } - this.touchableHandleActivePressIn = () => { - if ( - this.props.suppressHighlighting || - !this._hasPressHandler() - ) { - return; - } - this.setState({ - isHighlighted: true, - }); - }; - - this.touchableHandleActivePressOut = () => { - if ( - this.props.suppressHighlighting || - !this._hasPressHandler() - ) { - return; - } - this.setState({ - isHighlighted: false, - }); - }; - - this.touchableHandlePress = (e: PressEvent) => { - this.props.onPress && this.props.onPress(e); - }; - - this.touchableHandleLongPress = (e: PressEvent) => { - this.props.onLongPress && this.props.onLongPress(e); - }; - - this.touchableGetPressRectOffset = function(): RectOffset { - return this.props.pressRetentionOffset || PRESS_RECT_OFFSET; - }; - } - return setResponder; - }, - onResponderGrant: function(e: SyntheticEvent<>, dispatchID: string) { - // $FlowFixMe TouchableMixin handlers couldn't actually be null - this.touchableHandleResponderGrant(e, dispatchID); - this.props.onResponderGrant && - this.props.onResponderGrant.apply(this, arguments); - }.bind(this), - onResponderMove: function(e: SyntheticEvent<>) { - // $FlowFixMe TouchableMixin handlers couldn't actually be null - this.touchableHandleResponderMove(e); - this.props.onResponderMove && - this.props.onResponderMove.apply(this, arguments); - }.bind(this), - onResponderRelease: function(e: SyntheticEvent<>) { - // $FlowFixMe TouchableMixin handlers couldn't actually be null - this.touchableHandleResponderRelease(e); - this.props.onResponderRelease && - this.props.onResponderRelease.apply(this, arguments); - }.bind(this), - onResponderTerminate: function(e: SyntheticEvent<>) { - // $FlowFixMe TouchableMixin handlers couldn't actually be null - this.touchableHandleResponderTerminate(e); - this.props.onResponderTerminate && - this.props.onResponderTerminate.apply(this, arguments); - }.bind(this), - onResponderTerminationRequest: function(): boolean { - // Allow touchable or props.onResponderTerminationRequest to deny - // the request - // $FlowFixMe TouchableMixin handlers couldn't actually be null - var allowTermination = this.touchableHandleResponderTerminationRequest(); - if (allowTermination && this.props.onResponderTerminationRequest) { - allowTermination = this.props.onResponderTerminationRequest.apply( - this, - arguments, - ); - } - return allowTermination; - }.bind(this), - }; - } - newProps = { - ...this.props, - ...this._handlers, - isHighlighted: this.state.isHighlighted, - }; - } - if (newProps.selectionColor != null) { - newProps = { - ...newProps, - selectionColor: processColor(newProps.selectionColor), - }; - } - if (Touchable.TOUCH_TARGET_DEBUG && newProps.onPress) { - newProps = { - ...newProps, - style: [this.props.style, {color: 'magenta'}], - }; - } - if (this.context.isInAParentText) { - return ; - } else { - if (RCTSimpleText && typeof newProps.children === 'string') { - let simpleProps = {}; - Object.assign(simpleProps, newProps); - simpleProps.text = simpleProps.children; - delete simpleProps.children; - return ; - } - - return ; - } - } -} - -var RCTText = createReactNativeComponentClass( - viewConfig.uiViewClassName, - () => viewConfig, -); -var RCTVirtualText = RCTText; -var RCTSimpleText; - -if (UIManager.RCTVirtualText) { - RCTVirtualText = createReactNativeComponentClass('RCTVirtualText', () => ({ - validAttributes: mergeFast(ReactNativeViewAttributes.UIView, { - isHighlighted: true, - }), - uiViewClassName: 'RCTVirtualText', - })); -} - -if (UIManager.RCTSimpleText) { - RCTSimpleText = createReactNativeComponentClass( - simpleViewConfig.uiViewClassName, - () => simpleViewConfig, - ); -} - -module.exports = Text; diff --git a/ReactWindows/ReactNative.Net46/ReactNative.Net46.csproj b/ReactWindows/ReactNative.Net46/ReactNative.Net46.csproj index ab228e9f104..c801044f105 100644 --- a/ReactWindows/ReactNative.Net46/ReactNative.Net46.csproj +++ b/ReactWindows/ReactNative.Net46/ReactNative.Net46.csproj @@ -172,7 +172,6 @@ - diff --git a/ReactWindows/ReactNative.Net46/Shell/MainReactPackage.cs b/ReactWindows/ReactNative.Net46/Shell/MainReactPackage.cs index e4043005b6d..f660e89da40 100644 --- a/ReactWindows/ReactNative.Net46/Shell/MainReactPackage.cs +++ b/ReactWindows/ReactNative.Net46/Shell/MainReactPackage.cs @@ -75,7 +75,6 @@ public IReadOnlyList CreateViewManagers( { return new List { - new ReactSimpleTextViewManager(), //new ReactFlipViewManager(), new ReactImageManager(), new ReactProgressBarViewManager(), diff --git a/ReactWindows/ReactNative.Net46/Views/Text/ReactSimpleTextViewManager.cs b/ReactWindows/ReactNative.Net46/Views/Text/ReactSimpleTextViewManager.cs deleted file mode 100644 index 3442919ec4b..00000000000 --- a/ReactWindows/ReactNative.Net46/Views/Text/ReactSimpleTextViewManager.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System.Windows.Controls; - -namespace ReactNative.Views.Text -{ - /// - /// The view manager for simple text views. - /// - public class ReactSimpleTextViewManager : ReactTextViewManager - { - /// - /// Name of the view manager. - /// - public override string Name - { - get - { - return "RCTSimpleText"; - } - } - - /// - /// Gets the number of children for the view. - /// - /// The view parent. - /// The number of children. - public override int GetChildCount(TextBlock parent) - { - return 0; - } - - /// - /// Removes the children from the view. - /// - /// The view parent. - public override void RemoveAllChildren(TextBlock parent) - { - } - } -} diff --git a/ReactWindows/ReactNative.Net46/Views/Text/ReactTextCompoundView.cs b/ReactWindows/ReactNative.Net46/Views/Text/ReactTextCompoundView.cs index 3af82953cfc..3cb108becfc 100644 --- a/ReactWindows/ReactNative.Net46/Views/Text/ReactTextCompoundView.cs +++ b/ReactWindows/ReactNative.Net46/Views/Text/ReactTextCompoundView.cs @@ -1,8 +1,7 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. using ReactNative.UIManager; -using System.Linq; using System.Windows; using System.Windows.Controls; @@ -14,8 +13,7 @@ public int GetReactTagAtPoint(UIElement reactView, Point point) { var richTextBlock = reactView.As(); var textPointer = richTextBlock.GetPositionFromPoint(point, true); - var parentView = RootViewHelper.GetReactViewHierarchy(textPointer.Parent).First(); - return parentView.GetTag(); + return textPointer.Parent.GetTag(); } } } diff --git a/ReactWindows/ReactNative.Net46/Views/Text/ReactTextShadowNode.cs b/ReactWindows/ReactNative.Net46/Views/Text/ReactTextShadowNode.cs index df184065e19..95b55dbcedf 100644 --- a/ReactWindows/ReactNative.Net46/Views/Text/ReactTextShadowNode.cs +++ b/ReactWindows/ReactNative.Net46/Views/Text/ReactTextShadowNode.cs @@ -30,8 +30,6 @@ public class ReactTextShadowNode : LayoutShadowNode private string _fontFamily; - private string _text; - /// /// Instantiates a . /// @@ -41,21 +39,6 @@ public ReactTextShadowNode() MeasureText(this, node, width, widthMode, height, heightMode); } - /// - /// Sets the text for the node. - /// - /// The text. - [ReactProp("text")] - public void SetText(string text) - { - var nonNullText = text ?? ""; - if (_text != nonNullText) - { - _text = nonNullText; - MarkUpdated(); - } - } - /// /// Sets the font size for the node. /// @@ -242,11 +225,8 @@ public void UpdateTextBlock(TextBlock textBlock) private void UpdateTextBlockCore(TextBlock textBlock, bool measureOnly) { - if (ChildCount == 0 && _text != null) - { - textBlock.Text = _text; - } - + //textBlock.CharacterSpacing = _letterSpacing; + //textBlock.MaxLines = _numberOfLines; textBlock.LineHeight = _lineHeight != 0 ? _lineHeight : double.NaN; textBlock.TextAlignment = _textAlignment; textBlock.FontSize = _fontSize ?? 15; diff --git a/ReactWindows/ReactNative.Shared/UIManager/RootViewHelper.cs b/ReactWindows/ReactNative.Shared/UIManager/RootViewHelper.cs index fcf5dcebba8..5023f46ec47 100644 --- a/ReactWindows/ReactNative.Shared/UIManager/RootViewHelper.cs +++ b/ReactWindows/ReactNative.Shared/UIManager/RootViewHelper.cs @@ -9,7 +9,6 @@ using Windows.UI.Xaml.Media; #else using System.Windows; -using System.Windows.Documents; using System.Windows.Media; #endif @@ -105,24 +104,12 @@ private static DependencyObject GetParent(DependencyObject view, bool findRoot) if (!findRoot) { - var frameworkElement = view as FrameworkElement; - if (frameworkElement != null) - { - return frameworkElement.Parent; - } -#if !WINDOWS_UWP - - var frameworkContentElement = view as FrameworkContentElement; - if (frameworkContentElement != null) - { - return frameworkContentElement.Parent; - } -#endif - - return null; + return (view as FrameworkElement)?.Parent; + } + else + { + return VisualTreeHelper.GetParent(view); } - - return VisualTreeHelper.GetParent(view); } } } diff --git a/ReactWindows/ReactNative/ReactNative.csproj b/ReactWindows/ReactNative/ReactNative.csproj index c8a07707ebd..9e8058c1704 100644 --- a/ReactWindows/ReactNative/ReactNative.csproj +++ b/ReactWindows/ReactNative/ReactNative.csproj @@ -171,8 +171,6 @@ - - diff --git a/ReactWindows/ReactNative/Shell/MainReactPackage.cs b/ReactWindows/ReactNative/Shell/MainReactPackage.cs index 8ea220b177f..e75a65cdf8c 100644 --- a/ReactWindows/ReactNative/Shell/MainReactPackage.cs +++ b/ReactWindows/ReactNative/Shell/MainReactPackage.cs @@ -83,7 +83,6 @@ public IReadOnlyList CreateViewManagers( { return new List { - new ReactSimpleTextViewManager(), new ReactFlipViewManager(), new ReactImageManager(), new ReactProgressBarViewManager(), diff --git a/ReactWindows/ReactNative/Views/Text/ReactSimpleTextShadowNode.cs b/ReactWindows/ReactNative/Views/Text/ReactSimpleTextShadowNode.cs deleted file mode 100644 index 06c5f837f76..00000000000 --- a/ReactWindows/ReactNative/Views/Text/ReactSimpleTextShadowNode.cs +++ /dev/null @@ -1,273 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Facebook.Yoga; -using ReactNative.Reflection; -using ReactNative.UIManager; -using ReactNative.UIManager.Annotations; -using System; -using Windows.Foundation; -using Windows.UI.Text; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Media; - -namespace ReactNative.Views.Text -{ - /// - /// The shadow node implementation for text views. - /// - public class ReactSimpleTextShadowNode : LayoutShadowNode - { - private int _letterSpacing; - private int _numberOfLines; - - private double? _fontSize; - private double _lineHeight; - - private bool _allowFontScaling; - - private FontStyle? _fontStyle; - private FontWeight? _fontWeight; - private TextAlignment _textAlignment = TextAlignment.DetectFromContent; - - private string _fontFamily; - - private string _text = ""; - - /// - /// Instantiates a . - /// - public ReactSimpleTextShadowNode() - { - MeasureFunction = (node, width, widthMode, height, heightMode) => - MeasureText(this, node, width, widthMode, height, heightMode); - } - - /// - /// Sets the text on the view. - /// - /// The text. - [ReactProp("text")] - public void SetText(string text) - { - _text = text ?? ""; - MarkUpdated(); - } - - /// - /// Sets the font size for the node. - /// - /// The font size. - [ReactProp(ViewProps.FontSize)] - public void SetFontSize(double? fontSize) - { - if (_fontSize != fontSize) - { - _fontSize = fontSize; - MarkUpdated(); - } - } - - /// - /// Sets the font family for the node. - /// - /// The font family. - [ReactProp(ViewProps.FontFamily)] - public void SetFontFamily(string fontFamily) - { - if (_fontFamily != fontFamily) - { - _fontFamily = fontFamily; - MarkUpdated(); - } - } - - /// - /// Sets the font weight for the node. - /// - /// The font weight string. - [ReactProp(ViewProps.FontWeight)] - public void SetFontWeight(string fontWeightValue) - { - var fontWeight = FontStyleHelpers.ParseFontWeight(fontWeightValue); - if (_fontWeight.HasValue != fontWeight.HasValue || - (_fontWeight.HasValue && fontWeight.HasValue && - _fontWeight.Value.Weight != fontWeight.Value.Weight)) - { - _fontWeight = fontWeight; - MarkUpdated(); - } - } - - /// - /// Sets the font style for the node. - /// - /// The font style string. - [ReactProp(ViewProps.FontStyle)] - public void SetFontStyle(string fontStyleValue) - { - var fontStyle = EnumHelpers.ParseNullable(fontStyleValue); - if (_fontStyle != fontStyle) - { - _fontStyle = fontStyle; - MarkUpdated(); - } - } - - /// - /// Sets the letter spacing for the node. - /// - /// The letter spacing. - [ReactProp(ViewProps.LetterSpacing)] - public void SetLetterSpacing(int letterSpacing) - { - var spacing = 50 * letterSpacing; // TODO: Find exact multiplier (50) to match iOS - - if (_letterSpacing != spacing) - { - _letterSpacing = spacing; - MarkUpdated(); - } - } - - /// - /// Sets the line height. - /// - /// The line height. - [ReactProp(ViewProps.LineHeight)] - public virtual void SetLineHeight(double lineHeight) - { - if (_lineHeight != lineHeight) - { - _lineHeight = lineHeight; - MarkUpdated(); - } - } - - /// - /// Sets the maximum number of lines. - /// - /// Max number of lines. - [ReactProp(ViewProps.NumberOfLines)] - public virtual void SetNumberOfLines(int numberOfLines) - { - if (_numberOfLines != numberOfLines) - { - _numberOfLines = numberOfLines; - MarkUpdated(); - } - } - - /// - /// Sets the text alignment. - /// - /// The text alignment string. - [ReactProp(ViewProps.TextAlign)] - public void SetTextAlign(string textAlign) - { - var textAlignment = textAlign == "auto" || textAlign == null ? - TextAlignment.DetectFromContent : - EnumHelpers.Parse(textAlign); - - if (_textAlignment != textAlignment) - { - _textAlignment = textAlignment; - MarkUpdated(); - } - } - - /// - /// Set fontScaling - /// - /// Max number of lines. - [ReactProp(ViewProps.AllowFontScaling)] - public virtual void SetAllowFontScaling(bool allowFontScaling) - { - if (_allowFontScaling != allowFontScaling) - { - _allowFontScaling = allowFontScaling; - MarkUpdated(); - } - } - - /// - /// Called after a layout step at the end of a UI batch from - /// . May be used to enqueue additional UI - /// operations for the native view. Will only be called on nodes marked - /// as updated. - /// - /// - /// Interface for enqueueing UI operations. - /// - public override void OnCollectExtraUpdates(UIViewOperationQueue uiViewOperationQueue) - { - base.OnCollectExtraUpdates(uiViewOperationQueue); - uiViewOperationQueue.EnqueueUpdateExtraData(ReactTag, this); - } - - /// - /// Marks a node as updated. - /// - protected override void MarkUpdated() - { - base.MarkUpdated(); - dirty(); - } - - private static YogaSize MeasureText(ReactSimpleTextShadowNode textNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode) - { - // TODO: Measure text with DirectWrite or other API that does not - // require dispatcher access. Currently, we're instantiating a - // second CoreApplicationView (that is never activated) and using - // its Dispatcher thread to calculate layout. - var textBlock = new TextBlock - { - TextWrapping = TextWrapping.Wrap, - TextAlignment = TextAlignment.DetectFromContent, - TextTrimming = TextTrimming.CharacterEllipsis, - }; - - textNode.UpdateTextBlockCore(textBlock, true); - - var normalizedWidth = YogaConstants.IsUndefined(width) ? double.PositiveInfinity : width; - var normalizedHeight = YogaConstants.IsUndefined(height) ? double.PositiveInfinity : height; - textBlock.Measure(new Size(normalizedWidth, normalizedHeight)); - return MeasureOutput.Make( - (float)Math.Ceiling(textBlock.DesiredSize.Width), - (float)Math.Ceiling(textBlock.DesiredSize.Height)); - } - - /// - /// Updates the properties of a view. - /// - /// The view. - public void UpdateTextBlock(TextBlock textBlock) - { - UpdateTextBlockCore(textBlock, false); - } - - private void UpdateTextBlockCore(TextBlock textBlock, bool measureOnly) - { - textBlock.CharacterSpacing = _letterSpacing; - textBlock.LineHeight = _lineHeight; - textBlock.MaxLines = _numberOfLines; - textBlock.TextAlignment = _textAlignment; - textBlock.FontFamily = _fontFamily != null ? new FontFamily(_fontFamily) : FontFamily.XamlAutoFontFamily; - textBlock.FontSize = _fontSize ?? 15; - textBlock.FontStyle = _fontStyle ?? FontStyle.Normal; - textBlock.FontWeight = _fontWeight ?? FontWeights.Normal; - textBlock.IsTextScaleFactorEnabled = _allowFontScaling; - textBlock.Text = _text; - - if (!measureOnly) - { - textBlock.Padding = new Thickness( - GetPadding(YogaEdge.Left), - GetPadding(YogaEdge.Top), - 0, - 0); - } - } - } -} diff --git a/ReactWindows/ReactNative/Views/Text/ReactSimpleTextViewManager.cs b/ReactWindows/ReactNative/Views/Text/ReactSimpleTextViewManager.cs deleted file mode 100644 index ce58be0284b..00000000000 --- a/ReactWindows/ReactNative/Views/Text/ReactSimpleTextViewManager.cs +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using ReactNative.UIManager; -using ReactNative.UIManager.Annotations; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Media; - -namespace ReactNative.Views.Text -{ - /// - /// The view manager for text views. - /// - public class ReactSimpleTextViewManager : BaseViewManager - { - /// - /// The name of the view manager. - /// - public override string Name - { - get - { - return "RCTSimpleText"; - } - } - - /// - /// Creates the shadow node instance. - /// - /// The shadow node instance. - public override ReactSimpleTextShadowNode CreateShadowNodeInstance() - { - return new ReactSimpleTextShadowNode(); - } - - /// - /// Sets the font color for the node. - /// - /// The view. - /// The masked color value. - [ReactProp(ViewProps.Color, CustomType = "Color")] - public void SetColor(TextBlock view, uint? color) - { - view.Foreground = color.HasValue - ? new SolidColorBrush(ColorHelpers.Parse(color.Value)) - : null; - } - - /// - /// Sets whether or not the text is selectable. - /// - /// The view. - /// A flag indicating whether or not the text is selectable. - [ReactProp("selectable")] - public void SetSelectable(TextBlock view, bool selectable) - { - view.IsTextSelectionEnabled = selectable; - } - - - /// - /// Receive extra updates from the shadow node. - /// - /// The root view. - /// The extra data. - public override void UpdateExtraData(TextBlock root, object extraData) - { - var textNode = extraData as ReactSimpleTextShadowNode; - if (textNode != null) - { - textNode.UpdateTextBlock(root); - } - } - - /// - /// Creates the view instance. - /// - /// The React context. - /// The view instance. - protected override TextBlock CreateViewInstance(ThemedReactContext reactContext) - { - var textBlock = new TextBlock - { - IsTextSelectionEnabled = false, - TextAlignment = TextAlignment.DetectFromContent, - TextTrimming = TextTrimming.CharacterEllipsis, - TextWrapping = TextWrapping.Wrap, - }; - - return textBlock; - } - } -}