Browse Source

Ability to set easings

pull/4790/head
artyom 6 years ago
parent
commit
c3693a01cc
  1. 10
      src/Avalonia.Visuals/Animation/CompositePageTransition.cs
  2. 29
      src/Avalonia.Visuals/Animation/CrossFade.cs
  3. 44
      src/Avalonia.Visuals/Animation/PageSlide.cs

10
src/Avalonia.Visuals/Animation/CompositeTransition.cs → src/Avalonia.Visuals/Animation/CompositePageTransition.cs

@ -6,28 +6,28 @@ using Avalonia.Metadata;
namespace Avalonia.Animation namespace Avalonia.Animation
{ {
/// <summary> /// <summary>
/// Defines a composite transition that can be used to combine multiple transitions into one. /// Defines a composite page transition that can be used to combine multiple transitions.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// <para> /// <para>
/// Instantiate the <see cref="CompositeTransition" /> in XAML and initialize the /// Instantiate the <see cref="CompositePageTransition" /> in XAML and initialize the
/// <see cref="Transitions" /> property in order to have many animations triggered at once. /// <see cref="Transitions" /> property in order to have many animations triggered at once.
/// For example, you can combine <see cref="CrossFade"/> and <see cref="PageSlide"/>. /// For example, you can combine <see cref="CrossFade"/> and <see cref="PageSlide"/>.
/// <code> /// <code>
/// <![CDATA[ /// <![CDATA[
/// <reactiveUi:RoutedViewHost Router="{Binding Router}"> /// <reactiveUi:RoutedViewHost Router="{Binding Router}">
/// <reactiveUi:RoutedViewHost.PageTransition> /// <reactiveUi:RoutedViewHost.PageTransition>
/// <CompositeTransition> /// <CompositePageTransition>
/// <PageSlide Duration="0.5" /> /// <PageSlide Duration="0.5" />
/// <CrossFade Duration="0.5" /> /// <CrossFade Duration="0.5" />
/// </CompositeTransition> /// </CompositePageTransition>
/// </reactiveUi:RoutedViewHost.PageTransition> /// </reactiveUi:RoutedViewHost.PageTransition>
/// </reactiveUi:RoutedViewHost> /// </reactiveUi:RoutedViewHost>
/// ]]> /// ]]>
/// </code> /// </code>
/// </para> /// </para>
/// </remarks> /// </remarks>
public class CompositeTransition : IPageTransition public class CompositePageTransition : IPageTransition
{ {
/// <summary> /// <summary>
/// Gets or sets the transitions to be executed. Can be defined from XAML. /// Gets or sets the transitions to be executed. Can be defined from XAML.

29
src/Avalonia.Visuals/Animation/CrossFade.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Animation.Easings;
using Avalonia.Styling; using Avalonia.Styling;
using Avalonia.VisualTree; using Avalonia.VisualTree;
@ -74,14 +75,26 @@ namespace Avalonia.Animation
/// </summary> /// </summary>
public TimeSpan Duration public TimeSpan Duration
{ {
get get => _fadeOutAnimation.Duration;
{ set => _fadeOutAnimation.Duration = _fadeInAnimation.Duration = value;
return _fadeOutAnimation.Duration; }
}
set /// <summary>
{ /// Gets or sets element entrance easing.
_fadeOutAnimation.Duration = _fadeInAnimation.Duration = value; /// </summary>
} public Easing EntranceEasing
{
get => _fadeInAnimation.Easing;
set => _fadeInAnimation.Easing = value;
}
/// <summary>
/// Gets or sets element exit easing.
/// </summary>
public Easing ExitEasing
{
get => _fadeOutAnimation.Easing;
set => _fadeOutAnimation.Easing = value;
} }
/// <summary> /// <summary>

44
src/Avalonia.Visuals/Animation/PageSlide.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Animation.Easings;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Styling; using Avalonia.Styling;
using Avalonia.VisualTree; using Avalonia.VisualTree;
@ -48,6 +49,16 @@ namespace Avalonia.Animation
/// Gets the duration of the animation. /// Gets the duration of the animation.
/// </summary> /// </summary>
public SlideAxis Orientation { get; set; } public SlideAxis Orientation { get; set; }
/// <summary>
/// Gets or sets element entrance easing.
/// </summary>
public Easing EntranceEasing { get; set; } = new LinearEasing();
/// <summary>
/// Gets or sets element exit easing.
/// </summary>
public Easing ExitEasing { get; set; } = new LinearEasing();
/// <summary> /// <summary>
/// Starts the animation. /// Starts the animation.
@ -75,18 +86,12 @@ namespace Avalonia.Animation
{ {
var animation = new Animation var animation = new Animation
{ {
Children = Easing = ExitEasing,
Children =
{ {
new KeyFrame new KeyFrame
{ {
Setters = Setters = { new Setter { Property = translateProperty, Value = 0d } },
{
new Setter
{
Property = translateProperty,
Value = 0d
}
},
Cue = new Cue(0d) Cue = new Cue(0d)
}, },
new KeyFrame new KeyFrame
@ -100,10 +105,10 @@ namespace Avalonia.Animation
} }
}, },
Cue = new Cue(1d) Cue = new Cue(1d)
} }
} },
Duration = Duration
}; };
animation.Duration = Duration;
tasks.Add(animation.RunAsync(from)); tasks.Add(animation.RunAsync(from));
} }
@ -112,9 +117,9 @@ namespace Avalonia.Animation
to.IsVisible = true; to.IsVisible = true;
var animation = new Animation var animation = new Animation
{ {
Easing = EntranceEasing,
Children = Children =
{ {
new KeyFrame new KeyFrame
{ {
Setters = Setters =
@ -129,19 +134,12 @@ namespace Avalonia.Animation
}, },
new KeyFrame new KeyFrame
{ {
Setters = Setters = { new Setter { Property = translateProperty, Value = 0d } },
{
new Setter
{
Property = translateProperty,
Value = 0d
}
},
Cue = new Cue(1d) Cue = new Cue(1d)
} }
} },
Duration = Duration
}; };
animation.Duration = Duration;
tasks.Add(animation.RunAsync(to)); tasks.Add(animation.RunAsync(to));
} }

Loading…
Cancel
Save