Browse Source

Merge pull request #6072 from AvaloniaUI/fixes/animationinstance-unsubscribe

Ensure we unsubscribe from PropertyChanged.
pull/6105/head
Jumar Macato 5 years ago
committed by GitHub
parent
commit
60f3599a4d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/Avalonia.Animation/AnimationInstance`1.cs

8
src/Avalonia.Animation/AnimationInstance`1.cs

@ -37,6 +37,7 @@ namespace Avalonia.Animation
private IDisposable _timerSub; private IDisposable _timerSub;
private readonly IClock _baseClock; private readonly IClock _baseClock;
private IClock _clock; 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) public AnimationInstance(Animation animation, Animatable control, Animator<T> animator, IClock baseClock, Action OnComplete, Func<double, T, T> Interpolator)
{ {
@ -46,9 +47,6 @@ namespace Avalonia.Animation
_onCompleteAction = OnComplete; _onCompleteAction = OnComplete;
_interpolator = Interpolator; _interpolator = Interpolator;
_baseClock = baseClock; _baseClock = baseClock;
control.PropertyChanged += ControlPropertyChanged;
UpdateNeutralValue();
FetchProperties(); FetchProperties();
} }
@ -82,6 +80,7 @@ namespace Avalonia.Animation
// Animation may have been stopped before it has finished. // Animation may have been stopped before it has finished.
ApplyFinalFill(); ApplyFinalFill();
_targetControl.PropertyChanged -= _propertyChangedDelegate;
_timerSub?.Dispose(); _timerSub?.Dispose();
_clock.PlayState = PlayState.Stop; _clock.PlayState = PlayState.Stop;
} }
@ -90,6 +89,9 @@ namespace Avalonia.Animation
{ {
_clock = new Clock(_baseClock); _clock = new Clock(_baseClock);
_timerSub = _clock.Subscribe(Step); _timerSub = _clock.Subscribe(Step);
_propertyChangedDelegate ??= ControlPropertyChanged;
_targetControl.PropertyChanged += _propertyChangedDelegate;
UpdateNeutralValue();
} }
public void Step(TimeSpan frameTick) public void Step(TimeSpan frameTick)

Loading…
Cancel
Save