csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
55 lines
1.5 KiB
using Avalonia.Metadata;
|
|
using System;
|
|
using System.Reactive.Linq;
|
|
using Avalonia.Animation.Easings;
|
|
using Avalonia.Animation.Utils;
|
|
using Avalonia.Reactive;
|
|
|
|
namespace Avalonia.Animation
|
|
{
|
|
/// <summary>
|
|
/// Handles the timing and lifetime of a <see cref="Transition{T}"/>.
|
|
/// </summary>
|
|
internal class TransitionInstance : SingleSubscriberObservableBase<double>
|
|
{
|
|
private IDisposable _timerSubscription;
|
|
private TimeSpan _duration;
|
|
private readonly IClock _baseClock;
|
|
private IClock _clock;
|
|
|
|
public TransitionInstance(IClock clock, TimeSpan Duration)
|
|
{
|
|
_duration = Duration;
|
|
_baseClock = clock;
|
|
}
|
|
|
|
private void TimerTick(TimeSpan t)
|
|
{
|
|
var interpVal = _duration.Ticks == 0 ? 1d : (double)t.Ticks / _duration.Ticks;
|
|
|
|
// Clamp interpolation value.
|
|
if (interpVal >= 1d | interpVal < 0d)
|
|
{
|
|
PublishNext(1d);
|
|
PublishCompleted();
|
|
}
|
|
else
|
|
{
|
|
PublishNext(interpVal);
|
|
}
|
|
}
|
|
|
|
protected override void Unsubscribed()
|
|
{
|
|
_timerSubscription?.Dispose();
|
|
_clock.PlayState = PlayState.Stop;
|
|
}
|
|
|
|
protected override void Subscribed()
|
|
{
|
|
_clock = new Clock(_baseClock);
|
|
_timerSubscription = _clock.Subscribe(TimerTick);
|
|
PublishNext(0.0d);
|
|
}
|
|
}
|
|
}
|
|
|