JT
1 year ago
committed by
GitHub
11 changed files with 334 additions and 19 deletions
@ -0,0 +1,12 @@
|
||||
using System; |
||||
using FluentAvalonia.UI.Media.Animation; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Animations; |
||||
|
||||
public abstract class BaseTransitionInfo : NavigationTransitionInfo |
||||
{ |
||||
/// <summary> |
||||
/// The duration of the animation at 1x animation scale |
||||
/// </summary> |
||||
public abstract TimeSpan Duration { get; set; } |
||||
} |
@ -0,0 +1,59 @@
|
||||
using System; |
||||
using System.Threading; |
||||
using Avalonia; |
||||
using Avalonia.Animation; |
||||
using Avalonia.Animation.Easings; |
||||
using Avalonia.Media; |
||||
using Avalonia.Styling; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Animations; |
||||
|
||||
public class BetterDrillInNavigationTransition : BaseTransitionInfo |
||||
{ |
||||
/// <summary> |
||||
/// Gets or sets whether the animation should drill in (false) or drill out (true) |
||||
/// </summary> |
||||
public bool IsReversed { get; set; } = false; //Zoom out if true |
||||
|
||||
public override TimeSpan Duration { get; set; } = TimeSpan.FromMilliseconds(400); |
||||
|
||||
public override async void RunAnimation(Animatable ctrl, CancellationToken cancellationToken) |
||||
{ |
||||
var animation = new Animation |
||||
{ |
||||
Easing = new SplineEasing(0.1, 0.9, 0.2, 1.0), |
||||
Children = |
||||
{ |
||||
new KeyFrame |
||||
{ |
||||
Setters = |
||||
{ |
||||
new Setter(Visual.OpacityProperty, 0.0), |
||||
new Setter(ScaleTransform.ScaleXProperty, IsReversed ? 1.5 : 0.0), |
||||
new Setter(ScaleTransform.ScaleYProperty, IsReversed ? 1.5 : 0.0) |
||||
}, |
||||
Cue = new Cue(0d) |
||||
}, |
||||
new KeyFrame |
||||
{ |
||||
Setters = |
||||
{ |
||||
new Setter(Visual.OpacityProperty, 1.0), |
||||
new Setter(ScaleTransform.ScaleXProperty, IsReversed ? 1.0 : 1.0), |
||||
new Setter(ScaleTransform.ScaleYProperty, IsReversed ? 1.0 : 1.0) |
||||
}, |
||||
Cue = new Cue(1d) |
||||
} |
||||
}, |
||||
Duration = Duration, |
||||
FillMode = FillMode.Forward |
||||
}; |
||||
|
||||
await animation.RunAsync(ctrl, cancellationToken); |
||||
|
||||
if (ctrl is Visual visualCtrl) |
||||
{ |
||||
visualCtrl.Opacity = 1; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,66 @@
|
||||
using System; |
||||
using System.Threading; |
||||
using AsyncAwaitBestPractices; |
||||
using Avalonia; |
||||
using Avalonia.Animation; |
||||
using Avalonia.Animation.Easings; |
||||
using Avalonia.Media; |
||||
using Avalonia.Styling; |
||||
using FluentAvalonia.UI.Media.Animation; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Animations; |
||||
|
||||
public class BetterEntranceNavigationTransition : BaseTransitionInfo |
||||
{ |
||||
public override TimeSpan Duration { get; set; } = TimeSpan.FromMilliseconds(500); |
||||
|
||||
/// <summary> |
||||
/// Gets or sets the Horizontal Offset used when animating |
||||
/// </summary> |
||||
public double FromHorizontalOffset { get; set; } = 0; |
||||
|
||||
/// <summary> |
||||
/// Gets or sets the Vertical Offset used when animating |
||||
/// </summary> |
||||
public double FromVerticalOffset { get; set; } = 100; |
||||
|
||||
public override async void RunAnimation(Animatable ctrl, CancellationToken cancellationToken) |
||||
{ |
||||
var animation = new Animation |
||||
{ |
||||
Easing = new SplineEasing(0.1, 0.9, 0.2, 1.0), |
||||
Children = |
||||
{ |
||||
new KeyFrame |
||||
{ |
||||
Setters = |
||||
{ |
||||
new Setter(Visual.OpacityProperty, 0.0), |
||||
new Setter(TranslateTransform.XProperty,FromHorizontalOffset), |
||||
new Setter(TranslateTransform.YProperty, FromVerticalOffset) |
||||
}, |
||||
Cue = new Cue(0d) |
||||
}, |
||||
new KeyFrame |
||||
{ |
||||
Setters = |
||||
{ |
||||
new Setter(Visual.OpacityProperty, 1d), |
||||
new Setter(TranslateTransform.XProperty,0.0), |
||||
new Setter(TranslateTransform.YProperty, 0.0) |
||||
}, |
||||
Cue = new Cue(1d) |
||||
} |
||||
}, |
||||
Duration = Duration, |
||||
FillMode = FillMode.Forward |
||||
}; |
||||
|
||||
await animation.RunAsync(ctrl, cancellationToken); |
||||
|
||||
if (ctrl is Visual visualCtrl) |
||||
{ |
||||
visualCtrl.Opacity = 1; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,96 @@
|
||||
using System; |
||||
using System.Threading; |
||||
using Avalonia; |
||||
using Avalonia.Animation; |
||||
using Avalonia.Animation.Easings; |
||||
using Avalonia.Media; |
||||
using Avalonia.Styling; |
||||
using FluentAvalonia.UI.Media.Animation; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Animations; |
||||
|
||||
public class BetterSlideNavigationTransition : BaseTransitionInfo |
||||
{ |
||||
public override TimeSpan Duration { get; set; } = TimeSpan.FromMilliseconds(167); |
||||
|
||||
/// <summary> |
||||
/// Gets or sets the type of animation effect to play during the slide transition. |
||||
/// </summary> |
||||
public SlideNavigationTransitionEffect Effect { get; set; } = SlideNavigationTransitionEffect.FromRight; |
||||
|
||||
/// <summary> |
||||
/// Gets or sets the HorizontalOffset used when animating from the Left or Right |
||||
/// </summary> |
||||
public double FromHorizontalOffset { get; set; } = 56; |
||||
|
||||
/// <summary> |
||||
/// Gets or sets the VerticalOffset used when animating from the Top or Bottom |
||||
/// </summary> |
||||
public double FromVerticalOffset { get; set; } = 56; |
||||
|
||||
public override async void RunAnimation(Animatable ctrl, CancellationToken cancellationToken) |
||||
{ |
||||
double length = 0; |
||||
bool isVertical = false; |
||||
switch (Effect) |
||||
{ |
||||
case SlideNavigationTransitionEffect.FromLeft: |
||||
length = -FromHorizontalOffset; |
||||
break; |
||||
case SlideNavigationTransitionEffect.FromRight: |
||||
length = FromHorizontalOffset; |
||||
break; |
||||
case SlideNavigationTransitionEffect.FromTop: |
||||
length = -FromVerticalOffset; |
||||
isVertical = true; |
||||
break; |
||||
case SlideNavigationTransitionEffect.FromBottom: |
||||
length = FromVerticalOffset; |
||||
isVertical = true; |
||||
break; |
||||
} |
||||
|
||||
var animation = new Animation |
||||
{ |
||||
Easing = new SplineEasing(0.1, 0.9, 0.2, 1.0), |
||||
Children = |
||||
{ |
||||
new KeyFrame |
||||
{ |
||||
Setters = |
||||
{ |
||||
new Setter(isVertical ? TranslateTransform.YProperty : TranslateTransform.XProperty, length), |
||||
new Setter(Visual.OpacityProperty, 0d) |
||||
}, |
||||
Cue = new Cue(0d) |
||||
}, |
||||
new KeyFrame |
||||
{ |
||||
Setters= |
||||
{ |
||||
new Setter(Visual.OpacityProperty, 1d) |
||||
}, |
||||
Cue = new Cue(0.05d) |
||||
}, |
||||
new KeyFrame |
||||
{ |
||||
Setters = |
||||
{ |
||||
new Setter(Visual.OpacityProperty, 1d), |
||||
new Setter(isVertical ? TranslateTransform.YProperty : TranslateTransform.XProperty, 0.0) |
||||
}, |
||||
Cue = new Cue(1d) |
||||
} |
||||
}, |
||||
Duration = Duration, |
||||
FillMode = FillMode.Forward |
||||
}; |
||||
|
||||
await animation.RunAsync(ctrl, cancellationToken); |
||||
|
||||
if (ctrl is Visual visual) |
||||
{ |
||||
visual.Opacity = 1; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue