From 660691da49b246abf00b8588cf4c18f00cd90f58 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Fri, 7 Dec 2018 18:56:59 +0800 Subject: [PATCH] Make KeyFrame an AvaloniaObject and move the setters to a dedicated property. --- src/Avalonia.Animation/Animation.cs | 2 +- src/Avalonia.Animation/KeyFrame.cs | 15 +++-- src/Avalonia.Visuals/Animation/CrossFade.cs | 40 ++++++------ src/Avalonia.Visuals/Animation/PageSlide.cs | 63 ++++++++++--------- .../AnimationIterationTests.cs | 15 +++-- 5 files changed, 73 insertions(+), 62 deletions(-) diff --git a/src/Avalonia.Animation/Animation.cs b/src/Avalonia.Animation/Animation.cs index 0043749fc3..5cb648ba0e 100644 --- a/src/Avalonia.Animation/Animation.cs +++ b/src/Avalonia.Animation/Animation.cs @@ -113,7 +113,7 @@ namespace Avalonia.Animation foreach (var keyframe in Children) { - foreach (var setter in keyframe) + foreach (var setter in keyframe.Setters) { var handler = GetAnimatorType(setter.Property); diff --git a/src/Avalonia.Animation/KeyFrame.cs b/src/Avalonia.Animation/KeyFrame.cs index 44e39e042e..a6577505ee 100644 --- a/src/Avalonia.Animation/KeyFrame.cs +++ b/src/Avalonia.Animation/KeyFrame.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using Avalonia.Collections; +using Avalonia.Metadata; namespace Avalonia.Animation { @@ -17,7 +18,7 @@ namespace Avalonia.Animation /// Stores data regarding a specific key /// point and value in an animation. /// - public class KeyFrame : AvaloniaList + public class KeyFrame : AvaloniaObject { private TimeSpan _ktimeSpan; private Cue _kCue; @@ -26,13 +27,11 @@ namespace Avalonia.Animation { } - public KeyFrame(IEnumerable items) : base(items) - { - } - - public KeyFrame(params IAnimationSetter[] items) : base(items) - { - } + /// + /// Gets the setters of . + /// + [Content] + public AvaloniaList Setters { get; } = new AvaloniaList(); internal KeyFrameTimingMode TimingMode { get; private set; } diff --git a/src/Avalonia.Visuals/Animation/CrossFade.cs b/src/Avalonia.Visuals/Animation/CrossFade.cs index b07123e050..6b8cb8b755 100644 --- a/src/Avalonia.Visuals/Animation/CrossFade.cs +++ b/src/Avalonia.Visuals/Animation/CrossFade.cs @@ -33,36 +33,40 @@ namespace Avalonia.Animation { _fadeOutAnimation = new Animation { - Children = + Children = { - new KeyFrame - ( - new Setter - { - Property = Visual.OpacityProperty, - Value = 0d - } - ) + new KeyFrame() { + Setters = + { + new Setter + { + Property = Visual.OpacityProperty, + Value = 0d + } + }, Cue = new Cue(1d) } + } }; _fadeInAnimation = new Animation { - Children = + Children = { - new KeyFrame - ( - new Setter - { - Property = Visual.OpacityProperty, - Value = 0d - } - ) + new KeyFrame() { + Setters = + { + new Setter + { + Property = Visual.OpacityProperty, + Value = 0d + } + }, Cue = new Cue(0d) } + } }; _fadeOutAnimation.Duration = _fadeInAnimation.Duration = duration; diff --git a/src/Avalonia.Visuals/Animation/PageSlide.cs b/src/Avalonia.Visuals/Animation/PageSlide.cs index c1848d7daa..0aa85035ae 100644 --- a/src/Avalonia.Visuals/Animation/PageSlide.cs +++ b/src/Avalonia.Visuals/Animation/PageSlide.cs @@ -81,27 +81,29 @@ namespace Avalonia.Animation Children = { new KeyFrame - ( - new Setter + { + Setters = { - Property = translateProperty, + new Setter + { + Property = translateProperty, Value = 0d - } - ) - { + } + }, Cue = new Cue(0d) }, new KeyFrame - ( - new Setter - { - Property = translateProperty, - Value = forward ? -distance : distance - } - ) { + Setters = + { + new Setter + { + Property = translateProperty, + Value = forward ? -distance : distance + } + }, Cue = new Cue(1d) - } + } } }; animation.Duration = Duration; @@ -115,28 +117,31 @@ namespace Avalonia.Animation { Children = { + new KeyFrame - ( - new Setter - { - Property = translateProperty, - Value = forward ? distance : -distance - } - ) { + Setters = + { + new Setter + { + Property = translateProperty, + Value = forward ? distance : -distance + } + }, Cue = new Cue(0d) }, new KeyFrame - ( - new Setter - { - Property = translateProperty, - Value = 0d - } - ) { + Setters = + { + new Setter + { + Property = translateProperty, + Value = 0d + } + }, Cue = new Cue(1d) - }, + } } }; animation.Duration = Duration; diff --git a/tests/Avalonia.Animation.UnitTests/AnimationIterationTests.cs b/tests/Avalonia.Animation.UnitTests/AnimationIterationTests.cs index 9b59dd4cc9..7e0743a56f 100644 --- a/tests/Avalonia.Animation.UnitTests/AnimationIterationTests.cs +++ b/tests/Avalonia.Animation.UnitTests/AnimationIterationTests.cs @@ -18,17 +18,20 @@ namespace Avalonia.Animation.UnitTests { var keyframe1 = new KeyFrame() { - new Setter(Border.WidthProperty, 200d), + Setters = { + new Setter(Border.WidthProperty, 200d), + }, + Cue = new Cue(1d) }; - + var keyframe2 = new KeyFrame() { - new Setter(Border.WidthProperty, 100d), + Setters = { + new Setter(Border.WidthProperty, 100d), + }, + Cue = new Cue(0d) }; - keyframe1.Cue = new Cue(1d); - keyframe2.Cue = new Cue(0d); - var animation = new Animation() { Duration = TimeSpan.FromSeconds(3),