Example #1
0
        private static MeasureOutput MeasureTextInput(CSSNode node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode)
        {
            var textInputNode = (ReactPasswordBoxShadowNode)node;

            textInputNode._computedPadding = textInputNode.GetComputedPadding();

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

            var normalizedWidth = Math.Max(0,
                                           (CSSConstants.IsUndefined(width) ? double.PositiveInfinity : width)
                                           - textInputNode._computedPadding[0]
                                           - textInputNode._computedPadding[2]
                                           - (CSSConstants.IsUndefined(borderLeftWidth) ? 0 : borderLeftWidth)
                                           - (CSSConstants.IsUndefined(borderRightWidth) ? 0 : borderRightWidth));
            var normalizedHeight = Math.Max(0, CSSConstants.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 textNode = (ReactPasswordBoxShadowNode)node;

                var passwordBox = new PasswordBox();

                var normalizedText = string.IsNullOrEmpty(textNode._text) ? " " : textNode._text;
                FormatPasswordBox(textNode, passwordBox, true);

                passwordBox.Password = normalizedText;

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

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

                var finalizedHeight = (float)passwordBox.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));
            });

            return(task.Result);
        }