Skip to content

Commit

Permalink
Merge pull request #6072 from AvaloniaUI/fixes/animationinstance-unsu…
Browse files Browse the repository at this point in the history
…bscribe

Ensure we unsubscribe from PropertyChanged.
  • Loading branch information
jmacato committed Jun 17, 2021
2 parents 665560b + 4e8afe6 commit 60f3599
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Avalonia.Animation/AnimationInstance`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal class AnimationInstance<T> : SingleSubscriberObservableBase<T>
private IDisposable _timerSub;
private readonly IClock _baseClock;
private IClock _clock;
private EventHandler<AvaloniaPropertyChangedEventArgs> _propertyChangedDelegate;

public AnimationInstance(Animation animation, Animatable control, Animator<T> animator, IClock baseClock, Action OnComplete, Func<double, T, T> Interpolator)
{
Expand All @@ -46,9 +47,6 @@ public AnimationInstance(Animation animation, Animatable control, Animator<T> an
_onCompleteAction = OnComplete;
_interpolator = Interpolator;
_baseClock = baseClock;
control.PropertyChanged += ControlPropertyChanged;

UpdateNeutralValue();
FetchProperties();
}

Expand Down Expand Up @@ -82,6 +80,7 @@ protected override void Unsubscribed()
// Animation may have been stopped before it has finished.
ApplyFinalFill();

_targetControl.PropertyChanged -= _propertyChangedDelegate;
_timerSub?.Dispose();
_clock.PlayState = PlayState.Stop;
}
Expand All @@ -90,6 +89,9 @@ protected override void Subscribed()
{
_clock = new Clock(_baseClock);
_timerSub = _clock.Subscribe(Step);
_propertyChangedDelegate ??= ControlPropertyChanged;
_targetControl.PropertyChanged += _propertyChangedDelegate;
UpdateNeutralValue();
}

public void Step(TimeSpan frameTick)
Expand Down

0 comments on commit 60f3599

Please sign in to comment.