Browse Source

Better slide animations for sub pages

pull/324/head
Ionite 1 year ago
parent
commit
ada56a3a58
No known key found for this signature in database
  1. 53
      StabilityMatrix.Avalonia/Animations/BetterSlideNavigationTransition.cs
  2. 5
      StabilityMatrix.Avalonia/ViewModels/Settings/MainSettingsViewModel.cs
  3. 5
      StabilityMatrix.Avalonia/Views/SettingsPage.axaml.cs

53
StabilityMatrix.Avalonia/Animations/BetterSlideNavigationTransition.cs

@ -1,22 +1,25 @@
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using Avalonia; using Avalonia;
using Avalonia.Animation; using Avalonia.Animation;
using Avalonia.Animation.Easings; using Avalonia.Animation.Easings;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Styling; using Avalonia.Styling;
using FluentAvalonia.UI.Media.Animation; using FluentAvalonia.UI.Media.Animation;
using Projektanker.Icons.Avalonia;
namespace StabilityMatrix.Avalonia.Animations; namespace StabilityMatrix.Avalonia.Animations;
public class BetterSlideNavigationTransition : BaseTransitionInfo public class BetterSlideNavigationTransition : BaseTransitionInfo
{ {
public override TimeSpan Duration { get; set; } = TimeSpan.FromMilliseconds(167); public override TimeSpan Duration { get; set; } = TimeSpan.FromMilliseconds(167);
/// <summary> /// <summary>
/// Gets or sets the type of animation effect to play during the slide transition. /// Gets or sets the type of animation effect to play during the slide transition.
/// </summary> /// </summary>
public SlideNavigationTransitionEffect Effect { get; set; } = SlideNavigationTransitionEffect.FromRight; public SlideNavigationTransitionEffect Effect { get; set; } =
SlideNavigationTransitionEffect.FromRight;
/// <summary> /// <summary>
/// Gets or sets the HorizontalOffset used when animating from the Left or Right /// Gets or sets the HorizontalOffset used when animating from the Left or Right
@ -27,7 +30,12 @@ public class BetterSlideNavigationTransition : BaseTransitionInfo
/// Gets or sets the VerticalOffset used when animating from the Top or Bottom /// Gets or sets the VerticalOffset used when animating from the Top or Bottom
/// </summary> /// </summary>
public double FromVerticalOffset { get; set; } = 56; public double FromVerticalOffset { get; set; } = 56;
/// <summary>
/// Gets or sets the easing function applied to the slide transition.
/// </summary>
public Easing Easing { get; set; } = new SplineEasing(0.1, 0.9, 0.2, 1.0);
public override async void RunAnimation(Animatable ctrl, CancellationToken cancellationToken) public override async void RunAnimation(Animatable ctrl, CancellationToken cancellationToken)
{ {
double length = 0; double length = 0;
@ -52,24 +60,26 @@ public class BetterSlideNavigationTransition : BaseTransitionInfo
var animation = new Animation var animation = new Animation
{ {
Easing = new SplineEasing(0.1, 0.9, 0.2, 1.0), Easing = Easing,
Children = Children =
{ {
new KeyFrame new KeyFrame
{ {
Setters = Setters =
{ {
new Setter(isVertical ? TranslateTransform.YProperty : TranslateTransform.XProperty, length), new Setter(
isVertical
? TranslateTransform.YProperty
: TranslateTransform.XProperty,
length
),
new Setter(Visual.OpacityProperty, 0d) new Setter(Visual.OpacityProperty, 0d)
}, },
Cue = new Cue(0d) Cue = new Cue(0d)
}, },
new KeyFrame new KeyFrame
{ {
Setters= Setters = { new Setter(Visual.OpacityProperty, 1d) },
{
new Setter(Visual.OpacityProperty, 1d)
},
Cue = new Cue(0.05d) Cue = new Cue(0.05d)
}, },
new KeyFrame new KeyFrame
@ -77,7 +87,12 @@ public class BetterSlideNavigationTransition : BaseTransitionInfo
Setters = Setters =
{ {
new Setter(Visual.OpacityProperty, 1d), new Setter(Visual.OpacityProperty, 1d),
new Setter(isVertical ? TranslateTransform.YProperty : TranslateTransform.XProperty, 0.0) new Setter(
isVertical
? TranslateTransform.YProperty
: TranslateTransform.XProperty,
0.0
)
}, },
Cue = new Cue(1d) Cue = new Cue(1d)
} }
@ -93,4 +108,22 @@ public class BetterSlideNavigationTransition : BaseTransitionInfo
visual.Opacity = 1; visual.Opacity = 1;
} }
} }
public static BetterSlideNavigationTransition PageSlideFromLeft =>
new()
{
Duration = TimeSpan.FromMilliseconds(400),
Effect = SlideNavigationTransitionEffect.FromLeft,
FromHorizontalOffset = 150,
Easing = new SplineEasing(0.7, 0.4, 0.1, 0.2)
};
public static BetterSlideNavigationTransition PageSlideFromRight =>
new()
{
Duration = TimeSpan.FromMilliseconds(400),
Effect = SlideNavigationTransitionEffect.FromRight,
FromHorizontalOffset = 150,
Easing = new SplineEasing(0.7, 0.4, 0.1, 0.2)
};
} }

5
StabilityMatrix.Avalonia/ViewModels/Settings/MainSettingsViewModel.cs

@ -371,10 +371,7 @@ public partial class MainSettingsViewModel : PageViewModelBase
Dispatcher.UIThread.Post( Dispatcher.UIThread.Post(
() => () =>
settingsNavigationService.NavigateTo<InferenceSettingsViewModel>( settingsNavigationService.NavigateTo<InferenceSettingsViewModel>(
new BetterSlideNavigationTransition BetterSlideNavigationTransition.PageSlideFromRight
{
Effect = SlideNavigationTransitionEffect.FromRight
}
) )
); );
} }

5
StabilityMatrix.Avalonia/Views/SettingsPage.axaml.cs

@ -94,10 +94,7 @@ public partial class SettingsPage : UserControlBase
settingsNavigationService.NavigateTo( settingsNavigationService.NavigateTo(
viewModel, viewModel,
new BetterSlideNavigationTransition BetterSlideNavigationTransition.PageSlideFromLeft
{
Effect = SlideNavigationTransitionEffect.FromLeft
}
); );
} }
} }

Loading…
Cancel
Save