From 8c4707bdbbc54f521fc1801dbcc089becbdee0de Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 26 Jun 2017 01:50:39 +0200 Subject: [PATCH] Improved the Dispose method for attached effects --- .../Effects/AttachedAnimatableCompositionEffect.cs | 14 +++++++++----- ...AttachedCompositeAnimatableCompositionEffect.cs | 12 +++++++----- .../Effects/AttachedStaticCompositionEffect.cs | 8 +++++++- UICompositionAnimations/Properties/AssemblyInfo.cs | 2 +- .../UICompositionAnimations.nuspec | 4 ++-- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/UICompositionAnimations/Behaviours/Effects/AttachedAnimatableCompositionEffect.cs b/UICompositionAnimations/Behaviours/Effects/AttachedAnimatableCompositionEffect.cs index e69d2f2..9e7b283 100644 --- a/UICompositionAnimations/Behaviours/Effects/AttachedAnimatableCompositionEffect.cs +++ b/UICompositionAnimations/Behaviours/Effects/AttachedAnimatableCompositionEffect.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Windows.UI.Composition; using Windows.UI.Xaml; @@ -25,11 +27,13 @@ internal AttachedAnimatableCompositionEffect( Parameters = parameters; } - /// - /// Executes the animation to the desired destination status and returns a task that completes when the animation ends - /// - /// The target animation status - /// The animation duration + /// + protected override IEnumerable GetAnimatedProperties() + { + return base.GetAnimatedProperties().Concat(new[] { Parameters.Property }); + } + + /// public override Task AnimateAsync(FixedAnimationType animationType, TimeSpan duration) { return EffectBrush.StartAnimationAsync(Parameters.Property, diff --git a/UICompositionAnimations/Behaviours/Effects/AttachedCompositeAnimatableCompositionEffect.cs b/UICompositionAnimations/Behaviours/Effects/AttachedCompositeAnimatableCompositionEffect.cs index a86ebb2..f0aa5be 100644 --- a/UICompositionAnimations/Behaviours/Effects/AttachedCompositeAnimatableCompositionEffect.cs +++ b/UICompositionAnimations/Behaviours/Effects/AttachedCompositeAnimatableCompositionEffect.cs @@ -28,11 +28,13 @@ internal AttachedCompositeAnimatableCompositionEffect( PropertiesAnimationValues = propertyValues; } - /// - /// Executes the animation to the desired destination status and returns a task that completes when the animation ends - /// - /// The target animation status - /// The animation duration + /// + protected override IEnumerable GetAnimatedProperties() + { + return base.GetAnimatedProperties().Concat(PropertiesAnimationValues.Keys); + } + + /// public override Task AnimateAsync(FixedAnimationType animationType, TimeSpan duration) { // Apply all the animations in parallel and wait for their completion diff --git a/UICompositionAnimations/Behaviours/Effects/AttachedStaticCompositionEffect.cs b/UICompositionAnimations/Behaviours/Effects/AttachedStaticCompositionEffect.cs index 028c656..ce6e6a5 100644 --- a/UICompositionAnimations/Behaviours/Effects/AttachedStaticCompositionEffect.cs +++ b/UICompositionAnimations/Behaviours/Effects/AttachedStaticCompositionEffect.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Windows.UI.Composition; using Windows.UI.Xaml; using Windows.UI.Xaml.Hosting; @@ -39,6 +40,11 @@ internal AttachedStaticCompositionEffect([NotNull] T element, [NotNull] SpriteVi if (disposeOnUnload) element.Unloaded += (s, e) => Dispose(); } + /// + /// Gets a sequence of all the animated properties for the current instance + /// + protected virtual IEnumerable GetAnimatedProperties() => new[] { "Size" }; + // Indicates whether or not the wrapped effect has already been disposed private bool _Disposed; @@ -51,7 +57,7 @@ public void Dispose() _Disposed = true; try { - Sprite.StopAnimation("Size"); + foreach (String property in GetAnimatedProperties()) Sprite.StopAnimation(property); ElementCompositionPreview.SetElementChildVisual(Element, null); EffectBrush.Dispose(); Sprite.Dispose(); diff --git a/UICompositionAnimations/Properties/AssemblyInfo.cs b/UICompositionAnimations/Properties/AssemblyInfo.cs index 0c2f2ee..11c7831 100644 --- a/UICompositionAnimations/Properties/AssemblyInfo.cs +++ b/UICompositionAnimations/Properties/AssemblyInfo.cs @@ -23,6 +23,6 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.5.2.0")] +[assembly: AssemblyVersion("2.5.3.0")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: ComVisible(false)] \ No newline at end of file diff --git a/UICompositionAnimations/UICompositionAnimations.nuspec b/UICompositionAnimations/UICompositionAnimations.nuspec index 124817b..9cfdf00 100644 --- a/UICompositionAnimations/UICompositionAnimations.nuspec +++ b/UICompositionAnimations/UICompositionAnimations.nuspec @@ -2,14 +2,14 @@ Sergio0694.UWP.UICompositionAnimations - 2.5.2.0 + 2.5.3.0 UICompositionAnimations A wrapper UWP PCL to work with Windows.UI.Composition and XAML animations, and Win2D effects Sergio Pedri Sergio Pedri https://github.com/Sergio0694/UICompositionAnimations false - Minor bug fixes + Minor improvements Copyright 2017 uwp composition animations xaml csharp windows winrt universal app ui win2d graphics