コード例 #1
0
        /// <summary>
        /// Formats an inline instance with shadow properties.
        /// </summary>
        /// <param name="textNode">The text shadow node.</param>
        /// <param name="inline">The inline.</param>
        protected static void FormatInline(ReactTextInputShadowNode textNode, TextElement inline)
        {
            if (textNode._fontSize != Unset)
            {
                var fontSize = textNode._fontSize;
                inline.FontSize = fontSize;
            }

            if (textNode._fontStyle.HasValue)
            {
                var fontStyle = textNode._fontStyle.Value;
                inline.FontStyle = fontStyle;
            }

            if (textNode._fontWeight.HasValue)
            {
                var fontWeight = textNode._fontWeight.Value;
                inline.FontWeight = fontWeight;
            }

            if (textNode._fontFamily != null)
            {
                var fontFamily = new FontFamily(textNode._fontFamily);
                inline.FontFamily = fontFamily;
            }
        }
コード例 #2
0
        private static void ApplyStyles(ReactTextInputShadowNode textNode, TextBlock textBlock)
        {
            if (textNode._fontSize != Unset)
            {
                var fontSize = textNode._fontSize;
                textBlock.FontSize = fontSize;
            }

            if (textNode._fontStyle.HasValue)
            {
                var fontStyle = textNode._fontStyle.Value;
                textBlock.FontStyle = fontStyle;
            }

            if (textNode._fontWeight.HasValue)
            {
                var fontWeight = textNode._fontWeight.Value;
                textBlock.FontWeight = fontWeight;
            }

            if (textNode._fontFamily != null)
            {
                var fontFamily = new FontFamily(textNode._fontFamily);
                textBlock.FontFamily = fontFamily;
            }

            if (textNode._maxHeight.HasValue)
            {
                textBlock.MaxHeight = textNode._maxHeight.Value;
            }
        }
        private static YogaSize MeasureTextInput(ReactTextInputShadowNode textInputNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode)
        {
            textInputNode._computedPadding = textInputNode.GetComputedPadding();

            var normalizedWidth = Math.Max(0,
                                           (YogaConstants.IsUndefined(width) ? double.PositiveInfinity : width));

            var normalizedHeight = Math.Max(0,
                                            (YogaConstants.IsUndefined(height) ? double.PositiveInfinity : height));

            var normalizedText = string.IsNullOrEmpty(textInputNode._text) ? " " : textInputNode._text;

            var textBlock = new TextBlock
            {
                Text         = normalizedText,
                TextWrapping = textInputNode._multiline ? TextWrapping.Wrap : TextWrapping.NoWrap,
            };

            ApplyStyles(textInputNode, textBlock);

            textBlock.Measure(new Size(normalizedWidth, normalizedHeight));

            return(MeasureOutput.Make(
                       (float)Math.Ceiling(width),
                       (float)Math.Ceiling(textBlock.ActualHeight)));
        }
コード例 #4
0
        private static YogaSize MeasureTextInput(ReactTextInputShadowNode textInputNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode)
        {
            textInputNode._computedPadding = textInputNode.GetComputedPadding();

            var borderLeftWidth  = textInputNode.GetBorder(YogaEdge.Left);
            var borderRightWidth = textInputNode.GetBorder(YogaEdge.Right);

            var normalizedWidth = Math.Max(0,
                                           (YogaConstants.IsUndefined(width) ? double.PositiveInfinity : width)
                                           - textInputNode._computedPadding[0]
                                           - textInputNode._computedPadding[2]
                                           - (YogaConstants.IsUndefined(borderLeftWidth) ? 0 : borderLeftWidth)
                                           - (YogaConstants.IsUndefined(borderRightWidth) ? 0 : borderRightWidth));
            var normalizedHeight = Math.Max(0, YogaConstants.IsUndefined(height) ? double.PositiveInfinity : height);

            // This is not a terribly efficient way of projecting the height of
            // the text elements. It requires that we have access to the
            // dispatcher in order to do measurement, which, for obvious
            // reasons, can cause perceived performance issues as it will block
            // the UI thread from handling other work.
            //
            // TODO: determine another way to measure text elements.
            var task = DispatcherHelpers.CallOnDispatcher(() =>
            {
                /*
                 * var textBlock = new TextBlock
                 * {
                 *  TextWrapping = TextWrapping.Wrap,
                 * };
                 *
                 * var normalizedText = string.IsNullOrEmpty(textNode._text) ? " " : textNode._text;
                 * var inline = new Run { Text = normalizedText };
                 * FormatInline(textNode, inline);
                 *
                 * textBlock.Inlines.Add(inline);
                 *
                 * textBlock.Measure(new Size(normalizedWidth, normalizedHeight));
                 *
                 * var borderTopWidth = textInputNode.GetBorder(CSSSpacingType.Top);
                 * var borderBottomWidth = textInputNode.GetBorder(CSSSpacingType.Bottom);
                 *
                 * var finalizedHeight = (float)textBlock.DesiredSize.Height;
                 * finalizedHeight += textInputNode._computedPadding[1];
                 * finalizedHeight += textInputNode._computedPadding[3];
                 * finalizedHeight += CSSConstants.IsUndefined(borderTopWidth) ? 0 : borderTopWidth;
                 * finalizedHeight += CSSConstants.IsUndefined(borderBottomWidth) ? 0 : borderBottomWidth;
                 *
                 * return new MeasureOutput(width, finalizedHeight);
                 */

                float finalizedHeight = 1;
                return(MeasureOutput.Make(
                           (float)Math.Ceiling(width),
                           (float)Math.Ceiling(finalizedHeight)));
            });

            return(task.Result);
        }
コード例 #5
0
        private static YogaSize MeasureTextInput(ReactTextInputShadowNode textInputNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode)
        {
            textInputNode._computedPadding = textInputNode.GetComputedPadding();

            var borderLeftWidth  = textInputNode.GetBorder(YogaEdge.Left);
            var borderRightWidth = textInputNode.GetBorder(YogaEdge.Right);

            var normalizedWidth = Math.Max(0,
                                           (YogaConstants.IsUndefined(width) ? double.PositiveInfinity : width)
                                           - textInputNode._computedPadding[0]
                                           - textInputNode._computedPadding[2]
                                           - (YogaConstants.IsUndefined(borderLeftWidth) ? 0 : borderLeftWidth)
                                           - (YogaConstants.IsUndefined(borderRightWidth) ? 0 : borderRightWidth));
            var normalizedHeight = Math.Max(0, YogaConstants.IsUndefined(height) ? double.PositiveInfinity : height);

            var textBlock = new TextBlock
            {
                TextWrapping = TextWrapping.Wrap,
            };

            var normalizedText = string.IsNullOrEmpty(textInputNode._text) ? " " : textInputNode._text;
            var inline         = new Run {
                Text = normalizedText
            };

            FormatInline(textInputNode, inline);

            textBlock.Inlines.Add(inline);

            textBlock.Measure(new Size(normalizedWidth, normalizedHeight));

            var borderTopWidth    = textInputNode.GetBorder(YogaEdge.Top);
            var borderBottomWidth = textInputNode.GetBorder(YogaEdge.Bottom);

            var finalizedHeight = (float)textBlock.DesiredSize.Height;

            finalizedHeight += textInputNode._computedPadding[1];
            finalizedHeight += textInputNode._computedPadding[3];
            finalizedHeight += YogaConstants.IsUndefined(borderTopWidth) ? 0 : borderTopWidth;
            finalizedHeight += YogaConstants.IsUndefined(borderBottomWidth) ? 0 : borderBottomWidth;

            return(MeasureOutput.Make(
                       (float)Math.Ceiling(width),
                       (float)Math.Ceiling(finalizedHeight)));
        }