Commit f17f1ba1 authored by Adam Barth's avatar Adam Barth

Merge pull request #1102 from abarth/animated_container

AnimatedContainer has an issue with one config value change and not another
parents d8edf1c2 79c797a1
...@@ -146,6 +146,14 @@ class _AnimatedContainerState extends State<AnimatedContainer> { ...@@ -146,6 +146,14 @@ class _AnimatedContainerState extends State<AnimatedContainer> {
_updateCurve(); _updateCurve();
_performanceController.duration = config.duration; _performanceController.duration = config.duration;
if (_configAllVariables()) { if (_configAllVariables()) {
_updateBeginValue(_constraints);
_updateBeginValue(_decoration);
_updateBeginValue(_foregroundDecoration);
_updateBeginValue(_margin);
_updateBeginValue(_padding);
_updateBeginValue(_transform);
_updateBeginValue(_width);
_updateBeginValue(_height);
_performanceController.progress = 0.0; _performanceController.progress = 0.0;
_performanceController.play(); _performanceController.play();
} }
...@@ -183,82 +191,84 @@ class _AnimatedContainerState extends State<AnimatedContainer> { ...@@ -183,82 +191,84 @@ class _AnimatedContainerState extends State<AnimatedContainer> {
}); });
} }
bool _configVariable(AnimatedValue variable, dynamic targetValue) { bool _updateEndValue(AnimatedValue variable, dynamic targetValue) {
if (targetValue == variable.end) if (targetValue == variable.end)
return false; return false;
dynamic currentValue = variable.value;
variable.end = targetValue; variable.end = targetValue;
variable.begin = currentValue; return true;
return currentValue != targetValue; }
void _updateBeginValue(AnimatedValue variable) {
variable?.begin = variable.value;
} }
bool _configAllVariables() { bool _configAllVariables() {
bool needsAnimation = false; bool startAnimation = false;
if (config.constraints != null) { if (config.constraints != null) {
_constraints ??= new AnimatedBoxConstraintsValue(config.constraints); _constraints ??= new AnimatedBoxConstraintsValue(config.constraints);
if (_configVariable(_constraints, config.constraints)) if (_updateEndValue(_constraints, config.constraints))
needsAnimation = true; startAnimation = true;
} else { } else {
_constraints = null; _constraints = null;
} }
if (config.decoration != null) { if (config.decoration != null) {
_decoration ??= new AnimatedDecorationValue(config.decoration); _decoration ??= new AnimatedDecorationValue(config.decoration);
if (_configVariable(_decoration, config.decoration)) if (_updateEndValue(_decoration, config.decoration))
needsAnimation = true; startAnimation = true;
} else { } else {
_decoration = null; _decoration = null;
} }
if (config.foregroundDecoration != null) { if (config.foregroundDecoration != null) {
_foregroundDecoration ??= new AnimatedDecorationValue(config.foregroundDecoration); _foregroundDecoration ??= new AnimatedDecorationValue(config.foregroundDecoration);
if (_configVariable(_foregroundDecoration, config.foregroundDecoration)) if (_updateEndValue(_foregroundDecoration, config.foregroundDecoration))
needsAnimation = true; startAnimation = true;
} else { } else {
_foregroundDecoration = null; _foregroundDecoration = null;
} }
if (config.margin != null) { if (config.margin != null) {
_margin ??= new AnimatedEdgeDimsValue(config.margin); _margin ??= new AnimatedEdgeDimsValue(config.margin);
if (_configVariable(_margin, config.margin)) if (_updateEndValue(_margin, config.margin))
needsAnimation = true; startAnimation = true;
} else { } else {
_margin = null; _margin = null;
} }
if (config.padding != null) { if (config.padding != null) {
_padding ??= new AnimatedEdgeDimsValue(config.padding); _padding ??= new AnimatedEdgeDimsValue(config.padding);
if (_configVariable(_padding, config.padding)) if (_updateEndValue(_padding, config.padding))
needsAnimation = true; startAnimation = true;
} else { } else {
_padding = null; _padding = null;
} }
if (config.transform != null) { if (config.transform != null) {
_transform ??= new AnimatedMatrix4Value(config.transform); _transform ??= new AnimatedMatrix4Value(config.transform);
if (_configVariable(_transform, config.transform)) if (_updateEndValue(_transform, config.transform))
needsAnimation = true; startAnimation = true;
} else { } else {
_transform = null; _transform = null;
} }
if (config.width != null) { if (config.width != null) {
_width ??= new AnimatedValue<double>(config.width); _width ??= new AnimatedValue<double>(config.width);
if (_configVariable(_width, config.width)) if (_updateEndValue(_width, config.width))
needsAnimation = true; startAnimation = true;
} else { } else {
_width = null; _width = null;
} }
if (config.height != null) { if (config.height != null) {
_height ??= new AnimatedValue<double>(config.height); _height ??= new AnimatedValue<double>(config.height);
if (_configVariable(_height, config.height)) if (_updateEndValue(_height, config.height))
needsAnimation = true; startAnimation = true;
} else { } else {
_height = null; _height = null;
} }
return needsAnimation; return startAnimation;
} }
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -100,4 +100,74 @@ void main() { ...@@ -100,4 +100,74 @@ void main() {
expect(tester.binding.transientCallbackCount, 0); expect(tester.binding.transientCallbackCount, 0);
}); });
}); });
test('Animation rerun', () {
testWidgets((WidgetTester tester) {
tester.pumpWidget(
new Center(
child: new AnimatedContainer(
duration: const Duration(milliseconds: 200),
width: 100.0,
height: 100.0,
child: new Text('X')
)
)
);
tester.pump();
tester.pump(new Duration(milliseconds: 100));
RenderBox text = tester.findText('X').renderObject;
expect(text.size.width, equals(100.0));
expect(text.size.height, equals(100.0));
tester.pump(new Duration(milliseconds: 1000));
tester.pumpWidget(
new Center(
child: new AnimatedContainer(
duration: const Duration(milliseconds: 200),
width: 200.0,
height: 200.0,
child: new Text('X')
)
)
);
tester.pump();
tester.pump(new Duration(milliseconds: 100));
text = tester.findText('X').renderObject;
expect(text.size.width, greaterThan(110.0));
expect(text.size.width, lessThan(190.0));
expect(text.size.height, greaterThan(110.0));
expect(text.size.height, lessThan(190.0));
tester.pump(new Duration(milliseconds: 1000));
expect(text.size.width, equals(200.0));
expect(text.size.height, equals(200.0));
tester.pumpWidget(
new Center(
child: new AnimatedContainer(
duration: const Duration(milliseconds: 200),
width: 200.0,
height: 100.0,
child: new Text('X')
)
)
);
tester.pump();
tester.pump(new Duration(milliseconds: 100));
expect(text.size.width, equals(200.0));
expect(text.size.height, greaterThan(110.0));
expect(text.size.height, lessThan(190.0));
tester.pump(new Duration(milliseconds: 1000));
expect(text.size.width, equals(200.0));
expect(text.size.height, equals(100.0));
});
});
} }
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