Commit cc060ff2 authored by Amir Hardon's avatar Amir Hardon Committed by amirh

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.
parent b40c112e
......@@ -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();
if (widget.type == MaterialType.transparency)
......@@ -347,7 +370,7 @@ class _MaterialState extends State<Material> with TickerProviderStateMixin {
case MaterialType.card:
case MaterialType.button:
return new RoundedRectangleBorder(
borderRadius: kMaterialEdges[widget.type],
borderRadius: widget.borderRadius ?? kMaterialEdges[widget.type],
);
case MaterialType.circle:
......
......@@ -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.pump();
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.pump(const Duration(milliseconds: 10));
await tester.drag(find.byType(ListView), const Offset(0.0, 1000.0));
await tester.pump(const Duration(milliseconds: 10));
expect(
tester.renderObject<RenderProxyBox>(find.byType(PhysicalShape)).child,
tester.renderObject<RenderProxyBox>(find.byType(PhysicalModel)).child,
keepAlive ? (paints..circle()) : paintsNothing,
);
}
......
......@@ -24,6 +24,7 @@ Widget buildMaterial(
child: new Material(
shadowColor: shadowColor,
elevation: elevation,
shape: const 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