Animation.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. 
  2. namespace Perspex.Animation
  3. {
  4. using System;
  5. /// <summary>
  6. /// Tracks the progress of an animation.
  7. /// </summary>
  8. public class Animation : IObservable<object>, IDisposable
  9. {
  10. /// <summary>
  11. /// The animation being tracked.
  12. /// </summary>
  13. private IObservable<object> inner;
  14. /// <summary>
  15. /// The disposable used to cancel the animation.
  16. /// </summary>
  17. private IDisposable subscription;
  18. /// <summary>
  19. /// Initializes a new instance of the <see cref="Animation"/> class.
  20. /// </summary>
  21. /// <param name="inner">The animation observable being tracked.</param>
  22. /// <param name="subscription">A disposable used to cancel the animation.</param>
  23. public Animation(IObservable<object> inner, IDisposable subscription)
  24. {
  25. this.inner = inner;
  26. this.subscription = subscription;
  27. }
  28. /// <summary>
  29. /// Cancels the animation.
  30. /// </summary>
  31. public void Dispose()
  32. {
  33. this.subscription.Dispose();
  34. }
  35. /// <summary>
  36. /// Notifies the provider that an observer is to receive notifications.
  37. /// </summary>
  38. /// <param name="observer">The observer.</param>
  39. /// <returns>
  40. /// A reference to an interface that allows observers to stop receiving notifications
  41. /// before the provider has finished sending them.
  42. /// </returns>
  43. public IDisposable Subscribe(IObserver<object> observer)
  44. {
  45. return this.inner.Subscribe(observer);
  46. }
  47. }
  48. }