Unverified Commit 9f28aefa authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Call BorderRadiusGeometry.lerp where applicable in ShapeBorder subclasses (#24262)

Fixes https://github.com/flutter/flutter/issues/24257
parent ff25edd3
......@@ -60,7 +60,7 @@ class BeveledRectangleBorder extends ShapeBorder {
if (a is BeveledRectangleBorder) {
return BeveledRectangleBorder(
side: BorderSide.lerp(a.side, side, t),
borderRadius: BorderRadius.lerp(a.borderRadius, borderRadius, t),
borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, borderRadius, t),
);
}
return super.lerpFrom(a, t);
......@@ -72,7 +72,7 @@ class BeveledRectangleBorder extends ShapeBorder {
if (b is BeveledRectangleBorder) {
return BeveledRectangleBorder(
side: BorderSide.lerp(side, b.side, t),
borderRadius: BorderRadius.lerp(borderRadius, b.borderRadius, t),
borderRadius: BorderRadiusGeometry.lerp(borderRadius, b.borderRadius, t),
);
}
return super.lerpTo(b, t);
......
......@@ -59,7 +59,7 @@ class RoundedRectangleBorder extends ShapeBorder {
if (a is RoundedRectangleBorder) {
return RoundedRectangleBorder(
side: BorderSide.lerp(a.side, side, t),
borderRadius: BorderRadius.lerp(a.borderRadius, borderRadius, t),
borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, borderRadius, t),
);
}
if (a is CircleBorder) {
......@@ -78,7 +78,7 @@ class RoundedRectangleBorder extends ShapeBorder {
if (b is RoundedRectangleBorder) {
return RoundedRectangleBorder(
side: BorderSide.lerp(side, b.side, t),
borderRadius: BorderRadius.lerp(borderRadius, b.borderRadius, t),
borderRadius: BorderRadiusGeometry.lerp(borderRadius, b.borderRadius, t),
);
}
if (b is CircleBorder) {
......@@ -151,7 +151,7 @@ class _RoundedRectangleToCircleBorder extends ShapeBorder {
final BorderSide side;
final BorderRadius borderRadius;
final BorderRadiusGeometry borderRadius;
final double circleness;
......@@ -175,7 +175,7 @@ class _RoundedRectangleToCircleBorder extends ShapeBorder {
if (a is RoundedRectangleBorder) {
return _RoundedRectangleToCircleBorder(
side: BorderSide.lerp(a.side, side, t),
borderRadius: BorderRadius.lerp(a.borderRadius, borderRadius, t),
borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, borderRadius, t),
circleness: circleness * t,
);
}
......@@ -189,7 +189,7 @@ class _RoundedRectangleToCircleBorder extends ShapeBorder {
if (a is _RoundedRectangleToCircleBorder) {
return _RoundedRectangleToCircleBorder(
side: BorderSide.lerp(a.side, side, t),
borderRadius: BorderRadius.lerp(a.borderRadius, borderRadius, t),
borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, borderRadius, t),
circleness: ui.lerpDouble(a.circleness, circleness, t),
);
}
......@@ -201,7 +201,7 @@ class _RoundedRectangleToCircleBorder extends ShapeBorder {
if (b is RoundedRectangleBorder) {
return _RoundedRectangleToCircleBorder(
side: BorderSide.lerp(side, b.side, t),
borderRadius: BorderRadius.lerp(borderRadius, b.borderRadius, t),
borderRadius: BorderRadiusGeometry.lerp(borderRadius, b.borderRadius, t),
circleness: circleness * (1.0 - t),
);
}
......@@ -215,7 +215,7 @@ class _RoundedRectangleToCircleBorder extends ShapeBorder {
if (b is _RoundedRectangleToCircleBorder) {
return _RoundedRectangleToCircleBorder(
side: BorderSide.lerp(side, b.side, t),
borderRadius: BorderRadius.lerp(borderRadius, b.borderRadius, t),
borderRadius: BorderRadiusGeometry.lerp(borderRadius, b.borderRadius, t),
circleness: ui.lerpDouble(circleness, b.circleness, t),
);
}
......@@ -244,22 +244,23 @@ class _RoundedRectangleToCircleBorder extends ShapeBorder {
}
}
BorderRadius _adjustBorderRadius(Rect rect) {
BorderRadius _adjustBorderRadius(Rect rect, TextDirection textDirection) {
final BorderRadius resolvedRadius = borderRadius.resolve(textDirection);
if (circleness == 0.0)
return borderRadius;
return BorderRadius.lerp(borderRadius, BorderRadius.circular(rect.shortestSide / 2.0), circleness);
return resolvedRadius;
return BorderRadius.lerp(resolvedRadius, BorderRadius.circular(rect.shortestSide / 2.0), circleness);
}
@override
Path getInnerPath(Rect rect, { TextDirection textDirection }) {
return Path()
..addRRect(_adjustBorderRadius(rect).toRRect(_adjustRect(rect)).deflate(side.width));
..addRRect(_adjustBorderRadius(rect, textDirection).toRRect(_adjustRect(rect)).deflate(side.width));
}
@override
Path getOuterPath(Rect rect, { TextDirection textDirection }) {
return Path()
..addRRect(_adjustBorderRadius(rect).toRRect(_adjustRect(rect)));
..addRRect(_adjustBorderRadius(rect, textDirection).toRRect(_adjustRect(rect)));
}
@override
......@@ -270,9 +271,9 @@ class _RoundedRectangleToCircleBorder extends ShapeBorder {
case BorderStyle.solid:
final double width = side.width;
if (width == 0.0) {
canvas.drawRRect(_adjustBorderRadius(rect).toRRect(_adjustRect(rect)), side.toPaint());
canvas.drawRRect(_adjustBorderRadius(rect, textDirection).toRRect(_adjustRect(rect)), side.toPaint());
} else {
final RRect outer = _adjustBorderRadius(rect).toRRect(_adjustRect(rect));
final RRect outer = _adjustBorderRadius(rect, textDirection).toRRect(_adjustRect(rect));
final RRect inner = outer.deflate(width);
final Paint paint = Paint()
..color = side.color;
......
......@@ -34,6 +34,12 @@ void main() {
strokeWidth: 0.0,
)
);
const RoundedRectangleBorder directional = RoundedRectangleBorder(
borderRadius: BorderRadiusDirectional.only(topStart: Radius.circular(20)),
);
expect(ShapeBorder.lerp(directional, c10, 1.0),
ShapeBorder.lerp(c10, directional, 0.0));
});
test('RoundedRectangleBorder and CircleBorder', () {
......
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