From 5d43f8f69907191f4ec2a109f43d70dd32267479 Mon Sep 17 00:00:00 2001 From: artyom Date: Thu, 1 Oct 2020 20:23:43 +0300 Subject: [PATCH 1/4] Add a CompositeTransition --- .../Animation/CompositeTransition.cs | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/Avalonia.Visuals/Animation/CompositeTransition.cs diff --git a/src/Avalonia.Visuals/Animation/CompositeTransition.cs b/src/Avalonia.Visuals/Animation/CompositeTransition.cs new file mode 100644 index 0000000000..62ed9d5bc1 --- /dev/null +++ b/src/Avalonia.Visuals/Animation/CompositeTransition.cs @@ -0,0 +1,61 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Avalonia.Metadata; + +namespace Avalonia.Animation +{ + /// + /// Defines a composite transition that can be used to combine multiple transitions into one. + /// + /// + /// + /// Instantiate the in XAML and initialize the + /// property in order to have many animations triggered at once. + /// For example, you can combine and . + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// ]]> + /// + /// + /// + public class CompositeTransition : IPageTransition + { + /// + /// Gets or sets the transitions to be executed. Can be defined from XAML. + /// + [Content] + public List Transitions { get; set; } = new List(); + + /// + /// Starts the animation. + /// + /// + /// The control that is being transitioned away from. May be null. + /// + /// + /// The control that is being transitioned to. May be null. + /// + /// + /// Defines the direction of the transition. + /// + /// + /// A that tracks the progress of the animation. + /// + public Task Start(Visual from, Visual to, bool forward) + { + var transitionTasks = Transitions + .Select(transition => transition.Start(from, to, forward)) + .ToList(); + return Task.WhenAll(transitionTasks); + } + } +} From c3693a01cc1d6aa7cb692e92b46ed7298fcdfaae Mon Sep 17 00:00:00 2001 From: artyom Date: Fri, 2 Oct 2020 00:28:13 +0300 Subject: [PATCH 2/4] Ability to set easings --- ...ansition.cs => CompositePageTransition.cs} | 10 ++--- src/Avalonia.Visuals/Animation/CrossFade.cs | 29 ++++++++---- src/Avalonia.Visuals/Animation/PageSlide.cs | 44 +++++++++---------- 3 files changed, 47 insertions(+), 36 deletions(-) rename src/Avalonia.Visuals/Animation/{CompositeTransition.cs => CompositePageTransition.cs} (85%) diff --git a/src/Avalonia.Visuals/Animation/CompositeTransition.cs b/src/Avalonia.Visuals/Animation/CompositePageTransition.cs similarity index 85% rename from src/Avalonia.Visuals/Animation/CompositeTransition.cs rename to src/Avalonia.Visuals/Animation/CompositePageTransition.cs index 62ed9d5bc1..46bbb0bed2 100644 --- a/src/Avalonia.Visuals/Animation/CompositeTransition.cs +++ b/src/Avalonia.Visuals/Animation/CompositePageTransition.cs @@ -6,28 +6,28 @@ using Avalonia.Metadata; namespace Avalonia.Animation { /// - /// 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. /// /// /// - /// Instantiate the in XAML and initialize the + /// Instantiate the in XAML and initialize the /// property in order to have many animations triggered at once. /// For example, you can combine and . /// /// /// - /// + /// /// /// - /// + /// /// /// /// ]]> /// /// /// - public class CompositeTransition : IPageTransition + public class CompositePageTransition : IPageTransition { /// /// Gets or sets the transitions to be executed. Can be defined from XAML. diff --git a/src/Avalonia.Visuals/Animation/CrossFade.cs b/src/Avalonia.Visuals/Animation/CrossFade.cs index 640f401418..2ba9f6aeba 100644 --- a/src/Avalonia.Visuals/Animation/CrossFade.cs +++ b/src/Avalonia.Visuals/Animation/CrossFade.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Avalonia.Animation.Easings; using Avalonia.Styling; using Avalonia.VisualTree; @@ -74,14 +75,26 @@ namespace Avalonia.Animation /// public TimeSpan Duration { - get - { - return _fadeOutAnimation.Duration; - } - set - { - _fadeOutAnimation.Duration = _fadeInAnimation.Duration = value; - } + get => _fadeOutAnimation.Duration; + set => _fadeOutAnimation.Duration = _fadeInAnimation.Duration = value; + } + + /// + /// Gets or sets element entrance easing. + /// + public Easing EntranceEasing + { + get => _fadeInAnimation.Easing; + set => _fadeInAnimation.Easing = value; + } + + /// + /// Gets or sets element exit easing. + /// + public Easing ExitEasing + { + get => _fadeOutAnimation.Easing; + set => _fadeOutAnimation.Easing = value; } /// diff --git a/src/Avalonia.Visuals/Animation/PageSlide.cs b/src/Avalonia.Visuals/Animation/PageSlide.cs index 501c8c0ba4..b545385ad6 100644 --- a/src/Avalonia.Visuals/Animation/PageSlide.cs +++ b/src/Avalonia.Visuals/Animation/PageSlide.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Avalonia.Animation.Easings; using Avalonia.Media; using Avalonia.Styling; using Avalonia.VisualTree; @@ -48,6 +49,16 @@ namespace Avalonia.Animation /// Gets the duration of the animation. /// public SlideAxis Orientation { get; set; } + + /// + /// Gets or sets element entrance easing. + /// + public Easing EntranceEasing { get; set; } = new LinearEasing(); + + /// + /// Gets or sets element exit easing. + /// + public Easing ExitEasing { get; set; } = new LinearEasing(); /// /// Starts the animation. @@ -75,18 +86,12 @@ namespace Avalonia.Animation { var animation = new Animation { - Children = + Easing = ExitEasing, + Children = { new KeyFrame { - Setters = - { - new Setter - { - Property = translateProperty, - Value = 0d - } - }, + Setters = { new Setter { Property = translateProperty, Value = 0d } }, Cue = new Cue(0d) }, new KeyFrame @@ -100,10 +105,10 @@ namespace Avalonia.Animation } }, Cue = new Cue(1d) - } - } + } + }, + Duration = Duration }; - animation.Duration = Duration; tasks.Add(animation.RunAsync(from)); } @@ -112,9 +117,9 @@ namespace Avalonia.Animation to.IsVisible = true; var animation = new Animation { + Easing = EntranceEasing, Children = { - new KeyFrame { Setters = @@ -129,19 +134,12 @@ namespace Avalonia.Animation }, new KeyFrame { - Setters = - { - new Setter - { - Property = translateProperty, - Value = 0d - } - }, + Setters = { new Setter { Property = translateProperty, Value = 0d } }, Cue = new Cue(1d) } - } + }, + Duration = Duration }; - animation.Duration = Duration; tasks.Add(animation.RunAsync(to)); } From 4aecb6b99ae29c926bc715cfec84370cb4b0949c Mon Sep 17 00:00:00 2001 From: artyom Date: Fri, 2 Oct 2020 00:29:06 +0300 Subject: [PATCH 3/4] Better naming for easings --- src/Avalonia.Visuals/Animation/CrossFade.cs | 4 ++-- src/Avalonia.Visuals/Animation/PageSlide.cs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Avalonia.Visuals/Animation/CrossFade.cs b/src/Avalonia.Visuals/Animation/CrossFade.cs index 2ba9f6aeba..0615b854da 100644 --- a/src/Avalonia.Visuals/Animation/CrossFade.cs +++ b/src/Avalonia.Visuals/Animation/CrossFade.cs @@ -82,7 +82,7 @@ namespace Avalonia.Animation /// /// Gets or sets element entrance easing. /// - public Easing EntranceEasing + public Easing FadeInEasing { get => _fadeInAnimation.Easing; set => _fadeInAnimation.Easing = value; @@ -91,7 +91,7 @@ namespace Avalonia.Animation /// /// Gets or sets element exit easing. /// - public Easing ExitEasing + public Easing FadeOutEasing { get => _fadeOutAnimation.Easing; set => _fadeOutAnimation.Easing = value; diff --git a/src/Avalonia.Visuals/Animation/PageSlide.cs b/src/Avalonia.Visuals/Animation/PageSlide.cs index b545385ad6..dd5d598e12 100644 --- a/src/Avalonia.Visuals/Animation/PageSlide.cs +++ b/src/Avalonia.Visuals/Animation/PageSlide.cs @@ -53,12 +53,12 @@ namespace Avalonia.Animation /// /// Gets or sets element entrance easing. /// - public Easing EntranceEasing { get; set; } = new LinearEasing(); + public Easing SlideInEasing { get; set; } = new LinearEasing(); /// /// Gets or sets element exit easing. /// - public Easing ExitEasing { get; set; } = new LinearEasing(); + public Easing SlideOutEasing { get; set; } = new LinearEasing(); /// /// Starts the animation. @@ -86,7 +86,7 @@ namespace Avalonia.Animation { var animation = new Animation { - Easing = ExitEasing, + Easing = SlideOutEasing, Children = { new KeyFrame @@ -117,7 +117,7 @@ namespace Avalonia.Animation to.IsVisible = true; var animation = new Animation { - Easing = EntranceEasing, + Easing = SlideInEasing, Children = { new KeyFrame From 773055c78bb0bb19d0bb15ef330e51895ce3af78 Mon Sep 17 00:00:00 2001 From: "Artyom V. Gorchakov" Date: Mon, 5 Oct 2020 13:25:31 +0300 Subject: [PATCH 4/4] Transitions -> PageTransitions --- src/Avalonia.Visuals/Animation/CompositePageTransition.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Visuals/Animation/CompositePageTransition.cs b/src/Avalonia.Visuals/Animation/CompositePageTransition.cs index 46bbb0bed2..9489914c97 100644 --- a/src/Avalonia.Visuals/Animation/CompositePageTransition.cs +++ b/src/Avalonia.Visuals/Animation/CompositePageTransition.cs @@ -33,7 +33,7 @@ namespace Avalonia.Animation /// Gets or sets the transitions to be executed. Can be defined from XAML. /// [Content] - public List Transitions { get; set; } = new List(); + public List PageTransitions { get; set; } = new List(); /// /// Starts the animation. @@ -52,7 +52,7 @@ namespace Avalonia.Animation /// public Task Start(Visual from, Visual to, bool forward) { - var transitionTasks = Transitions + var transitionTasks = PageTransitions .Select(transition => transition.Start(from, to, forward)) .ToList(); return Task.WhenAll(transitionTasks);