Unverified Commit ddca78b4 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Fix memory leak in TransitionRoute (#42777)

parent 1faf6a9a
...@@ -228,31 +228,49 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> { ...@@ -228,31 +228,49 @@ abstract class TransitionRoute<T> extends OverlayRoute<T> {
if (nextRoute is TransitionRoute<dynamic> && canTransitionTo(nextRoute) && nextRoute.canTransitionFrom(this)) { if (nextRoute is TransitionRoute<dynamic> && canTransitionTo(nextRoute) && nextRoute.canTransitionFrom(this)) {
final Animation<double> current = _secondaryAnimation.parent; final Animation<double> current = _secondaryAnimation.parent;
if (current != null) { if (current != null) {
if (current is TrainHoppingAnimation) { final Animation<double> currentTrain = current is TrainHoppingAnimation ? current.currentTrain : current;
final Animation<double> nextTrain = nextRoute._animation;
if (currentTrain.value == nextTrain.value) {
_setSecondaryAnimation(nextTrain, nextRoute.completed);
} else {
TrainHoppingAnimation newAnimation; TrainHoppingAnimation newAnimation;
newAnimation = TrainHoppingAnimation( newAnimation = TrainHoppingAnimation(
current.currentTrain, currentTrain,
nextRoute._animation, nextTrain,
onSwitchedTrain: () { onSwitchedTrain: () {
assert(_secondaryAnimation.parent == newAnimation); assert(_secondaryAnimation.parent == newAnimation);
assert(newAnimation.currentTrain == nextRoute._animation); assert(newAnimation.currentTrain == nextRoute._animation);
_secondaryAnimation.parent = newAnimation.currentTrain; _setSecondaryAnimation(newAnimation.currentTrain, nextRoute.completed);
newAnimation.dispose(); newAnimation.dispose();
}, },
); );
_secondaryAnimation.parent = newAnimation; _setSecondaryAnimation(newAnimation, nextRoute.completed);
}
if (current is TrainHoppingAnimation) {
current.dispose(); current.dispose();
} else {
_secondaryAnimation.parent = TrainHoppingAnimation(current, nextRoute._animation);
} }
} else { } else {
_secondaryAnimation.parent = nextRoute._animation; _setSecondaryAnimation(nextRoute._animation, nextRoute.completed);
} }
} else { } else {
_secondaryAnimation.parent = kAlwaysDismissedAnimation; _setSecondaryAnimation(kAlwaysDismissedAnimation);
} }
} }
void _setSecondaryAnimation(Animation<double> animation, [Future<dynamic> disposed]) {
_secondaryAnimation.parent = animation;
// Release the reference to the next route's animation when that route
// is disposed.
disposed?.then((dynamic _) {
if (_secondaryAnimation.parent == animation) {
_secondaryAnimation.parent = kAlwaysDismissedAnimation;
if (animation is TrainHoppingAnimation) {
animation.dispose();
}
}
});
}
/// Returns true if this route supports a transition animation that runs /// Returns true if this route supports a transition animation that runs
/// when [nextRoute] is pushed on top of it or when [nextRoute] is popped /// when [nextRoute] is pushed on top of it or when [nextRoute] is popped
/// off of it. /// off of it.
......
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