Unverified Commit 5f477642 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

RenderEditable WidgetSpan intrinsics (#136979)

Update the `RenderEditable` implementation to match `RenderParagraph`. Fixes https://github.com/flutter/flutter/issues/136596
parent 78b754e5
...@@ -1817,12 +1817,28 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin, ...@@ -1817,12 +1817,28 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
@override @override
double computeMinIntrinsicWidth(double height) { double computeMinIntrinsicWidth(double height) {
if (!_canComputeIntrinsics) {
return 0.0;
}
_textPainter.setPlaceholderDimensions(layoutInlineChildren(
double.infinity,
(RenderBox child, BoxConstraints constraints) => Size(child.getMinIntrinsicWidth(double.infinity), 0.0),
));
_layoutText(); _layoutText();
return _textPainter.minIntrinsicWidth; return _textPainter.minIntrinsicWidth;
} }
@override @override
double computeMaxIntrinsicWidth(double height) { double computeMaxIntrinsicWidth(double height) {
if (!_canComputeIntrinsics) {
return 0.0;
}
_textPainter.setPlaceholderDimensions(layoutInlineChildren(
double.infinity,
// Height and baseline is irrelevant as all text will be laid
// out in a single line. Therefore, using 0.0 as a dummy for the height.
(RenderBox child, BoxConstraints constraints) => Size(child.getMaxIntrinsicWidth(double.infinity), 0.0),
));
_layoutText(); _layoutText();
return _textPainter.maxIntrinsicWidth + _caretMargin; return _textPainter.maxIntrinsicWidth + _caretMargin;
} }
...@@ -1890,12 +1906,14 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin, ...@@ -1890,12 +1906,14 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
} }
@override @override
double computeMinIntrinsicHeight(double width) { double computeMinIntrinsicHeight(double width) => computeMaxIntrinsicHeight(width);
return _preferredHeight(width);
}
@override @override
double computeMaxIntrinsicHeight(double width) { double computeMaxIntrinsicHeight(double width) {
if (!_canComputeIntrinsics) {
return 0.0;
}
_textPainter.setPlaceholderDimensions(layoutInlineChildren(width, ChildLayoutHelper.dryLayoutChild));
return _preferredHeight(width); return _preferredHeight(width);
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:math' as math;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
...@@ -1632,7 +1633,20 @@ void main() { ...@@ -1632,7 +1633,20 @@ void main() {
children: renderBoxes, children: renderBoxes,
); );
_applyParentData(renderBoxes, editable.text!); _applyParentData(renderBoxes, editable.text!);
// Intrinsics can be computed without doing layout.
expect(editable.computeMaxIntrinsicWidth(fixedHeight),
2.0 * 10.0 * 4 + 14.0 * 7 + 1.0,
reason: "intrinsic width = scale factor * width of 'test' + width of 'one two' + _caretMargin",
);
expect(editable.computeMinIntrinsicWidth(fixedHeight),
math.max(math.max(2.0 * 10.0 * 4, 14.0 * 3), 14.0 * 3),
reason: "intrinsic width = max(scale factor * width of 'test', width of 'one', width of 'two')",
);
expect(editable.computeMaxIntrinsicHeight(fixedHeight), 40.0);
expect(editable.computeMinIntrinsicHeight(fixedHeight), 40.0);
layout(editable, constraints: const BoxConstraints(maxWidth: screenWidth)); layout(editable, constraints: const BoxConstraints(maxWidth: screenWidth));
// Intrinsics can be computed after layout.
expect(editable.computeMaxIntrinsicWidth(fixedHeight), expect(editable.computeMaxIntrinsicWidth(fixedHeight),
2.0 * 10.0 * 4 + 14.0 * 7 + 1.0, 2.0 * 10.0 * 4 + 14.0 * 7 + 1.0,
reason: "intrinsic width = scale factor * width of 'test' + width of 'one two' + _caretMargin", reason: "intrinsic width = scale factor * width of 'test' + width of 'one two' + _caretMargin",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment