From 40557be1d6567b5dba7071bb2b9fbd5aeb861af0 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 31 Mar 2019 00:53:07 +0100 Subject: [PATCH 1/4] Minor code tweaks --- .../Animations/Abstract/AnimationBuilderBase.cs | 4 ++-- .../Animations/CompositionAnimationBuilder.cs | 4 ++-- UICompositionAnimations/Animations/XamlAnimationBuilder.cs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/UICompositionAnimations/Animations/Abstract/AnimationBuilderBase.cs b/UICompositionAnimations/Animations/Abstract/AnimationBuilderBase.cs index 967e546..ba8cb51 100644 --- a/UICompositionAnimations/Animations/Abstract/AnimationBuilderBase.cs +++ b/UICompositionAnimations/Animations/Abstract/AnimationBuilderBase.cs @@ -88,7 +88,7 @@ internal abstract class AnimationBuilderBase : IAnimationBuilder /// The target position /// The easing function to use for the translation animation [MustUseReturnValue, NotNull] - protected abstract IAnimationBuilder OnTranslation(Vector2? from, Vector2 to, Easing ease = Easing.Linear); + protected abstract IAnimationBuilder OnTranslation(Vector2? from, Vector2 to, Easing ease); /// public IAnimationBuilder Offset(Axis axis, double to, Easing ease = Easing.Linear) => OnOffset(axis, null, to, ease); @@ -119,7 +119,7 @@ internal abstract class AnimationBuilderBase : IAnimationBuilder /// The target position /// The easing function to use for the offset animation [MustUseReturnValue, NotNull] - protected abstract IAnimationBuilder OnOffset(Vector2? from, Vector2 to, Easing ease = Easing.Linear); + protected abstract IAnimationBuilder OnOffset(Vector2? from, Vector2 to, Easing ease); /// public IAnimationBuilder Scale(double to, Easing ease = Easing.Linear) => OnScale(null, to, ease); diff --git a/UICompositionAnimations/Animations/CompositionAnimationBuilder.cs b/UICompositionAnimations/Animations/CompositionAnimationBuilder.cs index dad2c4c..3eaf66c 100644 --- a/UICompositionAnimations/Animations/CompositionAnimationBuilder.cs +++ b/UICompositionAnimations/Animations/CompositionAnimationBuilder.cs @@ -35,13 +35,13 @@ public CompositionAnimationBuilder([NotNull] UIElement target) : base(target) protected override IAnimationBuilder OnTranslation(Axis axis, double? from, double to, Easing ease) => OnScalarAnimation($"Translation.{axis}", from, to, ease); /// - protected override IAnimationBuilder OnTranslation(Vector2? from, Vector2 to, Easing ease = Easing.Linear) => OnVector3Animation("Translation", from, to, ease); + protected override IAnimationBuilder OnTranslation(Vector2? from, Vector2 to, Easing ease) => OnVector3Animation("Translation", from, to, ease); /// protected override IAnimationBuilder OnOffset(Axis axis, double? from, double to, Easing ease) => OnScalarAnimation($"{nameof(Visual.Offset)}.{axis}", from, to, ease); /// - protected override IAnimationBuilder OnOffset(Vector2? from, Vector2 to, Easing ease = Easing.Linear) => OnVector3Animation(nameof(Visual.Offset), from, to, ease); + protected override IAnimationBuilder OnOffset(Vector2? from, Vector2 to, Easing ease) => OnVector3Animation(nameof(Visual.Offset), from, to, ease); /// protected override IAnimationBuilder OnScale(double? from, double to, Easing ease) diff --git a/UICompositionAnimations/Animations/XamlAnimationBuilder.cs b/UICompositionAnimations/Animations/XamlAnimationBuilder.cs index 1bb9bc9..5a97cd5 100644 --- a/UICompositionAnimations/Animations/XamlAnimationBuilder.cs +++ b/UICompositionAnimations/Animations/XamlAnimationBuilder.cs @@ -47,7 +47,7 @@ protected override IAnimationBuilder OnTranslation(Axis axis, double? from, doub } /// - protected override IAnimationBuilder OnTranslation(Vector2? from, Vector2 to, Easing ease = Easing.Linear) + protected override IAnimationBuilder OnTranslation(Vector2? from, Vector2 to, Easing ease) { AnimationFactories.Add(duration => TargetTransform.CreateDoubleAnimation(nameof(CompositeTransform.TranslateX), from?.X, to.X, duration, ease)); AnimationFactories.Add(duration => TargetTransform.CreateDoubleAnimation(nameof(CompositeTransform.TranslateY), from?.Y, to.Y, duration, ease)); @@ -57,7 +57,7 @@ protected override IAnimationBuilder OnTranslation(Vector2? from, Vector2 to, Ea protected override IAnimationBuilder OnOffset(Axis axis, double? from, double to, Easing ease) => throw new NotSupportedException("Can't animate the offset property from XAML"); - protected override IAnimationBuilder OnOffset(Vector2? from, Vector2 to, Easing ease = Easing.Linear) => throw new NotSupportedException("Can't animate the offset property from XAML"); + protected override IAnimationBuilder OnOffset(Vector2? from, Vector2 to, Easing ease) => throw new NotSupportedException("Can't animate the offset property from XAML"); /// protected override IAnimationBuilder OnScale(double? from, double to, Easing ease) From 5a43ab25caf1d728addadfe53b7925e9bbd3d348 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 31 Mar 2019 00:53:57 +0100 Subject: [PATCH 2/4] Fixed a typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0cfeb80..46e0fad 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ It is also possible to set an initial delay, and to wait for the animation to be ```C# await MyControl.Animation(FrameworkLayer.Xaml) .Opacity(0, 1, Easing.CircleEaseOut) - .Scale(1.2, 1, Easing.QuadratincEaseInOut) + .Scale(1.2, 1, Easing.QuadraticEaseInOut) .Duration(500) .Delay(250) .StartAsync(); From 50ab206892771670c1f0ff7b691045b6605b897c Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 13 Jun 2019 15:04:21 +0200 Subject: [PATCH 3/4] Added more annotations, new To extension --- .../Extensions/EnumExtensions.cs | 2 ++ .../Extensions/System/BaseExtensions.cs | 13 +++++++++++++ .../Windows.UI/Composition/CompositionExtensions.cs | 1 + .../Windows.UI/Xaml/DependencyObjectExtensions.cs | 4 ++-- .../Windows.UI/Xaml/FrameworkElementExtensions.cs | 1 + .../Windows.UI/Xaml/UIElementExtensions.cs | 5 +++-- 6 files changed, 22 insertions(+), 4 deletions(-) diff --git a/UICompositionAnimations/Extensions/EnumExtensions.cs b/UICompositionAnimations/Extensions/EnumExtensions.cs index 5af47e9..6856544 100644 --- a/UICompositionAnimations/Extensions/EnumExtensions.cs +++ b/UICompositionAnimations/Extensions/EnumExtensions.cs @@ -1,5 +1,6 @@ using System; using Windows.UI.Xaml.Media.Animation; +using JetBrains.Annotations; using UICompositionAnimations.Enums; namespace UICompositionAnimations.Extensions @@ -13,6 +14,7 @@ internal static class EnumExtensions /// Converts an easing value to the right easing function /// /// The desired easing function + [Pure, CanBeNull] public static EasingFunctionBase ToEasingFunction(this Easing ease) { switch (ease) diff --git a/UICompositionAnimations/Extensions/System/BaseExtensions.cs b/UICompositionAnimations/Extensions/System/BaseExtensions.cs index 96179ca..7e26dbe 100644 --- a/UICompositionAnimations/Extensions/System/BaseExtensions.cs +++ b/UICompositionAnimations/Extensions/System/BaseExtensions.cs @@ -11,10 +11,23 @@ public static class BaseExtensions /// /// Performs a direct cast on the given /// + /// The target type to return + /// The input to cast [MethodImpl(MethodImplOptions.AggressiveInlining)] [Pure] + [ContractAnnotation("null => null; notnull => notnull")] public static T To(this object o) => (T)o; + /// + /// Performs a safe cast to the specified type + /// + /// The target type to return, if possible + /// The input to try to convert + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [Pure] + [ContractAnnotation("null => null; notnull => canbenull")] + public static TTo As([CanBeNull] this object o) where TTo : class => o as TTo; + /// /// Converts an angle in radians to degrees /// diff --git a/UICompositionAnimations/Extensions/Windows.UI/Composition/CompositionExtensions.cs b/UICompositionAnimations/Extensions/Windows.UI/Composition/CompositionExtensions.cs index 34d2f11..194b8f4 100644 --- a/UICompositionAnimations/Extensions/Windows.UI/Composition/CompositionExtensions.cs +++ b/UICompositionAnimations/Extensions/Windows.UI/Composition/CompositionExtensions.cs @@ -184,6 +184,7 @@ public static void BindSize([NotNull] this CompositionObject source, [NotNull] U /// The source instance /// The resulting , if existing [MustUseReturnValue] + [ContractAnnotation("=> true, dispatcher: notnull; => false, dispatcher: null")] public static bool TryGetDispatcher([NotNull] this CompositionObject source, out CoreDispatcher dispatcher) { try diff --git a/UICompositionAnimations/Extensions/Windows.UI/Xaml/DependencyObjectExtensions.cs b/UICompositionAnimations/Extensions/Windows.UI/Xaml/DependencyObjectExtensions.cs index 4ef8761..dababa5 100644 --- a/UICompositionAnimations/Extensions/Windows.UI/Xaml/DependencyObjectExtensions.cs +++ b/UICompositionAnimations/Extensions/Windows.UI/Xaml/DependencyObjectExtensions.cs @@ -35,9 +35,9 @@ public static DoubleAnimation CreateDoubleAnimation( From = from, To = to, Duration = duration, - EnableDependentAnimation = enableDependecyAnimations + EnableDependentAnimation = enableDependecyAnimations, + EasingFunction = easing.ToEasingFunction() }; - if (easing != Easing.Linear) animation.EasingFunction = easing.ToEasingFunction(); Storyboard.SetTarget(animation, target); Storyboard.SetTargetProperty(animation, property); return animation; diff --git a/UICompositionAnimations/Extensions/Windows.UI/Xaml/FrameworkElementExtensions.cs b/UICompositionAnimations/Extensions/Windows.UI/Xaml/FrameworkElementExtensions.cs index 2f4b865..99360b6 100644 --- a/UICompositionAnimations/Extensions/Windows.UI/Xaml/FrameworkElementExtensions.cs +++ b/UICompositionAnimations/Extensions/Windows.UI/Xaml/FrameworkElementExtensions.cs @@ -45,6 +45,7 @@ public static void SetVisualCenterPoint([NotNull] this FrameworkElement element, /// The optional explicit blur radius /// The optional to use to create an alpha mask for the /// The that hosts the + [NotNull] public static SpriteVisual AttachVisualShadow( [NotNull] this FrameworkElement element, [NotNull] UIElement target, bool apply, diff --git a/UICompositionAnimations/Extensions/Windows.UI/Xaml/UIElementExtensions.cs b/UICompositionAnimations/Extensions/Windows.UI/Xaml/UIElementExtensions.cs index 18c60e2..f8bc69b 100644 --- a/UICompositionAnimations/Extensions/Windows.UI/Xaml/UIElementExtensions.cs +++ b/UICompositionAnimations/Extensions/Windows.UI/Xaml/UIElementExtensions.cs @@ -20,6 +20,7 @@ public static class UIElementExtensions /// Returns the Visual object for a given UIElement /// /// The source UIElement + [Pure, NotNull] public static Visual GetVisual([NotNull] this UIElement element) => ElementCompositionPreview.GetElementVisual(element); #region Animations @@ -110,8 +111,8 @@ public static void BeginVector3Animation( /// The desired type /// The target to modify /// If , a new instance will always be created and assigned to the - /// - public static T GetTransform(this UIElement element, bool reset = true) where T : Transform, new() + [MustUseReturnValue, NotNull] + public static T GetTransform([NotNull] this UIElement element, bool reset = true) where T : Transform, new() { // Return the existing transform object, if it exists if (element.RenderTransform is T && !reset) return element.RenderTransform.To(); From 4ceb64a3f85e19c063f4e1e7268ad8e396d7b202 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 13 Jun 2019 15:07:20 +0200 Subject: [PATCH 4/4] Updated NuGet info --- UICompositionAnimations/Properties/AssemblyInfo.cs | 6 +++--- UICompositionAnimations/UICompositionAnimations.nuspec | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/UICompositionAnimations/Properties/AssemblyInfo.cs b/UICompositionAnimations/Properties/AssemblyInfo.cs index 6d6795c..70401c0 100644 --- a/UICompositionAnimations/Properties/AssemblyInfo.cs +++ b/UICompositionAnimations/Properties/AssemblyInfo.cs @@ -23,8 +23,8 @@ // 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("4.0.2.0")] -[assembly: AssemblyFileVersion("4.0.2.0")] -[assembly: AssemblyInformationalVersion("4.0.2")] +[assembly: AssemblyVersion("4.0.3.0")] +[assembly: AssemblyFileVersion("4.0.3.0")] +[assembly: AssemblyInformationalVersion("4.0.3")] [assembly: ComVisible(false)] diff --git a/UICompositionAnimations/UICompositionAnimations.nuspec b/UICompositionAnimations/UICompositionAnimations.nuspec index f513e02..fbb8e66 100644 --- a/UICompositionAnimations/UICompositionAnimations.nuspec +++ b/UICompositionAnimations/UICompositionAnimations.nuspec @@ -2,7 +2,7 @@ UICompositionAnimations - 4.0.2 + 4.0.3 UICompositionAnimations A wrapper UWP PCL to work with Windows.UI.Composition and XAML animations, and Win2D effects Sergio Pedri @@ -10,7 +10,7 @@ https://github.com/Sergio0694/UICompositionAnimations GPL-3.0-only false - New size animation APIs, minor fixes + New extension APIs, more annotations Copyright © 2019 uwp composition animations xaml csharp windows winrt universal app ui win2d graphics