Updates to debugDisableShadows (#17577)

1. Make CupertinoSwitch use BoxShadow.toPaint() so that it respects
   the `debugDisableShadows` flag.
2. Increase blue radius on debug banner
3. Only stroke "synthetic shadow" borders if elevation is positive.
This commit is contained in:
Todd Volkert 2018-05-15 08:55:42 -07:00 committed by GitHub
parent 8be2682ee4
commit c4cb0ecff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 30 deletions

View File

@ -1 +1 @@
df3f713cc47fc4e919d1c5cf52c0543424c26c09
298b585e6eb2bf51b12cd0ea9261a1b7a83c9a29

View File

@ -6,8 +6,6 @@ import 'package:flutter/painting.dart';
import 'colors.dart';
final MaskFilter _kShadowMaskFilter = new MaskFilter.blur(BlurStyle.normal, BoxShadow.convertRadiusToSigma(1.0));
/// Paints an iOS-style slider thumb.
///
/// Used by [CupertinoSwitch] and [CupertinoSlider].
@ -16,7 +14,10 @@ class CupertinoThumbPainter {
CupertinoThumbPainter({
this.color: CupertinoColors.white,
this.shadowColor: const Color(0x2C000000),
});
}) : _shadowPaint = new BoxShadow(
color: shadowColor,
blurRadius: 1.0,
).toPaint();
/// The color of the interior of the thumb.
final Color color;
@ -24,6 +25,9 @@ class CupertinoThumbPainter {
/// The color of the shadow case by the thumb.
final Color shadowColor;
/// The paint used to draw the shadow case by the thumb.
final Paint _shadowPaint;
/// Half the default diameter of the thumb.
static const double radius = 14.0;
@ -35,17 +39,13 @@ class CupertinoThumbPainter {
/// Consider using [radius] and [extension] when deciding how large a
/// rectangle to use for the thumb.
void paint(Canvas canvas, Rect rect) {
final RRect rrect = new RRect.fromRectAndRadius(rect, new Radius.circular(rect.shortestSide / 2.0));
final RRect rrect = new RRect.fromRectAndRadius(
rect,
new Radius.circular(rect.shortestSide / 2.0),
);
final Paint paint = new Paint()
..color = shadowColor
..maskFilter = _kShadowMaskFilter;
canvas.drawRRect(rrect, paint);
canvas.drawRRect(rrect.shift(const Offset(0.0, 3.0)), paint);
paint
..color = color
..maskFilter = null;
canvas.drawRRect(rrect, paint);
canvas.drawRRect(rrect, _shadowPaint);
canvas.drawRRect(rrect.shift(const Offset(0.0, 3.0)), _shadowPaint);
canvas.drawRRect(rrect, new Paint()..color = color);
}
}

View File

@ -1600,13 +1600,15 @@ class RenderPhysicalModel extends _RenderPhysicalModelBase<RRect> {
bool paintShadows = true;
assert(() {
if (debugDisableShadows) {
context.canvas.drawRRect(
offsetRRect,
new Paint()
..color = shadowColor
..style = PaintingStyle.stroke
..strokeWidth = elevation * 2.0,
);
if (elevation > 0.0) {
context.canvas.drawRRect(
offsetRRect,
new Paint()
..color = shadowColor
..style = PaintingStyle.stroke
..strokeWidth = elevation * 2.0,
);
}
paintShadows = false;
}
return true;
@ -1721,13 +1723,15 @@ class RenderPhysicalShape extends _RenderPhysicalModelBase<Path> {
bool paintShadows = true;
assert(() {
if (debugDisableShadows) {
context.canvas.drawPath(
offsetPath,
new Paint()
..color = shadowColor
..style = PaintingStyle.stroke
..strokeWidth = elevation * 2.0,
);
if (elevation > 0.0) {
context.canvas.drawPath(
offsetPath,
new Paint()
..color = shadowColor
..style = PaintingStyle.stroke
..strokeWidth = elevation * 2.0,
);
}
paintShadows = false;
}
return true;

View File

@ -110,7 +110,7 @@ class BannerPainter extends CustomPainter {
static const BoxShadow _shadow = const BoxShadow(
color: const Color(0x7F000000),
blurRadius: 4.0,
blurRadius: 6.0,
);
bool _prepared = false;