Commit 4e650a89 authored by Hans Muller's avatar Hans Muller

Fix ProgressIndicators and add a regression test

Added some unit test infrasture for checking layers.
parent bb38d1d9
...@@ -31,6 +31,7 @@ abstract class ProgressIndicator extends StatefulComponent { ...@@ -31,6 +31,7 @@ abstract class ProgressIndicator extends StatefulComponent {
double get _animationValue => (_animation.variable as AnimatedValue<double>).value; double get _animationValue => (_animation.variable as AnimatedValue<double>).value;
Color get _backgroundColor => Theme.of(this).primarySwatch[200]; Color get _backgroundColor => Theme.of(this).primarySwatch[200];
Color get _valueColor => Theme.of(this).primaryColor; Color get _valueColor => Theme.of(this).primaryColor;
Object get _customPaintToken => value != null ? value : _animationValue;
void initState() { void initState() {
_animation = new AnimationPerformance() _animation = new AnimationPerformance()
...@@ -92,7 +93,7 @@ class LinearProgressIndicator extends ProgressIndicator { ...@@ -92,7 +93,7 @@ class LinearProgressIndicator extends ProgressIndicator {
Widget _buildIndicator() { Widget _buildIndicator() {
return new Container( return new Container(
child: new CustomPaint(callback: _paint), child: new CustomPaint(callback: _paint, token: _customPaintToken),
constraints: new BoxConstraints.tightFor( constraints: new BoxConstraints.tightFor(
width: double.INFINITY, width: double.INFINITY,
height: _kLinearProgressIndicatorHeight height: _kLinearProgressIndicatorHeight
...@@ -138,7 +139,7 @@ class CircularProgressIndicator extends ProgressIndicator { ...@@ -138,7 +139,7 @@ class CircularProgressIndicator extends ProgressIndicator {
Widget _buildIndicator() { Widget _buildIndicator() {
return new Container( return new Container(
child: new CustomPaint(callback: _paint), child: new CustomPaint(callback: _paint, token: _customPaintToken),
constraints: new BoxConstraints( constraints: new BoxConstraints(
minWidth: _kMinCircularProgressIndicatorSize, minWidth: _kMinCircularProgressIndicatorSize,
minHeight: _kMinCircularProgressIndicatorSize minHeight: _kMinCircularProgressIndicatorSize
......
...@@ -9,6 +9,7 @@ class TestRenderView extends RenderView { ...@@ -9,6 +9,7 @@ class TestRenderView extends RenderView {
attach(); attach();
rootConstraints = new ViewConstraints(size: _kTestViewSize); rootConstraints = new ViewConstraints(size: _kTestViewSize);
scheduleInitialLayout(); scheduleInitialLayout();
scheduleInitialPaint(new TransformLayer(transform: new Matrix4.identity()));
} }
} }
...@@ -63,6 +64,20 @@ class WidgetTester { ...@@ -63,6 +64,20 @@ class WidgetTester {
TestApp _app; TestApp _app;
RenderView _renderView; RenderView _renderView;
List<Layer> _layers(Layer layer) {
List<Layer> result = [layer];
if (layer is ContainerLayer) {
ContainerLayer root = layer;
Layer child = root.firstChild;
while(child != null) {
result.addAll(_layers(child));
child = child.nextSibling;
}
}
return result;
}
List<Layer> get layers => _layers(_renderView.layer);
void walkWidgets(WidgetTreeWalker walker) { void walkWidgets(WidgetTreeWalker walker) {
void walk(Widget widget) { void walk(Widget widget) {
walker(widget); walker(widget);
...@@ -113,4 +128,14 @@ class WidgetTester { ...@@ -113,4 +128,14 @@ class WidgetTester {
Component.flushBuild(); Component.flushBuild();
RenderObject.flushLayout(); RenderObject.flushLayout();
} }
// TODO(hansmuller): just having one pumpFrame() fn would be preferable.
void pumpPaintFrame(WidgetBuilder builder) {
_app.builder = builder;
Component.flushBuild();
RenderObject.flushLayout();
_renderView.updateCompositingBits();
RenderObject.flushPaint();
}
} }
import 'package:sky/rendering.dart';
import 'package:sky/widgets.dart';
import 'package:test/test.dart';
import 'build_utils.dart';
void main() {
test('LinearProgressIndicator changes when its value changes', () {
WidgetTester tester = new WidgetTester();
tester.pumpPaintFrame(() {
return new Block([new LinearProgressIndicator(value: 0.0)]);
});
List<Layer> layers1 = tester.layers;
tester.pumpPaintFrame(() {
return new Block([new LinearProgressIndicator(value: 0.5)]);
});
List<Layer> layers2 = tester.layers;
expect(layers1, isNot(equals(layers2)));
});
}
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