AnimatorTransitionObservable.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using Avalonia.Animation.Animators;
  3. using Avalonia.Animation.Easings;
  4. namespace Avalonia.Animation
  5. {
  6. /// <summary>
  7. /// Transition observable based on an <see cref="Animator{T}"/> producing a value.
  8. /// </summary>
  9. /// <typeparam name="T">Type of the transitioned value.</typeparam>
  10. /// <typeparam name="TAnimator">Type of the animator.</typeparam>
  11. public class AnimatorTransitionObservable<T, TAnimator> : TransitionObservableBase<T> where TAnimator : Animator<T>
  12. {
  13. private readonly TAnimator _animator;
  14. private readonly Easing _easing;
  15. private readonly T _oldValue;
  16. private readonly T _newValue;
  17. public AnimatorTransitionObservable(TAnimator animator, IObservable<double> progress, Easing easing, T oldValue, T newValue) : base(progress, easing)
  18. {
  19. _animator = animator;
  20. _easing = easing;
  21. _oldValue = oldValue;
  22. _newValue = newValue;
  23. }
  24. protected override T ProduceValue(double progress)
  25. {
  26. return _animator.Interpolate(progress, _oldValue, _newValue);
  27. }
  28. }
  29. }