private void UpdatePadding()
 {
     for (var spacingType = EdgeSpacing.Left; spacingType <= EdgeSpacing.All; spacingType++)
     {
         if (spacingType == EdgeSpacing.Left ||
             spacingType == EdgeSpacing.Right ||
             spacingType == EdgeSpacing.Start ||
             spacingType == EdgeSpacing.End)
         {
             if (YogaConstants.IsUndefined(_padding.GetRaw(spacingType)) &&
                 YogaConstants.IsUndefined(_padding.GetRaw(EdgeSpacing.Horizontal)) &&
                 YogaConstants.IsUndefined(_padding.GetRaw(EdgeSpacing.All)))
             {
                 SetPadding(_yogaNode, spacingType, _defaultPadding.GetRaw(spacingType));
             }
             else
             {
                 SetPadding(_yogaNode, spacingType, _padding.GetRaw(spacingType));
             }
         }
         else if (spacingType == EdgeSpacing.Top || spacingType == EdgeSpacing.Bottom)
         {
             if (YogaConstants.IsUndefined(_padding.GetRaw(spacingType)) &&
                 YogaConstants.IsUndefined(_padding.GetRaw(EdgeSpacing.Vertical)) &&
                 YogaConstants.IsUndefined(_padding.GetRaw(EdgeSpacing.All)))
             {
                 SetPadding(_yogaNode, spacingType, _defaultPadding.GetRaw(spacingType));
             }
             else
             {
                 SetPadding(_yogaNode, spacingType, _padding.GetRaw(spacingType));
             }
         }
         else
         {
             if (YogaConstants.IsUndefined(_padding.GetRaw(spacingType)))
             {
                 SetPadding(_yogaNode, spacingType, _defaultPadding.GetRaw(spacingType));
             }
             else
             {
                 SetPadding(_yogaNode, spacingType, _padding.GetRaw(spacingType));
             }
         }
     }
 }
Esempio n. 2
0
        public static float GetTopBorderWidth(this ReactShadowNode node)
        {
            var width = node.GetBorder(EdgeSpacing.Top);

            if (!YogaConstants.IsUndefined(width))
            {
                return(width);
            }

            width = node.GetBorder(EdgeSpacing.All);
            if (!YogaConstants.IsUndefined(width))
            {
                return(width);
            }

            return(0.0f);
        }
        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)));
        }
Esempio n. 4
0
        private static YogaSize MeasureText(ReactTextShadowNode textNode, YogaNode node, float width,
                                            YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode)
        {
            Log.Info(ReactConstants.Tag, "MeasureText node=" + textNode.ReactTag);
            // 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(() =>
            {
                if (textView == null)
                {
                    textView = new ReactTextView(ReactProgram.RctWindow);
                    textView.LineWrapType = WrapType.Mixed;
                }

                var normalizedWidth  = YogaConstants.IsUndefined(width) ? ReactProgram.RctWindow.ScreenSize.Width : width;
                var normalizedHeight = YogaConstants.IsUndefined(height) ? ReactProgram.RctWindow.ScreenSize.Height : height;
                textView.Resize((int)normalizedWidth, (int)normalizedHeight);

                textView.Text      = textNode._preparedSpannableText;
                var textPartObject = textView.EdjeObject["elm.text"];
                if (textPartObject == null)
                {
                    throw new Exception("Invalid ReactTextView.EdjeObject[\"elm.text\"]");
                }
                Size size = textPartObject.TextBlockFormattedSize;
                Log.Info(ReactConstants.Tag, "MeasureText result : width: " + size.Width + " height:" + size.Height);

                //textView.Unrealize();

                return(MeasureOutput.Make(
                           (float)size.Width,
                           (float)size.Height));
            });

            return(task.Result);
        }
Esempio n. 5
0
        private static YogaSize MeasureText(ReactTextShadowNode textNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode)
        {
            // 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 RichTextBlock
                {
                    TextWrapping  = TextWrapping.Wrap,
                    TextAlignment = TextAlignment.DetectFromContent,
                    TextTrimming  = TextTrimming.CharacterEllipsis,
                };

                textNode.UpdateTextBlockCore(textBlock, true);

                var block = new Paragraph();
                for (var i = 0; i < textNode.ChildCount; ++i)
                {
                    var child = textNode.GetChildAt(i);
                    block.Inlines.Add(ReactInlineShadowNodeVisitor.Apply(child));
                }
                textBlock.Blocks.Add(block);

                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)));
            });

            return(task.Result);
        }
        private YogaSize MeasureButton(ReactButtonShadowNode textNode, YogaNode node, float width,
                                       YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode)
        {
            Log.Info(ReactConstants.Tag, "[1] MeasureButton node=" + textNode.ReactTag + " with=" + width + " height=" + height + " content=" + _preparedSpannableText);
            // 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 btnView = new Button(ReactProgram.RctWindow);

                var normalizedWidth  = YogaConstants.IsUndefined(width) ? double.PositiveInfinity : width;
                var normalizedHeight = YogaConstants.IsUndefined(height) ? double.PositiveInfinity : height;

                btnView.Resize((int)normalizedWidth, (int)normalizedHeight);
                btnView.Text = _preparedSpannableText;

                var btnPartObject = btnView.EdjeObject["elm.text"];
                if (btnPartObject == null)
                {
                    throw new Exception("Invalid Button.EdjeObject[\"elm.text\"]");
                }
                Size size = btnPartObject.TextBlockFormattedSize;
                Log.Info(ReactConstants.Tag, "[2] EDC conf info ={ width: " + size.Width + " height:" + size.Height + "}");
                btnView.Unrealize();

                return(MeasureOutput.Make(
                           (float)(size.Width + 80),
                           (float)(size.Height < 80 ? 80 : size.Height)));
            });

            return(task.Result);
        }
        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)));
        }
        private static YogaSize MeasureTextInput(ReactTextInputShadowNode textInputNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode)
        {
            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)));
        }
Esempio n. 9
0
        private static YogaSize MeasureProgressBar(YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode)
        {
            var adjustedHeight = YogaConstants.IsUndefined(height) ? 4f : height;

            return(MeasureOutput.Make(width, adjustedHeight));
        }