|
|
|
@ -5,6 +5,7 @@ using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Reactive.Threading.Tasks; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Avalonia.Styling; |
|
|
|
using Avalonia.VisualTree; |
|
|
|
|
|
|
|
namespace Avalonia.Animation |
|
|
|
@ -14,10 +15,14 @@ namespace Avalonia.Animation |
|
|
|
/// </summary>
|
|
|
|
public class CrossFade : IPageTransition |
|
|
|
{ |
|
|
|
private Animation _fadeOutAnimation; |
|
|
|
private Animation _fadeInAnimation; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="CrossFade"/> class.
|
|
|
|
/// </summary>
|
|
|
|
public CrossFade() |
|
|
|
:this(TimeSpan.Zero) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
@ -27,13 +32,62 @@ namespace Avalonia.Animation |
|
|
|
/// <param name="duration">The duration of the animation.</param>
|
|
|
|
public CrossFade(TimeSpan duration) |
|
|
|
{ |
|
|
|
Duration = duration; |
|
|
|
_fadeOutAnimation = new Animation |
|
|
|
{ |
|
|
|
new KeyFrame |
|
|
|
( |
|
|
|
new Setter |
|
|
|
{ |
|
|
|
Property = Visual.OpacityProperty, |
|
|
|
Value = 0.0 |
|
|
|
} |
|
|
|
) |
|
|
|
{ |
|
|
|
Cue = new Cue(1.0) |
|
|
|
} |
|
|
|
}; |
|
|
|
_fadeInAnimation = new Animation |
|
|
|
{ |
|
|
|
new KeyFrame |
|
|
|
( |
|
|
|
new Setter |
|
|
|
{ |
|
|
|
Property = Visual.OpacityProperty, |
|
|
|
Value = 0.0 |
|
|
|
} |
|
|
|
) |
|
|
|
{ |
|
|
|
Cue = new Cue(0.0) |
|
|
|
}, |
|
|
|
new KeyFrame |
|
|
|
( |
|
|
|
new Setter |
|
|
|
{ |
|
|
|
Property = Visual.OpacityProperty, |
|
|
|
Value = 1.0 |
|
|
|
} |
|
|
|
) |
|
|
|
{ |
|
|
|
Cue = new Cue(1.0) |
|
|
|
} |
|
|
|
}; |
|
|
|
_fadeOutAnimation.Duration = _fadeInAnimation.Duration = duration; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the duration of the animation.
|
|
|
|
/// </summary>
|
|
|
|
public TimeSpan Duration { get; set; } |
|
|
|
public TimeSpan Duration |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
return _fadeOutAnimation.Duration; |
|
|
|
} |
|
|
|
set |
|
|
|
{ |
|
|
|
_fadeOutAnimation.Duration = _fadeInAnimation.Duration = value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Starts the animation.
|
|
|
|
@ -51,26 +105,25 @@ namespace Avalonia.Animation |
|
|
|
{ |
|
|
|
var tasks = new List<Task>(); |
|
|
|
|
|
|
|
// TODO: Implement relevant transition logic here (or discard this class)
|
|
|
|
// in favor of XAML based transition for pages
|
|
|
|
if (to != null) |
|
|
|
{ |
|
|
|
to.Opacity = 0; |
|
|
|
} |
|
|
|
|
|
|
|
if (from != null) |
|
|
|
if (from is Animatable fadeOut) |
|
|
|
{ |
|
|
|
tasks.Add(_fadeOutAnimation.RunAsync(fadeOut)); |
|
|
|
} |
|
|
|
|
|
|
|
if (to != null) |
|
|
|
if (to is Animatable fadeIn) |
|
|
|
{ |
|
|
|
to.Opacity = 0; |
|
|
|
to.IsVisible = true; |
|
|
|
tasks.Add(_fadeInAnimation.RunAsync(fadeIn)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// FIXME: This is temporary until animations are fixed.
|
|
|
|
await Task.Delay(1); |
|
|
|
await Task.WhenAll(tasks); |
|
|
|
|
|
|
|
if (from != null) |
|
|
|
{ |
|
|
|
|