forked from firka/flutter
RenderEditable WidgetSpan intrinsics (#136979)
Update the `RenderEditable` implementation to match `RenderParagraph`. Fixes https://github.com/flutter/flutter/issues/136596
This commit is contained in:
@@ -1817,12 +1817,28 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
|
||||
|
||||
@override
|
||||
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();
|
||||
return _textPainter.minIntrinsicWidth;
|
||||
}
|
||||
|
||||
@override
|
||||
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();
|
||||
return _textPainter.maxIntrinsicWidth + _caretMargin;
|
||||
}
|
||||
@@ -1890,12 +1906,14 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicHeight(double width) {
|
||||
return _preferredHeight(width);
|
||||
}
|
||||
double computeMinIntrinsicHeight(double width) => computeMaxIntrinsicHeight(width);
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicHeight(double width) {
|
||||
if (!_canComputeIntrinsics) {
|
||||
return 0.0;
|
||||
}
|
||||
_textPainter.setPlaceholderDimensions(layoutInlineChildren(width, ChildLayoutHelper.dryLayoutChild));
|
||||
return _preferredHeight(width);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:math' as math;
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -1632,7 +1633,20 @@ void main() {
|
||||
children: renderBoxes,
|
||||
);
|
||||
_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));
|
||||
// Intrinsics can be computed after 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",
|
||||
|
||||
Reference in New Issue
Block a user