Use PhysicalModel for the default canvas Material.

This is done to keep in place the workaround we have for rectangular material
where PhysicalModel skips the saveLayer call.
This commit is contained in:
Amir Hardon 2018-02-02 14:36:53 -08:00 committed by amirh
parent b40c112e22
commit cc060ff2f2
3 changed files with 28 additions and 4 deletions

View File

@ -301,6 +301,29 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
) )
); );
// PhysicalModel has a temporary workaround for a perfomance issue that
// speeds up rectangular non transparent material (the workaround is to
// skip the call to ui.Canvas.saveLayer if the border radius is 0).
// Until the saveLayer perfomance issue is resolved, we're keeping this
// special case here for canvas material type that is using the default
// shape (rectangle). We could go down this fast path for explicitly
// specified rectangles (e.g shape RoundeRectangleBorder with radius 0, but
// we choose not to as we want the change from the fast-path to the
// slow-path to be noticeable in the construction site of Material.
if (widget.type == MaterialType.canvas && widget.shape == null && widget.borderRadius == null) {
return new AnimatedPhysicalModel(
curve: Curves.fastOutSlowIn,
duration: kThemeChangeDuration,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.zero,
elevation: widget.elevation,
color: backgroundColor,
shadowColor: widget.shadowColor,
animateColor: false,
child: contents,
);
}
final ShapeBorder shape = _getShape(); final ShapeBorder shape = _getShape();
if (widget.type == MaterialType.transparency) if (widget.type == MaterialType.transparency)
@ -347,7 +370,7 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
case MaterialType.card: case MaterialType.card:
case MaterialType.button: case MaterialType.button:
return new RoundedRectangleBorder( return new RoundedRectangleBorder(
borderRadius: kMaterialEdges[widget.type], borderRadius: widget.borderRadius ?? kMaterialEdges[widget.type],
); );
case MaterialType.circle: case MaterialType.circle:

View File

@ -140,17 +140,17 @@ void main() {
), ),
), ),
); );
expect(tester.renderObject<RenderProxyBox>(find.byType(PhysicalShape)).child, paintsNothing); expect(tester.renderObject<RenderProxyBox>(find.byType(PhysicalModel)).child, paintsNothing);
await tester.tap(find.byType(InkWell)); await tester.tap(find.byType(InkWell));
await tester.pump(); await tester.pump();
await tester.pump(const Duration(milliseconds: 10)); await tester.pump(const Duration(milliseconds: 10));
expect(tester.renderObject<RenderProxyBox>(find.byType(PhysicalShape)).child, paints..circle()); expect(tester.renderObject<RenderProxyBox>(find.byType(PhysicalModel)).child, paints..circle());
await tester.drag(find.byType(ListView), const Offset(0.0, -1000.0)); await tester.drag(find.byType(ListView), const Offset(0.0, -1000.0));
await tester.pump(const Duration(milliseconds: 10)); await tester.pump(const Duration(milliseconds: 10));
await tester.drag(find.byType(ListView), const Offset(0.0, 1000.0)); await tester.drag(find.byType(ListView), const Offset(0.0, 1000.0));
await tester.pump(const Duration(milliseconds: 10)); await tester.pump(const Duration(milliseconds: 10));
expect( expect(
tester.renderObject<RenderProxyBox>(find.byType(PhysicalShape)).child, tester.renderObject<RenderProxyBox>(find.byType(PhysicalModel)).child,
keepAlive ? (paints..circle()) : paintsNothing, keepAlive ? (paints..circle()) : paintsNothing,
); );
} }

View File

@ -24,6 +24,7 @@ Widget buildMaterial(
child: new Material( child: new Material(
shadowColor: shadowColor, shadowColor: shadowColor,
elevation: elevation, elevation: elevation,
shape: const CircleBorder(),
), ),
), ),
); );