17 changed files with 120 additions and 146 deletions
@ -1,45 +1,58 @@ |
|||
using System; |
|||
using Avalonia.Animation.Easings; |
|||
using Avalonia.Reactive; |
|||
|
|||
#nullable enable |
|||
|
|||
namespace Avalonia.Animation |
|||
{ |
|||
/// <summary>
|
|||
/// Provides base for observables implementing transitions.
|
|||
/// </summary>
|
|||
/// <typeparam name="T">Type of the transitioned value.</typeparam>
|
|||
public abstract class TransitionObservableBase<T> : SingleSubscriberObservableBase<T>, IObserver<double> |
|||
{ |
|||
private readonly Easing _easing; |
|||
private readonly IObservable<double> _progress; |
|||
private IDisposable? _progressSubscription; |
|||
|
|||
protected TransitionObservableBase(IObservable<double> progress) |
|||
protected TransitionObservableBase(IObservable<double> progress, Easing easing) |
|||
{ |
|||
_progress = progress; |
|||
_easing = easing; |
|||
} |
|||
|
|||
void IObserver<double>.OnCompleted() |
|||
/// <summary>
|
|||
/// Produces value at given progress time point.
|
|||
/// </summary>
|
|||
/// <param name="progress">Transition progress.</param>
|
|||
protected abstract T ProduceValue(double progress); |
|||
|
|||
protected override void Subscribed() |
|||
{ |
|||
PublishCompleted(); |
|||
_progressSubscription = _progress.Subscribe(this); |
|||
} |
|||
|
|||
void IObserver<double>.OnError(Exception error) |
|||
protected override void Unsubscribed() |
|||
{ |
|||
PublishError(error); |
|||
_progressSubscription?.Dispose(); |
|||
} |
|||
|
|||
void IObserver<double>.OnNext(double value) |
|||
void IObserver<double>.OnCompleted() |
|||
{ |
|||
PublishNext(ProduceValue(value)); |
|||
PublishCompleted(); |
|||
} |
|||
|
|||
protected override void Unsubscribed() |
|||
void IObserver<double>.OnError(Exception error) |
|||
{ |
|||
_progressSubscription?.Dispose(); |
|||
PublishError(error); |
|||
} |
|||
|
|||
protected override void Subscribed() |
|||
void IObserver<double>.OnNext(double value) |
|||
{ |
|||
_progressSubscription = _progress.Subscribe(this); |
|||
} |
|||
double progress = _easing.Ease(value); |
|||
|
|||
protected abstract T ProduceValue(double progress); |
|||
PublishNext(ProduceValue(progress)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,12 @@ |
|||
using Avalonia.Animation.Animators; |
|||
using Avalonia.Media; |
|||
|
|||
namespace Avalonia.Animation |
|||
{ |
|||
/// <summary>
|
|||
/// Transition class that handles <see cref="AvaloniaProperty"/> with <see cref="Color"/> type.
|
|||
/// </summary>
|
|||
public class ColorTransition : AnimatorDrivenTransition<Color, ColorAnimator> |
|||
{ |
|||
} |
|||
} |
|||
Loading…
Reference in new issue