From 71608cc36c56603c4859880e40757d84f3156613 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 5 Feb 2021 13:24:02 +0100 Subject: [PATCH 1/5] Renamed AnimationSet.Ended to Completed --- Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationSet.cs | 6 +++--- .../Animations/AnimationEndBehavior.cs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationSet.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationSet.cs index c2cefeb6a6e..d7ca8aeb358 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationSet.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationSet.cs @@ -34,7 +34,7 @@ public sealed class AnimationSet : DependencyObjectCollection /// /// Raised whenever the current animation ends. /// - public event EventHandler? Ended; + public event EventHandler? Completed; /// /// An interface representing a node in an instance. @@ -73,7 +73,7 @@ public async void Start() // Here we're using an async void method on purpose, in order to be able to await // the completion of the animation and rethrow exceptions. We can't just use the // synchronous AnimationBuilder.Start method here, as we also need to await for the - // animation to complete in either case in order to raise the Ended event when that + // animation to complete in either case in order to raise the Completed event when that // happens. So we add an async state machine here to work around this. await StartAsync(); } @@ -181,7 +181,7 @@ public async Task StartAsync(UIElement element, CancellationToken token) await builder.StartAsync(element, token); } - Ended?.Invoke(this, EventArgs.Empty); + Completed?.Invoke(this, EventArgs.Empty); } /// diff --git a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs index eb0a6442bd9..24a1a8df7bd 100644 --- a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs +++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs @@ -48,14 +48,14 @@ private void SetResolvedCollection(AnimationSet? animationCollection) if (this.animationCollection is not null) { - this.animationCollection.Ended -= AnimationCollection_Ended; + this.animationCollection.Completed -= AnimationCollection_Completed; } this.animationCollection = animationCollection; if (animationCollection is not null) { - animationCollection.Ended += AnimationCollection_Ended; + animationCollection.Completed += AnimationCollection_Completed; } } @@ -64,7 +64,7 @@ private void SetResolvedCollection(AnimationSet? animationCollection) /// /// The source instance. /// The arguments for the event (unused). - private void AnimationCollection_Ended(object sender, System.EventArgs e) + private void AnimationCollection_Completed(object sender, System.EventArgs e) { Interaction.ExecuteActions(sender, Actions, e); } From e013df4837b30ffd8b2e4af15c30f02a49c99897 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 5 Feb 2021 13:27:18 +0100 Subject: [PATCH 2/5] Removed unnecessary INode interface --- .../Xaml/AnimationSet.cs | 20 ++++++++++--------- .../Xaml/Interfaces/IActivity.cs | 2 +- .../Xaml/Interfaces/ITimeline.cs | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationSet.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationSet.cs index d7ca8aeb358..1fe865a500f 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationSet.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationSet.cs @@ -36,13 +36,6 @@ public sealed class AnimationSet : DependencyObjectCollection /// public event EventHandler? Completed; - /// - /// An interface representing a node in an instance. - /// - public interface INode - { - } - /// /// Gets or sets a value indicating whether top level animation nodes in this collection are invoked /// sequentially. This applies to both nodes (which will still trigger @@ -124,7 +117,7 @@ public async Task StartAsync(UIElement element, CancellationToken token) if (IsSequential) { - foreach (INode node in this) + foreach (object node in this) { if (node is ITimeline timeline) { @@ -151,6 +144,10 @@ public async Task StartAsync(UIElement element, CancellationToken token) break; } } + else + { + ThrowArgumentException(); + } // This should in theory only be necessary in the timeline branch, but doing this check // after running activities too help guard against 3rd party activities that might not @@ -165,7 +162,7 @@ public async Task StartAsync(UIElement element, CancellationToken token) { var builder = AnimationBuilder.Create(); - foreach (INode node in this) + foreach (object node in this) { switch (node) { @@ -175,6 +172,9 @@ public async Task StartAsync(UIElement element, CancellationToken token) case IActivity activity: _ = activity.InvokeAsync(element, token); break; + default: + ThrowArgumentException(); + break; } } @@ -182,6 +182,8 @@ public async Task StartAsync(UIElement element, CancellationToken token) } Completed?.Invoke(this, EventArgs.Empty); + + static void ThrowArgumentException() => throw new ArgumentException($"An animation set can only contain nodes implementing either ITimeline or IActivity"); } /// diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Interfaces/IActivity.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Interfaces/IActivity.cs index 7baa9a47d77..9237b843c85 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Interfaces/IActivity.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Interfaces/IActivity.cs @@ -11,7 +11,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations /// /// An interface representing a XAML model for a custom activity or action within an . /// - public interface IActivity : AnimationSet.INode + public interface IActivity { /// /// Invokes the current activity. diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Interfaces/ITimeline.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Interfaces/ITimeline.cs index 78635101acd..6f3ad7d93d7 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Interfaces/ITimeline.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Interfaces/ITimeline.cs @@ -10,7 +10,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Animations /// /// An interface representing a XAML model for a custom animation. /// - public interface ITimeline : AnimationSet.INode + public interface ITimeline { /// /// Appens the current animation to a target instance. From ba9d5591a0f15d53bc1b2de31693f2a32c78364f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 6 Feb 2021 13:07:36 +0100 Subject: [PATCH 3/5] Removed leftover files from before the rewrite --- .../Behaviors/Blur.cs | 42 ----- .../Behaviors/CompositionBehaviorBase.cs | 141 --------------- .../CompositionBehaviorBase.nongeneric.cs | 16 -- .../Behaviors/Fade.cs | 42 ----- .../Behaviors/Light.cs | 65 ------- .../Behaviors/Offset.cs | 66 ------- .../Behaviors/Rotate.cs | 81 --------- .../Behaviors/Saturation.cs | 61 ------- .../Behaviors/Scale.cs | 99 ---------- .../Effects/AnimationEffect.cs | 170 ------------------ .../Effects/Blur.cs | 50 ------ .../Effects/Saturation.cs | 48 ----- ...Microsoft.Toolkit.Uwp.UI.Animations.csproj | 16 -- 13 files changed, 897 deletions(-) delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Blur.cs delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/CompositionBehaviorBase.cs delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/CompositionBehaviorBase.nongeneric.cs delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Fade.cs delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Light.cs delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Offset.cs delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Rotate.cs delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Saturation.cs delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Scale.cs delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Effects/AnimationEffect.cs delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Effects/Blur.cs delete mode 100644 Microsoft.Toolkit.Uwp.UI.Animations/Effects/Saturation.cs diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Blur.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Blur.cs deleted file mode 100644 index 3a56da53c15..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Blur.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using Windows.UI.Xaml; - -namespace Microsoft.Toolkit.Uwp.UI.Animations.Behaviors -{ - /// - /// Performs an blur animation using composition. - /// - /// - /// Microsoft.Xaml.Interactivity.Behavior{Windows.UI.Xaml.UIElement} - /// - public class Blur : CompositionBehaviorBase - { - /// - /// The Blur value of the associated object - /// - public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(nameof(Value), typeof(double), typeof(Blur), new PropertyMetadata(0d, PropertyChangedCallback)); - - /// - /// Gets or sets the Blur. - /// - /// - /// The Blur. - /// - public double Value - { - get { return (double)GetValue(ValueProperty); } - set { SetValue(ValueProperty, value); } - } - - /// - /// Starts the animation. - /// - public override void StartAnimation() - { - AssociatedObject?.Blur(duration: Duration, delay: Delay, value: (float)Value, easingType: EasingType, easingMode: EasingMode)?.Start(); - } - } -} diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/CompositionBehaviorBase.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/CompositionBehaviorBase.cs deleted file mode 100644 index 3dd912d33a7..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/CompositionBehaviorBase.cs +++ /dev/null @@ -1,141 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using Microsoft.Toolkit.Uwp.UI.Behaviors; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Media.Animation; - -namespace Microsoft.Toolkit.Uwp.UI.Animations.Behaviors -{ - /// - /// A base class for all behaviors using composition.It contains some of the common properties to set on a visual. - /// - /// The type of the associated object. - /// - public abstract class CompositionBehaviorBase : BehaviorBase - where T : UIElement - { - /// - /// Called when the associated object has been loaded. - /// - protected override void OnAssociatedObjectLoaded() - { - base.OnAssociatedObjectLoaded(); - - if (AutomaticallyStart) - { - StartAnimation(); - } - } - - /// - /// The duration of the animation. - /// - public static readonly DependencyProperty DurationProperty = DependencyProperty.Register(nameof(Duration), typeof(double), typeof(CompositionBehaviorBase), new PropertyMetadata(1d, PropertyChangedCallback)); - - /// - /// The delay of the animation. - /// - public static readonly DependencyProperty DelayProperty = DependencyProperty.Register(nameof(Delay), typeof(double), typeof(CompositionBehaviorBase), new PropertyMetadata(0d, PropertyChangedCallback)); - - /// - /// The property sets if the animation should automatically start. - /// - public static readonly DependencyProperty AutomaticallyStartProperty = DependencyProperty.Register(nameof(AutomaticallyStart), typeof(bool), typeof(CompositionBehaviorBase), new PropertyMetadata(true, PropertyChangedCallback)); - - /// - /// The used to generate the easing function of the animation. - /// - public static readonly DependencyProperty EasingTypeProperty = DependencyProperty.Register(nameof(EasingType), typeof(EasingType), typeof(CompositionBehaviorBase), new PropertyMetadata(EasingType.Default, PropertyChangedCallback)); - - /// - /// The used to generate the easing function of the animation. - /// - public static readonly DependencyProperty EasingModeProperty = DependencyProperty.Register(nameof(EasingMode), typeof(EasingMode), typeof(CompositionBehaviorBase), new PropertyMetadata(EasingMode.EaseOut, PropertyChangedCallback)); - - /// - /// Gets or sets a value indicating whether [automatically start] on the animation is set. - /// - /// - /// true if [automatically start]; otherwise, false. - /// - public bool AutomaticallyStart - { - get { return (bool)GetValue(AutomaticallyStartProperty); } - set { SetValue(AutomaticallyStartProperty, value); } - } - - /// - /// Gets or sets the delay. - /// - /// - /// The delay. - /// - public double Delay - { - get { return (double)GetValue(DelayProperty); } - set { SetValue(DelayProperty, value); } - } - - /// - /// Gets or sets the duration. - /// - /// - /// The duration. - /// - public double Duration - { - get { return (double)GetValue(DurationProperty); } - set { SetValue(DurationProperty, value); } - } - - /// - /// Gets or sets the used to generate the easing function of the animation. - /// - /// - /// The easing function - /// - public EasingType EasingType - { - get { return (EasingType)GetValue(EasingTypeProperty); } - set { SetValue(EasingTypeProperty, value); } - } - - /// - /// Gets or sets the used to generate the easing function of the animation. - /// - /// - /// The easing mode - /// - public EasingMode EasingMode - { - get { return (EasingMode)GetValue(EasingModeProperty); } - set { SetValue(EasingModeProperty, value); } - } - - /// - /// Starts the animation. - /// - public abstract void StartAnimation(); - - /// - /// If any of the properties are changed then the animation is automatically started depending on the AutomaticallyStart property. - /// - /// The dependency object. - /// The instance containing the event data. - protected static void PropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) - { - var behavior = dependencyObject as CompositionBehaviorBase; - if (behavior == null) - { - return; - } - - if (behavior.AutomaticallyStart) - { - behavior.StartAnimation(); - } - } - } -} diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/CompositionBehaviorBase.nongeneric.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/CompositionBehaviorBase.nongeneric.cs deleted file mode 100644 index c68a8180bac..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/CompositionBehaviorBase.nongeneric.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using Windows.UI.Xaml; - -namespace Microsoft.Toolkit.Uwp.UI.Animations.Behaviors -{ - /// - /// Non-generic convenience implementation to provide backwards compatibility. - /// - /// - public abstract class CompositionBehaviorBase : CompositionBehaviorBase - { - } -} diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Fade.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Fade.cs deleted file mode 100644 index fe9d4bab165..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Fade.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using Windows.UI.Xaml; - -namespace Microsoft.Toolkit.Uwp.UI.Animations.Behaviors -{ - /// - /// Performs an fade animation using composition. - /// - /// - /// Microsoft.Xaml.Interactivity.Behavior{Windows.UI.Xaml.UIElement} - /// - public class Fade : CompositionBehaviorBase - { - /// - /// The Opacity value of the associated object - /// - public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(nameof(Value), typeof(double), typeof(Fade), new PropertyMetadata(1d, PropertyChangedCallback)); - - /// - /// Gets or sets the Opacity. - /// - /// - /// The Opacity. - /// - public double Value - { - get { return (double)GetValue(ValueProperty); } - set { SetValue(ValueProperty, value); } - } - - /// - /// Starts the animation. - /// - public override void StartAnimation() - { - AssociatedObject.Fade((float)Value, Duration, Delay, EasingType, EasingMode)?.Start(); - } - } -} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Light.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Light.cs deleted file mode 100644 index 556972c1dae..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Light.cs +++ /dev/null @@ -1,65 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using Windows.UI; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Media; - -namespace Microsoft.Toolkit.Uwp.UI.Animations.Behaviors -{ - /// - /// Applies a basic point light to a UIElement. You control the intensity by setting the distance of the light. - /// - /// - [Obsolete("The Light effect will be removed in a future major release. Please use XamlLight instead")] - - public class Light : CompositionBehaviorBase - { - /// - /// The Blur value of the associated object - /// - public static readonly DependencyProperty DistanceProperty = DependencyProperty.Register(nameof(Distance), typeof(double), typeof(Light), new PropertyMetadata(0d, PropertyChangedCallback)); - - /// - /// The Color of the spotlight no the associated object. - /// - public static readonly DependencyProperty ColorProperty = DependencyProperty.Register("Color", typeof(Brush), typeof(Light), new PropertyMetadata(new SolidColorBrush(Colors.White))); - - /// - /// Gets or sets the Blur. - /// - /// - /// The Blur. - /// - public double Distance - { - get { return (double)GetValue(DistanceProperty); } - set { SetValue(DistanceProperty, value); } - } - - /// - /// Gets or sets the color of the spotlight. - /// - public Brush Color - { - get { return (Brush)GetValue(ColorProperty); } - set { SetValue(ColorProperty, value); } - } - - /// - /// Starts the animation. - /// - public override void StartAnimation() - { - AssociatedObject?.Light( - duration: Duration, - delay: Delay, - easingType: EasingType, - easingMode: EasingMode, - distance: (float)Distance, - color: ((SolidColorBrush)Color).Color)?.Start(); - } - } -} diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Offset.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Offset.cs deleted file mode 100644 index 16e1e7d7c47..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Offset.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using Windows.UI.Xaml; - -namespace Microsoft.Toolkit.Uwp.UI.Animations.Behaviors -{ - /// - /// Performs an offset animation using composition. - /// - /// - /// - /// Microsoft.Xaml.Interactivity.Behavior{Windows.UI.Xaml.UIElement} - /// - public class Offset : CompositionBehaviorBase - { - /// - /// The Offset on the x axis of the associated object - /// - public static readonly DependencyProperty OffsetXProperty = DependencyProperty.Register(nameof(OffsetX), typeof(double), typeof(Offset), new PropertyMetadata(0d, PropertyChangedCallback)); - - /// - /// The Offset on the y axis of the associated object - /// - public static readonly DependencyProperty OffsetYProperty = DependencyProperty.Register(nameof(OffsetY), typeof(double), typeof(Offset), new PropertyMetadata(0d, PropertyChangedCallback)); - - /// - /// Gets or sets the Offset x. - /// - /// - /// The Offset x. - /// - public double OffsetX - { - get { return (double)GetValue(OffsetXProperty); } - set { SetValue(OffsetXProperty, value); } - } - - /// - /// Gets or sets the Offset y. - /// - /// - /// The Offset y. - /// - public double OffsetY - { - get { return (double)GetValue(OffsetYProperty); } - set { SetValue(OffsetYProperty, value); } - } - - /// - /// Starts the animation. - /// - public override void StartAnimation() - { - AssociatedObject.Offset( - duration: Duration, - delay: Delay, - easingType: EasingType, - easingMode: EasingMode, - offsetX: (float)OffsetX, - offsetY: (float)OffsetY)?.Start(); - } - } -} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Rotate.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Rotate.cs deleted file mode 100644 index d1117c791c0..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Rotate.cs +++ /dev/null @@ -1,81 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using Windows.UI.Xaml; - -namespace Microsoft.Toolkit.Uwp.UI.Animations.Behaviors -{ - /// - /// Performs a rotation animation using composition. - /// - public class Rotate : CompositionBehaviorBase - { - /// - /// The rotation of the associated object in degrees - /// - public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(nameof(Value), typeof(double), typeof(Rotate), new PropertyMetadata(0d, PropertyChangedCallback)); - - /// - /// The center (x axis) of rotation for associated object - /// - public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register(nameof(CenterX), typeof(double), typeof(Rotate), new PropertyMetadata(0d, PropertyChangedCallback)); - - /// - /// The center (y axis) of rotation for associated object - /// - public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register(nameof(CenterY), typeof(double), typeof(Rotate), new PropertyMetadata(0d, PropertyChangedCallback)); - - /// - /// Gets or sets the center point (x axis) of the associated object. - /// - /// - /// The center point (x axis) of the associated object. - /// - public double CenterX - { - get { return (double)GetValue(CenterXProperty); } - set { SetValue(CenterXProperty, value); } - } - - /// - /// Gets or sets the center point (y axis) of the associated object. - /// - /// - /// The center point (y axis) of the associated object. - /// - public double CenterY - { - get { return (double)GetValue(CenterYProperty); } - set { SetValue(CenterYProperty, value); } - } - - /// - /// Gets or sets the Rotation in degrees. - /// - /// - /// The Rotation of the associated object in degrees. - /// - public double Value - { - get { return (double)GetValue(ValueProperty); } - set { SetValue(ValueProperty, value); } - } - - /// - /// Starts the animation. - /// - public override void StartAnimation() - { - AssociatedObject.Rotate( - duration: Duration, - delay: Delay, - easingType: EasingType, - easingMode: EasingMode, - value: (float)Value, - centerX: (float)CenterX, - centerY: (float)CenterY)? - .Start(); - } - } -} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Saturation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Saturation.cs deleted file mode 100644 index 61e0050fcb0..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Saturation.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using Windows.UI.Xaml; - -namespace Microsoft.Toolkit.Uwp.UI.Animations.Behaviors -{ - /// - /// A behavior to allow Saturation changes to a UI Element. - /// - public class Saturation : CompositionBehaviorBase - { - /// - /// The Saturation value of the associated object - /// - public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(nameof(Value), typeof(double), typeof(Saturation), new PropertyMetadata(0d, PropertyChangedCallback)); - - /// - /// The _framework element - /// - private FrameworkElement _frameworkElement; - - /// - /// Gets or sets the Saturation. - /// - /// - /// The Saturation. - /// - public double Value - { - get { return (double)GetValue(ValueProperty); } - set { SetValue(ValueProperty, value); } - } - - /// - /// Starts the animation. - /// - public override void StartAnimation() - { - _frameworkElement?.Saturation( - duration: Duration, - delay: Delay, - easingType: EasingType, - easingMode: EasingMode, - value: (float)Value)?.StartAsync(); - } - - /// - /// Called after the behavior is attached to the . - /// - /// - /// Override this to hook up functionality to the - /// - protected override void OnAttached() - { - base.OnAttached(); - _frameworkElement = AssociatedObject as FrameworkElement; - } - } -} diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Scale.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Scale.cs deleted file mode 100644 index dc56e81a0e9..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Behaviors/Scale.cs +++ /dev/null @@ -1,99 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using Windows.UI.Xaml; - -namespace Microsoft.Toolkit.Uwp.UI.Animations.Behaviors -{ - /// - /// Performs a scale animation using composition. - /// - public class Scale : CompositionBehaviorBase - { - /// - /// The scale (x axis) of the associated object - /// - public static readonly DependencyProperty ScaleXProperty = DependencyProperty.Register(nameof(ScaleX), typeof(double), typeof(Scale), new PropertyMetadata(1d, PropertyChangedCallback)); - - /// - /// The scale (y axis) of the associated object - /// - public static readonly DependencyProperty ScaleYProperty = DependencyProperty.Register(nameof(ScaleY), typeof(double), typeof(Scale), new PropertyMetadata(1d, PropertyChangedCallback)); - - /// - /// The center (x axis) of scale for associated object - /// - public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register(nameof(CenterX), typeof(double), typeof(Scale), new PropertyMetadata(0d, PropertyChangedCallback)); - - /// - /// The center (y axis) of scale for associated object - /// - public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register(nameof(CenterY), typeof(double), typeof(Scale), new PropertyMetadata(0d, PropertyChangedCallback)); - - /// - /// Gets or sets the scale on the x axis. - /// - /// - /// The scale on the x axis. - /// - public double ScaleX - { - get { return (double)GetValue(ScaleXProperty); } - set { SetValue(ScaleXProperty, value); } - } - - /// - /// Gets or sets the scale on the y axis. - /// - /// - /// The scale on the y axis. - /// - public double ScaleY - { - get { return (double)GetValue(ScaleYProperty); } - set { SetValue(ScaleYProperty, value); } - } - - /// - /// Gets or sets the scale (x axis) of the associated object. - /// - /// - /// The scale (x axis) of the associated object. - /// - public double CenterX - { - get { return (double)GetValue(CenterXProperty); } - set { SetValue(CenterXProperty, value); } - } - - /// - /// Gets or sets the scale (y axis) of the associated object. - /// - /// - /// The scale (y axis) of the associated object. - /// - public double CenterY - { - get { return (double)GetValue(CenterYProperty); } - set { SetValue(CenterYProperty, value); } - } - - /// - /// Starts the animation. - /// - public override void StartAnimation() - { - AssociatedObject.Scale( - duration: Duration, - delay: Delay, - easingType: EasingType, - easingMode: EasingMode, - centerX: (float)CenterX, - centerY: (float)CenterY, - scaleX: (float)ScaleX, - scaleY: (float)ScaleY)? - .Start(); - } - } -} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Effects/AnimationEffect.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Effects/AnimationEffect.cs deleted file mode 100644 index 724e1e35fec..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Effects/AnimationEffect.cs +++ /dev/null @@ -1,170 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Numerics; -using Windows.UI.Composition; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Hosting; -using Windows.UI.Xaml.Media.Animation; - -namespace Microsoft.Toolkit.Uwp.UI.Animations.Effects -{ - /// - /// An abstract class that provides the mechanism to create - /// an effect using composition. - /// - public abstract class AnimationEffect - { - private static string[] _effectProperties; - - /// - /// Gets the name of the effect. - /// - /// - /// The name of the effect. - /// - public abstract string EffectName { get; } - - /// - /// Gets or sets the compositor. - /// - /// - /// The compositor. - /// - public Compositor Compositor { get; set; } - - /// - /// Gets or sets the effect brush. - /// - /// - /// The effect brush. - /// - public CompositionEffectBrush EffectBrush { get; set; } - - /// - /// Applies the effect. - /// - /// An array of strings of the effect properties to change. - public abstract string[] ApplyEffect(); - - /// - /// An animation which will apply the derived effect. - /// - /// The animation set. - /// The value. - /// The duration in milliseconds. - /// The delay in milliseconds. - /// The easing function to use - /// The easing mode to use - /// An animation set with the effect added to it. - public AnimationSet EffectAnimation( - AnimationSet animationSet, - double value = 0d, - double duration = 500d, - double delay = 0d, - EasingType easingType = EasingType.Default, - EasingMode easingMode = EasingMode.EaseOut) - { - if (animationSet == null) - { - return null; - } - - var visual = animationSet.Visual; - var associatedObject = animationSet.Element as FrameworkElement; - - if (associatedObject == null) - { - return animationSet; - } - - Compositor = visual?.Compositor; - - if (Compositor == null) - { - return null; - } - - // check to see if the visual already has an effect applied. - var spriteVisual = ElementCompositionPreview.GetElementChildVisual(associatedObject) as SpriteVisual; - EffectBrush = spriteVisual?.Brush as CompositionEffectBrush; - - if (EffectBrush == null || EffectBrush?.Comment != EffectName) - { - _effectProperties = ApplyEffect(); - EffectBrush.Comment = EffectName; - - var sprite = Compositor.CreateSpriteVisual(); - sprite.Brush = EffectBrush; - ElementCompositionPreview.SetElementChildVisual(associatedObject, sprite); - - sprite.Size = new Vector2((float)associatedObject.ActualWidth, (float)associatedObject.ActualHeight); - - associatedObject.SizeChanged += - (s, e) => - { - sprite.Size = new Vector2( - (float)associatedObject.ActualWidth, - (float)associatedObject.ActualHeight); - }; - } - - if (duration <= 0) - { - foreach (var effectProperty in _effectProperties) - { - animationSet.AddEffectDirectPropertyChange(EffectBrush, (float)value, effectProperty); - } - } - else - { - foreach (var effectProperty in _effectProperties) - { - var animation = Compositor.CreateScalarKeyFrameAnimation(); - animation.InsertKeyFrame(1f, (float)value, AnimationExtensions.GetCompositionEasingFunction(easingType, Compositor, easingMode)); - - animation.Duration = TimeSpan.FromMilliseconds(duration); - animation.DelayTime = TimeSpan.FromMilliseconds(delay); - - animationSet.AddCompositionEffectAnimation(EffectBrush, animation, effectProperty); - } - } - - // Saturation starts from 1 to 0, instead of 0 to 1 so this makes sure the - // the brush isn't removed from the UI element incorrectly. Completing on - // Saturation as it's reusing the same sprite visual. Removing the Sprite removes the effect. - if (EffectName != "Saturation" && value == 0) - { - animationSet.Completed += AnimationSet_Completed; - } - - return animationSet; - } - - /// - /// Handles the Completed event of the AnimationSet control. - /// When an animation is completed the brush is removed from the sprite. - /// - /// The source of the event. - /// The instance containing the event data. - private void AnimationSet_Completed(object sender, EventArgs e) - { - var animationSet = sender as AnimationSet; - - if (animationSet != null) - { - animationSet.Completed -= AnimationSet_Completed; - - var spriteVisual = ElementCompositionPreview.GetElementChildVisual(animationSet.Element) as SpriteVisual; - var brush = spriteVisual?.Brush as CompositionEffectBrush; - - if (brush != null && brush.Comment == EffectName) - { - spriteVisual.Brush = null; - } - } - } - } -} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Effects/Blur.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Effects/Blur.cs deleted file mode 100644 index aa60fd5e059..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Effects/Blur.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using Microsoft.Graphics.Canvas.Effects; -using Windows.UI.Composition; - -namespace Microsoft.Toolkit.Uwp.UI.Animations.Effects -{ - /// - /// An animation effect that applies blur. - /// - /// - public class Blur : AnimationEffect - { - /// - /// Gets the name of the effect. - /// - /// - /// The name of the effect. - /// - public override string EffectName { get; } = "Blur"; - - /// - /// Applies the effect. - /// - /// - /// An array of strings of the effect properties to change. - /// - public override string[] ApplyEffect() - { - var gaussianBlur = new GaussianBlurEffect - { - Name = EffectName, - BlurAmount = 0f, - Optimization = EffectOptimization.Balanced, - BorderMode = EffectBorderMode.Hard, - Source = new CompositionEffectSourceParameter("source") - }; - - var propertyToChange = $"{EffectName}.BlurAmount"; - var propertiesToAnimate = new[] { propertyToChange }; - - EffectBrush = Compositor.CreateEffectFactory(gaussianBlur, propertiesToAnimate).CreateBrush(); - EffectBrush.SetSourceParameter("source", Compositor.CreateBackdropBrush()); - - return propertiesToAnimate; - } - } -} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Effects/Saturation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Effects/Saturation.cs deleted file mode 100644 index 30289f925a3..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Effects/Saturation.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using Microsoft.Graphics.Canvas.Effects; -using Windows.UI.Composition; - -namespace Microsoft.Toolkit.Uwp.UI.Animations.Effects -{ - /// - /// An animation effect that applies saturation. - /// - /// - public class Saturation : AnimationEffect - { - /// - /// Gets the name of the effect. - /// - /// - /// The name of the effect. - /// - public override string EffectName { get; } = "Saturation"; - - /// - /// Applies the effect. - /// - /// - /// An array of strings of the effect properties to change. - /// - public override string[] ApplyEffect() - { - var saturationEffect = new SaturationEffect - { - Saturation = 1f, - Name = EffectName, - Source = new CompositionEffectSourceParameter("source") - }; - - var propertyToChange = $"{EffectName}.Saturation"; - var propertiesToAnimate = new[] { propertyToChange }; - - EffectBrush = Compositor.CreateEffectFactory(saturationEffect, propertiesToAnimate).CreateBrush(); - EffectBrush.SetSourceParameter("source", Compositor.CreateBackdropBrush()); - - return propertiesToAnimate; - } - } -} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj b/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj index 77c82601938..3bc4c0b8b6c 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Microsoft.Toolkit.Uwp.UI.Animations.csproj @@ -18,22 +18,6 @@ 9.0 - - - - - - - - - - - - - - - - From 749ccc7adcfa6ab99b617e09bd4a8ad18955d0d9 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 8 Feb 2021 20:29:51 +0100 Subject: [PATCH 4/5] Fixed wording in AnimationSet.Completed XML docs --- Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationSet.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationSet.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationSet.cs index 1fe865a500f..44a211cb0f0 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationSet.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/AnimationSet.cs @@ -32,7 +32,7 @@ public sealed class AnimationSet : DependencyObjectCollection public event EventHandler? Started; /// - /// Raised whenever the current animation ends. + /// Raised whenever the current animation completes. /// public event EventHandler? Completed; From 7b4acf3bf7cb6913267b345e73a75a5caaacb636 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 9 Feb 2021 18:38:56 +0100 Subject: [PATCH 5/5] Renamed AnimationSet trigger behaviors --- ...ionEndBehavior.cs => AnimationCompletedTriggerBehavior.cs} | 4 ++-- ...ionStartBehavior.cs => AnimationStartedTriggerBehavior.cs} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/{AnimationEndBehavior.cs => AnimationCompletedTriggerBehavior.cs} (94%) rename Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/{AnimationStartBehavior.cs => AnimationStartedTriggerBehavior.cs} (96%) diff --git a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationCompletedTriggerBehavior.cs similarity index 94% rename from Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs rename to Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationCompletedTriggerBehavior.cs index 24a1a8df7bd..86848be62f2 100644 --- a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationEndBehavior.cs +++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationCompletedTriggerBehavior.cs @@ -10,9 +10,9 @@ namespace Microsoft.Toolkit.Uwp.UI.Behaviors { /// - /// A custom that fires whenever a linked ends. + /// A custom that fires whenever a linked completes. /// - public sealed class AnimationEndBehavior : Trigger + public sealed class AnimationCompletedTriggerBehavior : Trigger { /// /// The current instance in use. diff --git a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationStartBehavior.cs b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationStartedTriggerBehavior.cs similarity index 96% rename from Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationStartBehavior.cs rename to Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationStartedTriggerBehavior.cs index 11c87b9cb52..a436fa21738 100644 --- a/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationStartBehavior.cs +++ b/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations/AnimationStartedTriggerBehavior.cs @@ -12,7 +12,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Behaviors /// /// A custom that fires whenever a linked starts. /// - public sealed class AnimationStartBehavior : Trigger + public sealed class AnimationStartedTriggerBehavior : Trigger { /// /// The current instance in use.