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