Make the InkResponse's focus highlight honor the radius parameter (#59117)

This commit is contained in:
Darren Austin 2020-06-10 12:25:04 -07:00 committed by GitHub
parent cd547c70b2
commit cb8562e163
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View File

@ -41,6 +41,7 @@ class InkHighlight extends InteractiveInkFeature {
@required Color color,
@required TextDirection textDirection,
BoxShape shape = BoxShape.rectangle,
double radius,
BorderRadius borderRadius,
ShapeBorder customBorder,
RectCallback rectCallback,
@ -51,6 +52,7 @@ class InkHighlight extends InteractiveInkFeature {
assert(textDirection != null),
assert(fadeDuration != null),
_shape = shape,
_radius = radius,
_borderRadius = borderRadius ?? BorderRadius.zero,
_customBorder = customBorder,
_textDirection = textDirection,
@ -69,6 +71,7 @@ class InkHighlight extends InteractiveInkFeature {
}
final BoxShape _shape;
final double _radius;
final BorderRadius _borderRadius;
final ShapeBorder _customBorder;
final RectCallback _rectCallback;
@ -112,7 +115,7 @@ class InkHighlight extends InteractiveInkFeature {
}
switch (_shape) {
case BoxShape.circle:
canvas.drawCircle(rect.center, Material.defaultSplashRadius, paint);
canvas.drawCircle(rect.center, _radius ?? Material.defaultSplashRadius, paint);
break;
case BoxShape.rectangle:
if (_borderRadius != BorderRadius.zero) {

View File

@ -840,6 +840,7 @@ class _InkResponseState extends State<_InkResponseStateWidget>
referenceBox: referenceBox,
color: getHighlightColorForType(type),
shape: widget.highlightShape,
radius: widget.radius,
borderRadius: widget.borderRadius,
customBorder: widget.customBorder,
rectCallback: widget.getRectCallback(referenceBox),

View File

@ -313,6 +313,36 @@ void main() {
await gesture.up();
});
testWidgets('ink response uses radius for focus highlight', (WidgetTester tester) async {
FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
await tester.pumpWidget(
Material(
child: Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: Container(
width: 100,
height: 100,
child: InkResponse(
focusNode: focusNode,
radius: 20,
focusColor: const Color(0xff0000ff),
onTap: () { },
),
),
),
),
),
);
await tester.pumpAndSettle();
final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
expect(inkFeatures, paintsExactlyCountTimes(#drawCircle, 0));
focusNode.requestFocus();
await tester.pumpAndSettle();
expect(inkFeatures, paints..circle(radius: 20, color: const Color(0xff0000ff)));
});
testWidgets("ink response doesn't change color on focus when on touch device", (WidgetTester tester) async {
FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTouch;
final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');