Browse Source

Enable transitions to run on custom clocks.

pull/1715/head
Jeremy Koritzinsky 8 years ago
parent
commit
b0368c80b2
  1. 2
      src/Avalonia.Animation/Animatable.cs
  2. 2
      src/Avalonia.Animation/ITransition.cs
  3. 8
      src/Avalonia.Animation/TransitionInstance.cs
  4. 4
      src/Avalonia.Animation/Transition`1.cs

2
src/Avalonia.Animation/Animatable.cs

@ -69,7 +69,7 @@ namespace Avalonia.Animation
if (match != null)
{
match.Apply(this, e.OldValue, e.NewValue);
match.Apply(this, Clock.GlobalClock, e.OldValue, e.NewValue);
}
}
}

2
src/Avalonia.Animation/ITransition.cs

@ -13,7 +13,7 @@ namespace Avalonia.Animation
/// <summary>
/// Applies the transition to the specified <see cref="Animatable"/>.
/// </summary>
IDisposable Apply(Animatable control, object oldValue, object newValue);
IDisposable Apply(Animatable control, Clock clock, object oldValue, object newValue);
/// <summary>
/// Gets the property to be animated.

8
src/Avalonia.Animation/TransitionInstance.cs

@ -18,10 +18,12 @@ namespace Avalonia.Animation
private IDisposable timerSubscription;
private TimeSpan startTime;
private TimeSpan duration;
private readonly Clock _clock;
public TransitionInstance(TimeSpan Duration)
public TransitionInstance(Clock clock, TimeSpan Duration)
{
duration = Duration;
_clock = clock;
}
private void TimerTick(TimeSpan t)
@ -45,8 +47,8 @@ namespace Avalonia.Animation
protected override void Subscribed()
{
startTime = Clock.GlobalClock.CurrentTime;
timerSubscription = Clock.GlobalClock.Subscribe(TimerTick);
startTime = _clock.CurrentTime;
timerSubscription = _clock.Subscribe(TimerTick);
PublishNext(0.0d);
}
}

4
src/Avalonia.Animation/Transition`1.cs

@ -49,9 +49,9 @@ namespace Avalonia.Animation
public abstract IObservable<T> DoTransition(IObservable<double> progress, T oldValue, T newValue);
/// <inheritdocs/>
public virtual IDisposable Apply(Animatable control, object oldValue, object newValue)
public virtual IDisposable Apply(Animatable control, Clock clock, object oldValue, object newValue)
{
var transition = DoTransition(new TransitionInstance(Duration), (T)oldValue, (T)newValue);
var transition = DoTransition(new TransitionInstance(clock, Duration), (T)oldValue, (T)newValue);
return control.Bind<T>((AvaloniaProperty<T>)Property, transition, Data.BindingPriority.Animation);
}

Loading…
Cancel
Save