Browse Source
Currently only one transition available: CrossFadeTransition, which is demonstrated in the test app.pull/58/head
16 changed files with 253 additions and 11 deletions
@ -0,0 +1,62 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="Animation.cs" company="Steven Kirk">
|
|||
// Copyright 2015 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Animation |
|||
{ |
|||
using System; |
|||
|
|||
/// <summary>
|
|||
/// Tracks the progress of an animation.
|
|||
/// </summary>
|
|||
public class Animation : IObservable<object>, IDisposable |
|||
{ |
|||
private IObservable<object> inner; |
|||
|
|||
private IDisposable subscription; |
|||
|
|||
public Animation(IObservable<object> inner, IDisposable subscription) |
|||
{ |
|||
this.inner = inner; |
|||
this.subscription = subscription; |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
this.subscription.Dispose(); |
|||
} |
|||
|
|||
public IDisposable Subscribe(IObserver<object> observer) |
|||
{ |
|||
return this.inner.Subscribe(observer); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tracks the progress of an animation.
|
|||
/// </summary>
|
|||
public class Animation<T> : IObservable<T>, IDisposable |
|||
{ |
|||
private IObservable<T> inner; |
|||
|
|||
private IDisposable subscription; |
|||
|
|||
public Animation(IObservable<T> inner, IDisposable subscription) |
|||
{ |
|||
this.inner = inner; |
|||
this.subscription = subscription; |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
this.subscription.Dispose(); |
|||
} |
|||
|
|||
public IDisposable Subscribe(IObserver<T> observer) |
|||
{ |
|||
return this.inner.Subscribe(observer); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,70 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="CrossFadeTransition.cs" company="Steven Kirk">
|
|||
// Copyright 2015 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Animation |
|||
{ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Reactive.Linq; |
|||
using System.Reactive.Threading.Tasks; |
|||
using System.Threading.Tasks; |
|||
|
|||
public class CrossFadeTransition : IVisibilityTransition |
|||
{ |
|||
public CrossFadeTransition(TimeSpan duration) |
|||
{ |
|||
this.Duration = duration; |
|||
} |
|||
|
|||
public TimeSpan Duration { get; } |
|||
|
|||
public async Task Start(Visual from, Visual to) |
|||
{ |
|||
var tasks = new List<Task>(); |
|||
|
|||
if (to != null) |
|||
{ |
|||
to.Opacity = 0; |
|||
} |
|||
|
|||
if (from != null) |
|||
{ |
|||
tasks.Add(Animate.Property( |
|||
from, |
|||
Visual.OpacityProperty, |
|||
from.Opacity, |
|||
0, |
|||
LinearEasing.For<double>(), |
|||
this.Duration).ToTask()); |
|||
} |
|||
|
|||
if (to != null) |
|||
{ |
|||
to.Opacity = 0; |
|||
to.IsVisible = true; |
|||
|
|||
tasks.Add(Animate.Property( |
|||
to, |
|||
Visual.OpacityProperty, |
|||
0, |
|||
1, |
|||
LinearEasing.For<double>(), |
|||
this.Duration).ToTask()); |
|||
|
|||
} |
|||
|
|||
await Task.WhenAll(tasks.ToArray()); |
|||
|
|||
if (from != null) |
|||
{ |
|||
from.IsVisible = false; |
|||
from.Opacity = 1; |
|||
} |
|||
|
|||
to.Opacity = 1; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="IVisibilityTransition.cs" company="Steven Kirk">
|
|||
// Copyright 2015 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Animation |
|||
{ |
|||
using System.Threading.Tasks; |
|||
|
|||
public interface IVisibilityTransition |
|||
{ |
|||
Task Start(Visual from, Visual to); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue