From 59e25a8998aa27c2bb41f6345b075d1e3896d676 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 28 Feb 2021 19:27:47 +0100 Subject: [PATCH 1/4] Added internal builder support for delay behavior option --- .../Builders/AnimationBuilder.KeyFrames.cs | 10 ++++++---- .../AnimationBuilder.PropertyBuilders.cs | 10 ++++++---- ...dKeyFrameAnimationBuilder{T}.Composition.cs | 18 ++++++++++++++++-- ...rmalizedKeyFrameAnimationBuilder{T}.Xaml.cs | 5 ++++- ...dKeyFrameAnimationBuilder{T}.Composition.cs | 14 ++++++++++++-- .../Extensions/AnimationExtensions.cs | 5 +++++ 6 files changed, 49 insertions(+), 13 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.KeyFrames.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.KeyFrames.cs index e349a62c50c..79309f2e7c5 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.KeyFrames.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.KeyFrames.cs @@ -253,7 +253,8 @@ public AnimationBuilder NormalizedKeyFrames( property, delay, duration ?? DefaultDuration, - repeatOption ?? RepeatOption.Once); + repeatOption ?? RepeatOption.Once, + DefaultDelayBehavior); build(builder); @@ -304,7 +305,8 @@ public AnimationBuilder NormalizedKeyFrames( property, delay, duration ?? DefaultDuration, - repeatOption ?? RepeatOption.Once); + repeatOption ?? RepeatOption.Once, + DefaultDelayBehavior); build(builder, state); @@ -346,7 +348,7 @@ public AnimationBuilder TimedKeyFrames( { if (layer == FrameworkLayer.Composition) { - TimedKeyFrameAnimationBuilder.Composition builder = new(property, delay, repeat ?? RepeatOption.Once); + TimedKeyFrameAnimationBuilder.Composition builder = new(property, delay, repeat ?? RepeatOption.Once, DefaultDelayBehavior); build(builder); @@ -387,7 +389,7 @@ public AnimationBuilder TimedKeyFrames( { if (layer == FrameworkLayer.Composition) { - TimedKeyFrameAnimationBuilder.Composition builder = new(property, delay, repeatOption ?? RepeatOption.Once); + TimedKeyFrameAnimationBuilder.Composition builder = new(property, delay, repeatOption ?? RepeatOption.Once, DefaultDelayBehavior); build(builder, state); diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs index 9775b507c0e..e12087877fd 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs @@ -87,7 +87,8 @@ public AnimationBuilder NormalizedKeyFrames( Property, delay, duration ?? DefaultDuration, - repeatOption ?? RepeatOption.Once); + repeatOption ?? RepeatOption.Once, + DefaultDelayBehavior); build(builder); @@ -108,7 +109,8 @@ public AnimationBuilder NormalizedKeyFrames( Property, delay, duration ?? DefaultDuration, - repeatOption ?? RepeatOption.Once); + repeatOption ?? RepeatOption.Once, + DefaultDelayBehavior); build(builder, state); @@ -123,7 +125,7 @@ public AnimationBuilder TimedKeyFrames( TimeSpan? delay, RepeatOption? repeatOption) { - TimedKeyFrameAnimationBuilder.Composition builder = new(Property, delay, repeatOption ?? RepeatOption.Once); + TimedKeyFrameAnimationBuilder.Composition builder = new(Property, delay, repeatOption ?? RepeatOption.Once, DefaultDelayBehavior); build(builder); @@ -139,7 +141,7 @@ public AnimationBuilder TimedKeyFrames( TimeSpan? delay, RepeatOption? repeatOption) { - TimedKeyFrameAnimationBuilder.Composition builder = new(Property, delay, repeatOption ?? RepeatOption.Once); + TimedKeyFrameAnimationBuilder.Composition builder = new(Property, delay, repeatOption ?? RepeatOption.Once, DefaultDelayBehavior); build(builder, state); diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs index 718ee6781ae..5a4fb1e047f 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs @@ -24,6 +24,7 @@ internal abstract partial class NormalizedKeyFrameAnimationBuilder /// The optional initial delay for the animation. /// The animation duration. /// The value for the animation + /// The delay behavior mode to use. /// The list of keyframes to use to build the animation. /// A instance with the specified animation. public static CompositionAnimation GetAnimation( @@ -32,6 +33,7 @@ public static CompositionAnimation GetAnimation( TimeSpan? delay, TimeSpan duration, RepeatOption repeat, + AnimationDelayBehavior delayBehavior, ArraySegment keyFrames) where TKeyFrame : struct, IKeyFrameInfo { @@ -237,6 +239,7 @@ public static CompositionAnimation GetAnimation( if (delay.HasValue) { + animation.DelayBehavior = delayBehavior; animation.DelayTime = delay!.Value; } @@ -251,13 +254,23 @@ public static CompositionAnimation GetAnimation( /// public sealed class Composition : NormalizedKeyFrameAnimationBuilder, AnimationBuilder.ICompositionAnimationFactory { + /// + /// The target delay behavior to use. + /// + private readonly AnimationDelayBehavior delayBehavior; + /// /// Initializes a new instance of the class. /// - /// - public Composition(string property, TimeSpan? delay, TimeSpan duration, RepeatOption repeat) + /// The target property to animate. + /// The target delay for the animation. + /// The target duration for the animation. + /// The repeat options for the animation. + /// The delay behavior mode to use. + public Composition(string property, TimeSpan? delay, TimeSpan duration, RepeatOption repeat, AnimationDelayBehavior delayBehavior) : base(property, delay, duration, repeat) { + this.delayBehavior = delayBehavior; } /// @@ -283,6 +296,7 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo this.delay, this.duration, this.repeat, + this.delayBehavior, this.keyFrames.GetArraySegment()); } } diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs index a5727d42d0b..cc6285140d1 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs @@ -20,7 +20,10 @@ public sealed class Xaml : NormalizedKeyFrameAnimationBuilder, AnimationBuild /// /// Initializes a new instance of the class. /// - /// + /// The target property to animate. + /// The target delay for the animation. + /// The target duration for the animation. + /// The repeat options for the animation. public Xaml(string property, TimeSpan? delay, TimeSpan duration, RepeatOption repeat) : base(property, delay, duration, repeat) { diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs index 772aa7f90a7..62957589480 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs @@ -19,13 +19,22 @@ internal abstract partial class TimedKeyFrameAnimationBuilder /// public sealed class Composition : TimedKeyFrameAnimationBuilder, AnimationBuilder.ICompositionAnimationFactory { + /// + /// The target delay behavior to use. + /// + private readonly AnimationDelayBehavior delayBehavior; + /// /// Initializes a new instance of the class. /// - /// - public Composition(string property, TimeSpan? delay, RepeatOption repeat) + /// The target property to animate. + /// The target delay for the animation. + /// The repeat options for the animation. + /// The delay behavior mode to use. + public Composition(string property, TimeSpan? delay, RepeatOption repeat, AnimationDelayBehavior delayBehavior) : base(property, delay, repeat) { + this.delayBehavior = delayBehavior; } /// @@ -56,6 +65,7 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo this.delay, duration, this.repeat, + this.delayBehavior, keyFrames); } } diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs index ae4081f56f1..599f5419835 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs @@ -38,6 +38,11 @@ public static class AnimationExtensions /// public const EasingMode DefaultEasingMode = EasingMode.EaseInOut; + /// + /// The default value used for animations (only applies to composition animations). + /// + public const AnimationDelayBehavior DefaultDelayBehavior = AnimationDelayBehavior.SetInitialValueBeforeDelay; + /// /// The reusable mapping of control points for easing curves for combinations of and values. /// From 59d0b1297f69fbdb961e05fb5e16e380eb3d8c07 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 28 Feb 2021 19:38:07 +0100 Subject: [PATCH 2/4] Expanded delay behavior option to keyframe helpers --- .../Builders/AnimationBuilder.KeyFrames.cs | 24 ++++++-- .../AnimationBuilder.PropertyBuilders.cs | 60 ++++++++++++------- .../IPropertyAnimationBuilder{T}.cs | 17 ++++-- 3 files changed, 73 insertions(+), 28 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.KeyFrames.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.KeyFrames.cs index 79309f2e7c5..453c7e727d5 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.KeyFrames.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.KeyFrames.cs @@ -236,6 +236,7 @@ public IPropertyAnimationBuilder Size() /// The optional initial delay for the animation. /// The animation duration. /// The repeat option for the animation (defaults to one iteration). + /// The delay behavior to use (ignored if is ). /// The target framework layer to animate. /// The current instance. public AnimationBuilder NormalizedKeyFrames( @@ -244,6 +245,7 @@ public AnimationBuilder NormalizedKeyFrames( TimeSpan? delay = null, TimeSpan? duration = null, RepeatOption? repeatOption = null, + AnimationDelayBehavior? delayBehavior = null, FrameworkLayer layer = FrameworkLayer.Composition) where T : unmanaged { @@ -254,7 +256,7 @@ public AnimationBuilder NormalizedKeyFrames( delay, duration ?? DefaultDuration, repeatOption ?? RepeatOption.Once, - DefaultDelayBehavior); + delayBehavior ?? DefaultDelayBehavior); build(builder); @@ -287,6 +289,7 @@ public AnimationBuilder NormalizedKeyFrames( /// The optional initial delay for the animation. /// The animation duration. /// The repeat option for the animation (defaults to one iteration). + /// The delay behavior to use (ignored if is ). /// The target framework layer to animate. /// The current instance. public AnimationBuilder NormalizedKeyFrames( @@ -296,6 +299,7 @@ public AnimationBuilder NormalizedKeyFrames( TimeSpan? delay = null, TimeSpan? duration = null, RepeatOption? repeatOption = null, + AnimationDelayBehavior? delayBehavior = null, FrameworkLayer layer = FrameworkLayer.Composition) where T : unmanaged { @@ -306,7 +310,7 @@ public AnimationBuilder NormalizedKeyFrames( delay, duration ?? DefaultDuration, repeatOption ?? RepeatOption.Once, - DefaultDelayBehavior); + delayBehavior ?? DefaultDelayBehavior); build(builder, state); @@ -336,6 +340,7 @@ public AnimationBuilder NormalizedKeyFrames( /// The callback to use to construct the custom animation. /// The optional initial delay for the animation. /// The repeat option for the animation (defaults to one iteration). + /// The delay behavior to use (ignored if is ). /// The target framework layer to animate. /// The current instance. public AnimationBuilder TimedKeyFrames( @@ -343,12 +348,17 @@ public AnimationBuilder TimedKeyFrames( Action> build, TimeSpan? delay = null, RepeatOption? repeat = null, + AnimationDelayBehavior? delayBehavior = null, FrameworkLayer layer = FrameworkLayer.Composition) where T : unmanaged { if (layer == FrameworkLayer.Composition) { - TimedKeyFrameAnimationBuilder.Composition builder = new(property, delay, repeat ?? RepeatOption.Once, DefaultDelayBehavior); + TimedKeyFrameAnimationBuilder.Composition builder = new( + property, + delay, + repeat ?? RepeatOption.Once, + delayBehavior ?? DefaultDelayBehavior); build(builder); @@ -376,6 +386,7 @@ public AnimationBuilder TimedKeyFrames( /// The callback to use to construct the custom animation. /// The optional initial delay for the animation. /// The repeat option for the animation (defaults to one iteration). + /// The delay behavior to use (ignored if is ). /// The target framework layer to animate. /// The current instance. public AnimationBuilder TimedKeyFrames( @@ -384,12 +395,17 @@ public AnimationBuilder TimedKeyFrames( Action, TState> build, TimeSpan? delay = null, RepeatOption? repeatOption = null, + AnimationDelayBehavior? delayBehavior = null, FrameworkLayer layer = FrameworkLayer.Composition) where T : unmanaged { if (layer == FrameworkLayer.Composition) { - TimedKeyFrameAnimationBuilder.Composition builder = new(property, delay, repeatOption ?? RepeatOption.Once, DefaultDelayBehavior); + TimedKeyFrameAnimationBuilder.Composition builder = new( + property, + delay, + repeatOption ?? RepeatOption.Once, + delayBehavior ?? DefaultDelayBehavior); build(builder, state); diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs index e12087877fd..5ad5cc9d7e5 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs @@ -32,9 +32,10 @@ public AnimationBuilder NormalizedKeyFrames( Action> build, TimeSpan? delay, TimeSpan? duration, - RepeatOption? repeatOption) + RepeatOption? repeatOption, + AnimationDelayBehavior? delayBehavior) { - return Builder.NormalizedKeyFrames(Property, build, delay, duration, repeatOption, Layer); + return Builder.NormalizedKeyFrames(Property, build, delay, duration, repeatOption, delayBehavior, Layer); } /// @@ -43,18 +44,20 @@ public AnimationBuilder NormalizedKeyFrames( Action, TState> build, TimeSpan? delay, TimeSpan? duration, - RepeatOption? repeatOption) + RepeatOption? repeatOption, + AnimationDelayBehavior? delayBehavior) { - return Builder.NormalizedKeyFrames(Property, state, build, delay, duration, repeatOption, Layer); + return Builder.NormalizedKeyFrames(Property, state, build, delay, duration, repeatOption, delayBehavior, Layer); } /// public AnimationBuilder TimedKeyFrames( Action> build, TimeSpan? delay, - RepeatOption? repeatOption) + RepeatOption? repeatOption, + AnimationDelayBehavior? delayBehavior) { - return Builder.TimedKeyFrames(Property, build, delay, repeatOption, Layer); + return Builder.TimedKeyFrames(Property, build, delay, repeatOption, delayBehavior, Layer); } /// @@ -62,9 +65,10 @@ public AnimationBuilder TimedKeyFrames( TState state, Action, TState> build, TimeSpan? delay, - RepeatOption? repeatOption) + RepeatOption? repeatOption, + AnimationDelayBehavior? delayBehavior) { - return Builder.TimedKeyFrames(Property, state, build, delay, repeatOption, Layer); + return Builder.TimedKeyFrames(Property, state, build, delay, repeatOption, delayBehavior, Layer); } } @@ -81,14 +85,15 @@ public AnimationBuilder NormalizedKeyFrames( Action> build, TimeSpan? delay, TimeSpan? duration, - RepeatOption? repeatOption) + RepeatOption? repeatOption, + AnimationDelayBehavior? delayBehavior) { NormalizedKeyFrameAnimationBuilder.Composition builder = new( Property, delay, duration ?? DefaultDuration, repeatOption ?? RepeatOption.Once, - DefaultDelayBehavior); + delayBehavior ?? DefaultDelayBehavior); build(builder); @@ -103,14 +108,15 @@ public AnimationBuilder NormalizedKeyFrames( Action, TState> build, TimeSpan? delay, TimeSpan? duration, - RepeatOption? repeatOption) + RepeatOption? repeatOption, + AnimationDelayBehavior? delayBehavior) { NormalizedKeyFrameAnimationBuilder.Composition builder = new( Property, delay, duration ?? DefaultDuration, repeatOption ?? RepeatOption.Once, - DefaultDelayBehavior); + delayBehavior ?? DefaultDelayBehavior); build(builder, state); @@ -123,9 +129,14 @@ public AnimationBuilder NormalizedKeyFrames( public AnimationBuilder TimedKeyFrames( Action> build, TimeSpan? delay, - RepeatOption? repeatOption) + RepeatOption? repeatOption, + AnimationDelayBehavior? delayBehavior) { - TimedKeyFrameAnimationBuilder.Composition builder = new(Property, delay, repeatOption ?? RepeatOption.Once, DefaultDelayBehavior); + TimedKeyFrameAnimationBuilder.Composition builder = new( + Property, + delay, + repeatOption ?? RepeatOption.Once, + delayBehavior ?? DefaultDelayBehavior); build(builder); @@ -139,9 +150,14 @@ public AnimationBuilder TimedKeyFrames( TState state, Action, TState> build, TimeSpan? delay, - RepeatOption? repeatOption) + RepeatOption? repeatOption, + AnimationDelayBehavior? delayBehavior) { - TimedKeyFrameAnimationBuilder.Composition builder = new(Property, delay, repeatOption ?? RepeatOption.Once, DefaultDelayBehavior); + TimedKeyFrameAnimationBuilder.Composition builder = new( + Property, + delay, + repeatOption ?? RepeatOption.Once, + delayBehavior ?? DefaultDelayBehavior); build(builder, state); @@ -182,7 +198,8 @@ public AnimationBuilder NormalizedKeyFrames( Action> build, TimeSpan? delay, TimeSpan? duration, - RepeatOption? repeatOption) + RepeatOption? repeatOption, + AnimationDelayBehavior? _) { NormalizedKeyFrameAnimationBuilder.Xaml builder = new( Property, @@ -203,7 +220,8 @@ public AnimationBuilder NormalizedKeyFrames( Action, TState> build, TimeSpan? delay, TimeSpan? duration, - RepeatOption? repeatOption) + RepeatOption? repeatOption, + AnimationDelayBehavior? _) { NormalizedKeyFrameAnimationBuilder.Xaml builder = new( Property, @@ -222,7 +240,8 @@ public AnimationBuilder NormalizedKeyFrames( public AnimationBuilder TimedKeyFrames( Action> build, TimeSpan? delay, - RepeatOption? repeatOption) + RepeatOption? repeatOption, + AnimationDelayBehavior? _) { TimedKeyFrameAnimationBuilder.Xaml builder = new(Property, delay, repeatOption ?? RepeatOption.Once); @@ -238,7 +257,8 @@ public AnimationBuilder TimedKeyFrames( TState state, Action, TState> build, TimeSpan? delay, - RepeatOption? repeatOption) + RepeatOption? repeatOption, + AnimationDelayBehavior? _) { TimedKeyFrameAnimationBuilder.Xaml builder = new(Property, delay, repeatOption ?? RepeatOption.Once); diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IPropertyAnimationBuilder{T}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IPropertyAnimationBuilder{T}.cs index 40d4989b5ba..1a2714bce2e 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IPropertyAnimationBuilder{T}.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IPropertyAnimationBuilder{T}.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using Windows.UI.Composition; namespace Microsoft.Toolkit.Uwp.UI.Animations { @@ -19,12 +20,14 @@ public interface IPropertyAnimationBuilder /// The optional initial delay for the animation. /// The animation duration. /// The repeat option for the animation (defaults to one iteration). + /// The delay behavior to use (ignored if the animation is not being executed on the composition layer). /// The current instance. AnimationBuilder NormalizedKeyFrames( Action> build, TimeSpan? delay = null, TimeSpan? duration = null, - RepeatOption? repeat = null); + RepeatOption? repeat = null, + AnimationDelayBehavior? delayBehavior = null); /// /// Adds a custom animation based on normalized keyframes ot the current schedule. @@ -35,13 +38,15 @@ AnimationBuilder NormalizedKeyFrames( /// The optional initial delay for the animation. /// The animation duration. /// The repeat option for the animation (defaults to one iteration). + /// The delay behavior to use (ignored if the animation is not being executed on the composition layer). /// The current instance. AnimationBuilder NormalizedKeyFrames( TState state, Action, TState> build, TimeSpan? delay = null, TimeSpan? duration = null, - RepeatOption? repeat = null); + RepeatOption? repeat = null, + AnimationDelayBehavior? delayBehavior = null); /// /// Adds a custom animation based on timed keyframes to the current schedule. @@ -49,11 +54,13 @@ AnimationBuilder NormalizedKeyFrames( /// The callback to use to construct the custom animation. /// The optional initial delay for the animation. /// The repeat option for the animation (defaults to one iteration). + /// The delay behavior to use (ignored if the animation is not being executed on the composition layer). /// The current instance. AnimationBuilder TimedKeyFrames( Action> build, TimeSpan? delay = null, - RepeatOption? repeat = null); + RepeatOption? repeat = null, + AnimationDelayBehavior? delayBehavior = null); /// /// Adds a custom animation based on timed keyframes to the current schedule. @@ -63,11 +70,13 @@ AnimationBuilder TimedKeyFrames( /// The callback to use to construct the custom animation. /// The optional initial delay for the animation. /// The repeat option for the animation (defaults to one iteration). + /// The delay behavior to use (ignored if the animation is not being executed on the composition layer). /// The current instance. AnimationBuilder TimedKeyFrames( TState state, Action, TState> build, TimeSpan? delay = null, - RepeatOption? repeat = null); + RepeatOption? repeat = null, + AnimationDelayBehavior? delayBehavior = null); } } From d97a7f674b95495abf9f04ceb2ff69f243d53bf7 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 28 Feb 2021 19:40:09 +0100 Subject: [PATCH 3/4] Added DelayBehavior option to XAML animation types --- .../Xaml/Abstract/Animation.cs | 21 +++++++++++++++++++ .../Abstract/Animation{TValue,TKeyFrame}.cs | 1 + .../CustomAnimation{TValue,TKeyFrame}.cs | 1 + .../ImplicitAnimation{TValue,TKeyFrame}.cs | 3 ++- ...fectAnimation{TEffect,TValue,TKeyFrame}.cs | 3 ++- 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation.cs index 6e1590697f4..210e3828d5a 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using Windows.UI.Composition; using Windows.UI.Xaml; using Windows.UI.Xaml.Media.Animation; @@ -103,6 +104,26 @@ public RepeatOption Repeat typeof(Animation), new PropertyMetadata(RepeatOption.Once)); + /// + /// Gets or sets the delay behavior for the animation. The default value is set to . + /// This value is applicable when the current animation is used as either an implicit composition animation, or an explicit composition animation. + /// If the current animation is instead running on the XAML layer (if used through ), it will be ignored. + /// + public AnimationDelayBehavior DelayBehavior + { + get => (AnimationDelayBehavior)GetValue(DelayBehaviorProperty); + set => SetValue(DelayBehaviorProperty, value); + } + + /// + /// Identifies the dependency property. + /// + public static readonly DependencyProperty DelayBehaviorProperty = DependencyProperty.Register( + nameof(DelayBehavior), + typeof(AnimationDelayBehavior), + typeof(Animation), + new PropertyMetadata(AnimationDelayBehavior.SetInitialValueBeforeDelay)); + /// public abstract AnimationBuilder AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint); } diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation{TValue,TKeyFrame}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation{TValue,TKeyFrame}.cs index ad90e43cb93..c2e933be801 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation{TValue,TKeyFrame}.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/Animation{TValue,TKeyFrame}.cs @@ -104,6 +104,7 @@ public override AnimationBuilder AppendToBuilder(AnimationBuilder builder, TimeS delay: Delay ?? delayHint ?? DefaultDelay, duration: Duration ?? durationHint ?? DefaultDuration, repeatOption: Repeat, + delayBehavior: DelayBehavior, build: static (b, s) => s.This.AppendToBuilder(b, s.EasingTypeHint, s.EasingModeHint)); } diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/CustomAnimation{TValue,TKeyFrame}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/CustomAnimation{TValue,TKeyFrame}.cs index 5f070e6eb6d..bd77f2a49e1 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/CustomAnimation{TValue,TKeyFrame}.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/CustomAnimation{TValue,TKeyFrame}.cs @@ -42,6 +42,7 @@ public override AnimationBuilder AppendToBuilder(AnimationBuilder builder, TimeS state: (this, easingTypeHint, easingModeHint), delay: Delay ?? delayHint ?? DefaultDelay, duration: Duration ?? durationHint ?? DefaultDuration, + delayBehavior: DelayBehavior, layer: Layer, build: static (b, s) => s.This.AppendToBuilder(b, s.EasingTypeHint, s.EasingModeHint)); } diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/ImplicitAnimation{TValue,TKeyFrame}.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/ImplicitAnimation{TValue,TKeyFrame}.cs index f98baa39fba..3f9ffc479ec 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/ImplicitAnimation{TValue,TKeyFrame}.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Abstract/ImplicitAnimation{TValue,TKeyFrame}.cs @@ -29,7 +29,8 @@ public CompositionAnimation GetAnimation(UIElement element, out string? target) ExplicitTarget, Delay ?? DefaultDelay, Duration ?? DefaultDuration, - Repeat); + Repeat, + DelayBehavior); var (to, from) = GetParsedValues(); diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Animations/Abstract/EffectAnimation{TEffect,TValue,TKeyFrame}.cs b/Microsoft.Toolkit.Uwp.UI.Media/Animations/Abstract/EffectAnimation{TEffect,TValue,TKeyFrame}.cs index faaa78dd171..7b9e3481129 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Animations/Abstract/EffectAnimation{TEffect,TValue,TKeyFrame}.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Animations/Abstract/EffectAnimation{TEffect,TValue,TKeyFrame}.cs @@ -70,7 +70,8 @@ static AnimationBuilder ThrowArgumentNullException() explicitTarget, Delay ?? delayHint ?? DefaultDelay, Duration ?? durationHint ?? DefaultDuration, - Repeat); + Repeat, + DelayBehavior); AppendToBuilder(keyFrameBuilder, easingTypeHint, easingModeHint); From e27c0d7657c5616e9db417a778bd7c05a675c28d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 28 Feb 2021 20:03:37 +0100 Subject: [PATCH 4/4] Added RepeatOption parameter to default animations --- .../Builders/AnimationBuilder.Default.cs | 139 ++++++++++++------ .../Builders/AnimationBuilder.Factories.cs | 62 ++++++-- .../Builders/AnimationBuilder.Setup.cs | 15 +- .../Xaml/Default/ClipAnimation.cs | 1 + 4 files changed, 161 insertions(+), 56 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs index 1dcbee0c547..de38a7cd375 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Default.cs @@ -25,6 +25,7 @@ public sealed partial class AnimationBuilder /// The optional starting value for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The current instance. @@ -35,10 +36,11 @@ public AnimationBuilder AnchorPoint( double? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode) { - AddCompositionAnimationFactory(Properties.Composition.AnchorPoint(axis), (float)to, (float?)from, delay, duration, easingType, easingMode); + AddCompositionAnimationFactory(Properties.Composition.AnchorPoint(axis), (float)to, (float?)from, delay, duration, repeat, easingType, easingMode); return this; } @@ -50,6 +52,7 @@ public AnimationBuilder AnchorPoint( /// The optional starting point for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The current instance. @@ -59,10 +62,11 @@ public AnimationBuilder AnchorPoint( Vector2? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode) { - AddCompositionAnimationFactory(nameof(Visual.AnchorPoint), to, from, delay, duration, easingType, easingMode); + AddCompositionAnimationFactory(nameof(Visual.AnchorPoint), to, from, delay, duration, repeat, easingType, easingMode); return this; } @@ -74,6 +78,7 @@ public AnimationBuilder AnchorPoint( /// The optional starting value for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The target framework layer to animate. @@ -83,17 +88,18 @@ public AnimationBuilder Opacity( double? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode, FrameworkLayer layer = FrameworkLayer.Composition) { if (layer == FrameworkLayer.Composition) { - AddCompositionAnimationFactory(nameof(Visual.Opacity), (float)to, (float?)from, delay, duration, easingType, easingMode); + AddCompositionAnimationFactory(nameof(Visual.Opacity), (float)to, (float?)from, delay, duration, repeat, easingType, easingMode); } else { - AddXamlAnimationFactory(nameof(UIElement.Opacity), to, from, delay, duration, easingType, easingMode); + AddXamlAnimationFactory(nameof(UIElement.Opacity), to, from, delay, duration, repeat, easingType, easingMode); } return this; @@ -107,6 +113,7 @@ public AnimationBuilder Opacity( /// The optional starting value for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The target framework layer to animate. @@ -117,17 +124,18 @@ public AnimationBuilder Translation( double? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode, FrameworkLayer layer = FrameworkLayer.Composition) { if (layer == FrameworkLayer.Composition) { - AddCompositionAnimationFactory(Properties.Composition.Translation(axis), (float)to, (float?)from, delay, duration, easingType, easingMode); + AddCompositionAnimationFactory(Properties.Composition.Translation(axis), (float)to, (float?)from, delay, duration, repeat, easingType, easingMode); } else { - AddXamlAnimationFactory(Properties.Xaml.Translation(axis), to, from, delay, duration, easingType, easingMode); + AddXamlAnimationFactory(Properties.Xaml.Translation(axis), to, from, delay, duration, repeat, easingType, easingMode); } return this; @@ -140,6 +148,7 @@ public AnimationBuilder Translation( /// The optional starting point for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The target framework layer to animate. @@ -149,18 +158,19 @@ public AnimationBuilder Translation( Vector2? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode, FrameworkLayer layer = FrameworkLayer.Composition) { if (layer == FrameworkLayer.Composition) { - AddCompositionAnimationFactory(Properties.Composition.TranslationXY(), to, from, delay, duration, easingType, easingMode); + AddCompositionAnimationFactory(Properties.Composition.TranslationXY(), to, from, delay, duration, repeat, easingType, easingMode); } else { - AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.TranslateX), to.X, from?.X, delay, duration, easingType, easingMode); - AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.TranslateY), to.Y, from?.Y, delay, duration, easingType, easingMode); + AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.TranslateX), to.X, from?.X, delay, duration, repeat, easingType, easingMode); + AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.TranslateY), to.Y, from?.Y, delay, duration, repeat, easingType, easingMode); } return this; @@ -173,6 +183,7 @@ public AnimationBuilder Translation( /// The optional starting point for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The current instance. @@ -182,10 +193,11 @@ public AnimationBuilder Translation( Vector3? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode) { - return AddCompositionAnimationFactory(Properties.Composition.Translation(), to, from, delay, duration, easingType, easingMode); + return AddCompositionAnimationFactory(Properties.Composition.Translation(), to, from, delay, duration, repeat, easingType, easingMode); } /// @@ -196,6 +208,7 @@ public AnimationBuilder Translation( /// The optional starting value for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The current instance. @@ -206,10 +219,11 @@ public AnimationBuilder Offset( double? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode) { - return AddCompositionAnimationFactory(Properties.Composition.Offset(axis), (float)to, (float?)from, delay, duration, easingType, easingMode); + return AddCompositionAnimationFactory(Properties.Composition.Offset(axis), (float)to, (float?)from, delay, duration, repeat, easingType, easingMode); } /// @@ -219,6 +233,7 @@ public AnimationBuilder Offset( /// The optional starting point for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The current instance. @@ -228,10 +243,11 @@ public AnimationBuilder Offset( Vector2? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode) { - AddCompositionAnimationFactory(Properties.Composition.OffsetXY(), to, from, delay, duration, easingType, easingMode); + AddCompositionAnimationFactory(Properties.Composition.OffsetXY(), to, from, delay, duration, repeat, easingType, easingMode); return this; } @@ -243,6 +259,7 @@ public AnimationBuilder Offset( /// The optional starting point for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The current instance. @@ -252,10 +269,11 @@ public AnimationBuilder Offset( Vector3? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode) { - return AddCompositionAnimationFactory(nameof(Visual.Offset), to, from, delay, duration, easingType, easingMode); + return AddCompositionAnimationFactory(nameof(Visual.Offset), to, from, delay, duration, repeat, easingType, easingMode); } /// @@ -265,6 +283,7 @@ public AnimationBuilder Offset( /// The optional starting value for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The target framework layer to animate. @@ -274,6 +293,7 @@ public AnimationBuilder Scale( double? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode, FrameworkLayer layer = FrameworkLayer.Composition) @@ -283,12 +303,12 @@ public AnimationBuilder Scale( Vector3? from3 = from is null ? null : new((float)(double)from); Vector3 to3 = new((float)to); - AddCompositionAnimationFactory(nameof(Visual.Scale), to3, from3, delay, duration, easingType, easingMode); + AddCompositionAnimationFactory(nameof(Visual.Scale), to3, from3, delay, duration, repeat, easingType, easingMode); } else { - AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleX), to, from, delay, duration, easingType, easingMode); - AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleY), to, from, delay, duration, easingType, easingMode); + AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleX), to, from, delay, duration, repeat, easingType, easingMode); + AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleY), to, from, delay, duration, repeat, easingType, easingMode); } return this; @@ -302,6 +322,7 @@ public AnimationBuilder Scale( /// The optional starting value for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The target framework layer to animate. @@ -312,17 +333,18 @@ public AnimationBuilder Scale( double? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode, FrameworkLayer layer = FrameworkLayer.Composition) { if (layer == FrameworkLayer.Composition) { - AddCompositionAnimationFactory(Properties.Composition.Scale(axis), (float)to, (float?)from, delay, duration, easingType, easingMode); + AddCompositionAnimationFactory(Properties.Composition.Scale(axis), (float)to, (float?)from, delay, duration, repeat, easingType, easingMode); } else { - AddXamlTransformDoubleAnimationFactory(Properties.Xaml.Scale(axis), to, from, delay, duration, easingType, easingMode); + AddXamlTransformDoubleAnimationFactory(Properties.Xaml.Scale(axis), to, from, delay, duration, repeat, easingType, easingMode); } return this; @@ -335,6 +357,7 @@ public AnimationBuilder Scale( /// The optional starting point for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The target framework layer to animate. @@ -344,18 +367,19 @@ public AnimationBuilder Scale( Vector2? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode, FrameworkLayer layer = FrameworkLayer.Composition) { if (layer == FrameworkLayer.Composition) { - AddCompositionAnimationFactory(Properties.Composition.ScaleXY(), to, from, delay, duration, easingType, easingMode); + AddCompositionAnimationFactory(Properties.Composition.ScaleXY(), to, from, delay, duration, repeat, easingType, easingMode); } else { - AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleX), to.X, from?.X, delay, duration, easingType, easingMode); - AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleY), to.Y, from?.Y, delay, duration, easingType, easingMode); + AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleX), to.X, from?.X, delay, duration, repeat, easingType, easingMode); + AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.ScaleY), to.Y, from?.Y, delay, duration, repeat, easingType, easingMode); } return this; @@ -368,6 +392,7 @@ public AnimationBuilder Scale( /// The optional starting point for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The current instance. @@ -377,10 +402,11 @@ public AnimationBuilder Scale( Vector3? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode) { - return AddCompositionAnimationFactory(nameof(Visual.Scale), to, from, delay, duration, easingType, easingMode); + return AddCompositionAnimationFactory(nameof(Visual.Scale), to, from, delay, duration, repeat, easingType, easingMode); } /// @@ -391,6 +417,7 @@ public AnimationBuilder Scale( /// The optional starting value for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The target framework layer to animate. @@ -401,17 +428,18 @@ public AnimationBuilder CenterPoint( double? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode, FrameworkLayer layer = FrameworkLayer.Composition) { if (layer == FrameworkLayer.Composition) { - AddCompositionAnimationFactory(Properties.Composition.CenterPoint(axis), (float)to, (float?)from, delay, duration, easingType, easingMode); + AddCompositionAnimationFactory(Properties.Composition.CenterPoint(axis), (float)to, (float?)from, delay, duration, repeat, easingType, easingMode); } else { - AddXamlTransformDoubleAnimationFactory(Properties.Xaml.CenterPoint(axis), to, from, delay, duration, easingType, easingMode); + AddXamlTransformDoubleAnimationFactory(Properties.Xaml.CenterPoint(axis), to, from, delay, duration, repeat, easingType, easingMode); } return this; @@ -424,6 +452,7 @@ public AnimationBuilder CenterPoint( /// The optional starting point for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The target framework layer to animate. @@ -433,18 +462,19 @@ public AnimationBuilder CenterPoint( Vector2? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode, FrameworkLayer layer = FrameworkLayer.Composition) { if (layer == FrameworkLayer.Composition) { - AddCompositionAnimationFactory(Properties.Composition.CenterPointXY(), to, from, delay, duration, easingType, easingMode); + AddCompositionAnimationFactory(Properties.Composition.CenterPointXY(), to, from, delay, duration, repeat, easingType, easingMode); } else { - AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.CenterX), to.X, from?.X, delay, duration, easingType, easingMode); - AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.CenterY), to.Y, from?.Y, delay, duration, easingType, easingMode); + AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.CenterX), to.X, from?.X, delay, duration, repeat, easingType, easingMode); + AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.CenterY), to.Y, from?.Y, delay, duration, repeat, easingType, easingMode); } return this; @@ -457,6 +487,7 @@ public AnimationBuilder CenterPoint( /// The optional starting point for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The current instance. @@ -466,10 +497,11 @@ public AnimationBuilder CenterPoint( Vector3? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode) { - return AddCompositionAnimationFactory(nameof(Visual.CenterPoint), to, from, delay, duration, easingType, easingMode); + return AddCompositionAnimationFactory(nameof(Visual.CenterPoint), to, from, delay, duration, repeat, easingType, easingMode); } /// @@ -479,6 +511,7 @@ public AnimationBuilder CenterPoint( /// The optional starting value for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The target framework layer to animate. @@ -488,20 +521,21 @@ public AnimationBuilder Rotation( double? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode, FrameworkLayer layer = FrameworkLayer.Composition) { if (layer == FrameworkLayer.Composition) { - AddCompositionAnimationFactory(nameof(Visual.RotationAngle), (float)to, (float?)from, delay, duration, easingType, easingMode); + AddCompositionAnimationFactory(nameof(Visual.RotationAngle), (float)to, (float?)from, delay, duration, repeat, easingType, easingMode); } else { double? fromDegrees = from * Math.PI / 180; double toDegrees = to * Math.PI / 180; - AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.Rotation), toDegrees, fromDegrees, delay, duration, easingType, easingMode); + AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.Rotation), toDegrees, fromDegrees, delay, duration, repeat, easingType, easingMode); } return this; @@ -514,6 +548,7 @@ public AnimationBuilder Rotation( /// The optional starting value for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The target framework layer to animate. @@ -523,17 +558,18 @@ public AnimationBuilder RotationInDegrees( double? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode, FrameworkLayer layer = FrameworkLayer.Composition) { if (layer == FrameworkLayer.Composition) { - AddCompositionAnimationFactory(nameof(Visual.RotationAngleInDegrees), (float)to, (float?)from, delay, duration, easingType, easingMode); + AddCompositionAnimationFactory(nameof(Visual.RotationAngleInDegrees), (float)to, (float?)from, delay, duration, repeat, easingType, easingMode); } else { - AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.Rotation), to, from, delay, duration, easingType, easingMode); + AddXamlTransformDoubleAnimationFactory(nameof(CompositeTransform.Rotation), to, from, delay, duration, repeat, easingType, easingMode); } return this; @@ -546,6 +582,7 @@ public AnimationBuilder RotationInDegrees( /// The optional starting value for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The current instance. @@ -555,10 +592,11 @@ public AnimationBuilder RotationAxis( Vector3? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode) { - return AddCompositionAnimationFactory(nameof(Visual.RotationAxis), to, from, delay, duration, easingType, easingMode); + return AddCompositionAnimationFactory(nameof(Visual.RotationAxis), to, from, delay, duration, repeat, easingType, easingMode); } /// @@ -568,6 +606,7 @@ public AnimationBuilder RotationAxis( /// The optional starting value for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The current instance. @@ -577,10 +616,11 @@ public AnimationBuilder Orientation( Quaternion? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode) { - return AddCompositionAnimationFactory(nameof(Visual.Orientation), to, from, delay, duration, easingType, easingMode); + return AddCompositionAnimationFactory(nameof(Visual.Orientation), to, from, delay, duration, repeat, easingType, easingMode); } /// @@ -590,6 +630,7 @@ public AnimationBuilder Orientation( /// The optional starting value for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The current instance. @@ -599,6 +640,7 @@ public AnimationBuilder Transform( Matrix4x4? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode) { @@ -623,9 +665,9 @@ public AnimationBuilder Transform( fromTranslation = translation3; } - Scale(toScale, fromScale, delay, duration, easingType, easingMode); - Orientation(toRotation, fromRotation, delay, duration, easingType, easingMode); - Translation(toTranslation, fromTranslation, delay, duration, easingType, easingMode); + Scale(toScale, fromScale, delay, duration, repeat, easingType, easingMode); + Orientation(toRotation, fromRotation, delay, duration, repeat, easingType, easingMode); + Translation(toTranslation, fromTranslation, delay, duration, repeat, easingType, easingMode); return this; @@ -641,6 +683,7 @@ public AnimationBuilder Transform( /// The optional starting value for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The current instance. @@ -651,6 +694,7 @@ public AnimationBuilder Clip( double? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode) { @@ -660,6 +704,7 @@ public AnimationBuilder Clip( (float?)from, delay ?? DefaultDelay, duration ?? DefaultDuration, + repeat ?? RepeatOption.Once, easingType, easingMode); @@ -675,6 +720,7 @@ public AnimationBuilder Clip( /// The optional starting value for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The current instance. @@ -684,6 +730,7 @@ public AnimationBuilder Clip( Thickness? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode) { @@ -693,6 +740,7 @@ public AnimationBuilder Clip( (float?)from?.Left, delay ?? DefaultDelay, duration ?? DefaultDuration, + repeat ?? RepeatOption.Once, easingType, easingMode)); @@ -702,6 +750,7 @@ public AnimationBuilder Clip( (float?)from?.Top, delay ?? DefaultDelay, duration ?? DefaultDuration, + repeat ?? RepeatOption.Once, easingType, easingMode)); @@ -711,6 +760,7 @@ public AnimationBuilder Clip( (float?)from?.Right, delay ?? DefaultDelay, duration ?? DefaultDuration, + repeat ?? RepeatOption.Once, easingType, easingMode)); @@ -720,6 +770,7 @@ public AnimationBuilder Clip( (float?)from?.Bottom, delay ?? DefaultDelay, duration ?? DefaultDuration, + repeat ?? RepeatOption.Once, easingType, easingMode)); @@ -734,6 +785,7 @@ public AnimationBuilder Clip( /// The optional starting value for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The target framework layer to animate. @@ -744,17 +796,18 @@ public AnimationBuilder Size( double? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode, FrameworkLayer layer = FrameworkLayer.Composition) { if (layer == FrameworkLayer.Composition) { - AddCompositionAnimationFactory(Properties.Composition.Size(axis), (float)to, (float?)from, delay, duration, easingType, easingMode); + AddCompositionAnimationFactory(Properties.Composition.Size(axis), (float)to, (float?)from, delay, duration, repeat, easingType, easingMode); } else { - AddXamlAnimationFactory(Properties.Xaml.Size(axis), to, from, delay, duration, easingType, easingMode); + AddXamlAnimationFactory(Properties.Xaml.Size(axis), to, from, delay, duration, repeat, easingType, easingMode); } return this; @@ -767,6 +820,7 @@ public AnimationBuilder Size( /// The optional starting point for the animation. /// The optional initial delay for the animation. /// The optional animation duration. + /// The optional repeat mode (defaults to once). /// The optional easing function type for the animation. /// The optional easing function mode for the animation. /// The target framework layer to animate. @@ -776,18 +830,19 @@ public AnimationBuilder Size( Vector2? from = null, TimeSpan? delay = null, TimeSpan? duration = null, + RepeatOption? repeat = null, EasingType easingType = DefaultEasingType, EasingMode easingMode = DefaultEasingMode, FrameworkLayer layer = FrameworkLayer.Composition) { if (layer == FrameworkLayer.Composition) { - AddCompositionAnimationFactory(Properties.Composition.Size(), to, from, delay, duration, easingType, easingMode); + AddCompositionAnimationFactory(Properties.Composition.Size(), to, from, delay, duration, repeat, easingType, easingMode); } else { - AddXamlAnimationFactory(nameof(FrameworkElement.Width), to.X, from?.X, delay, duration, easingType, easingMode); - AddXamlAnimationFactory(nameof(FrameworkElement.Height), to.Y, from?.Y, delay, duration, easingType, easingMode); + AddXamlAnimationFactory(nameof(FrameworkElement.Width), to.X, from?.X, delay, duration, repeat, easingType, easingMode); + AddXamlAnimationFactory(nameof(FrameworkElement.Height), to.Y, from?.Y, delay, duration, repeat, easingType, easingMode); } return this; diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Factories.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Factories.cs index 890420badd8..33264d04be9 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Factories.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Factories.cs @@ -61,6 +61,7 @@ private sealed record AnimationFactory( T? From, TimeSpan Delay, TimeSpan Duration, + RepeatOption Repeat, EasingType EasingType, EasingMode EasingMode) : ICompositionAnimationFactory, IXamlAnimationFactory @@ -70,6 +71,7 @@ private sealed record AnimationFactory( public CompositionAnimation GetAnimation(CompositionObject targetHint, out CompositionObject? target) { CompositionEasingFunction? easingFunction = targetHint.Compositor.TryCreateEasingFunction(EasingType, EasingMode); + (AnimationIterationBehavior iterationBehavior, int iterationCount) = Repeat.ToBehaviorAndCount(); target = null; @@ -80,7 +82,9 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo GetToAs(), GetFromAs(), Delay, - Duration); + Duration, + iterationBehavior: iterationBehavior, + iterationCount: iterationCount); } if (typeof(T) == typeof(float)) @@ -91,7 +95,9 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo GetFromAs(), Delay, Duration, - easingFunction); + easingFunction, + iterationBehavior: iterationBehavior, + iterationCount: iterationCount); } if (typeof(T) == typeof(double)) @@ -102,7 +108,9 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo (float?)GetFromAs(), Delay, Duration, - easingFunction); + easingFunction, + iterationBehavior: iterationBehavior, + iterationCount: iterationCount); } if (typeof(T) == typeof(Vector2)) @@ -113,7 +121,9 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo GetFromAs(), Delay, Duration, - easingFunction); + easingFunction, + iterationBehavior: iterationBehavior, + iterationCount: iterationCount); } if (typeof(T) == typeof(Vector3)) @@ -124,7 +134,9 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo GetFromAs(), Delay, Duration, - easingFunction); + easingFunction, + iterationBehavior: iterationBehavior, + iterationCount: iterationCount); } if (typeof(T) == typeof(Vector4)) @@ -135,7 +147,9 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo GetFromAs(), Delay, Duration, - easingFunction); + easingFunction, + iterationBehavior: iterationBehavior, + iterationCount: iterationCount); } if (typeof(T) == typeof(Color)) @@ -146,7 +160,9 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo GetFromAs(), Delay, Duration, - easingFunction); + easingFunction, + iterationBehavior: iterationBehavior, + iterationCount: iterationCount); } if (typeof(T) == typeof(Quaternion)) @@ -157,7 +173,9 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo GetFromAs(), Delay, Duration, - easingFunction); + easingFunction, + iterationBehavior: iterationBehavior, + iterationCount: iterationCount); } throw new InvalidOperationException("Invalid animation type"); @@ -177,6 +195,7 @@ public Timeline GetAnimation(DependencyObject targetHint) Delay, Duration, easingFunction, + Repeat.ToRepeatBehavior(), enableDependecyAnimations: true); } @@ -189,6 +208,7 @@ public Timeline GetAnimation(DependencyObject targetHint) Delay, Duration, easingFunction, + Repeat.ToRepeatBehavior(), enableDependecyAnimations: true); } @@ -201,6 +221,7 @@ public Timeline GetAnimation(DependencyObject targetHint) Delay, Duration, easingFunction, + Repeat.ToRepeatBehavior(), enableDependecyAnimations: true); } @@ -212,7 +233,8 @@ public Timeline GetAnimation(DependencyObject targetHint) GetFromAs(), Delay, Duration, - easingFunction); + easingFunction, + Repeat.ToRepeatBehavior()); } throw new InvalidOperationException("Invalid animation type"); @@ -287,6 +309,7 @@ private sealed record CompositionClipScalarAnimation( float? From, TimeSpan Delay, TimeSpan Duration, + RepeatOption Repeat, EasingType EasingType, EasingMode EasingMode) : ICompositionAnimationFactory @@ -297,7 +320,16 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo Visual visual = (Visual)targetHint; InsetClip clip = visual.Clip as InsetClip ?? (InsetClip)(visual.Clip = visual.Compositor.CreateInsetClip()); CompositionEasingFunction? easingFunction = clip.Compositor.TryCreateEasingFunction(EasingType, EasingMode); - ScalarKeyFrameAnimation animation = clip.Compositor.CreateScalarKeyFrameAnimation(Property, To, From, Delay, Duration, easingFunction); + (AnimationIterationBehavior iterationBehavior, int iterationCount) = Repeat.ToBehaviorAndCount(); + ScalarKeyFrameAnimation animation = clip.Compositor.CreateScalarKeyFrameAnimation( + Property, + To, + From, + Delay, + Duration, + easingFunction, + iterationBehavior: iterationBehavior, + iterationCount: iterationCount); target = clip; @@ -314,6 +346,7 @@ private sealed record XamlTransformDoubleAnimationFactory( double? From, TimeSpan Delay, TimeSpan Duration, + RepeatOption Repeat, EasingType EasingType, EasingMode EasingMode) : IXamlAnimationFactory @@ -328,7 +361,14 @@ public Timeline GetAnimation(DependencyObject targetHint) element.RenderTransform = transform = new CompositeTransform(); } - return transform.CreateDoubleAnimation(Property, To, From, Duration, Delay, EasingType.ToEasingFunction(EasingMode)); + return transform.CreateDoubleAnimation( + Property, + To, + From, + Duration, + Delay, + EasingType.ToEasingFunction(EasingMode), + Repeat.ToRepeatBehavior()); } } diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs index f095bab5736..ca581d31cb1 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.Setup.cs @@ -32,7 +32,8 @@ public sealed partial class AnimationBuilder /// The final value for the animation. /// The optional starting value for the animation. /// The optional initial delay for the animation. - /// The animation duration. + /// The optional animation duration. + /// The optional repeat option for the animation. /// The easing function for the animation. /// The easing mode for the animation. /// The current instance. @@ -42,6 +43,7 @@ private AnimationBuilder AddCompositionAnimationFactory( T? from, TimeSpan? delay, TimeSpan? duration, + RepeatOption? repeat, EasingType easingType, EasingMode easingMode) where T : unmanaged @@ -52,6 +54,7 @@ private AnimationBuilder AddCompositionAnimationFactory( from, delay ?? DefaultDelay, duration ?? DefaultDuration, + repeat ?? RepeatOption.Once, easingType, easingMode); @@ -68,7 +71,8 @@ private AnimationBuilder AddCompositionAnimationFactory( /// The final value for the animation. /// The optional starting value for the animation. /// The optional initial delay for the animation. - /// The animation duration. + /// The optional animation duration. + /// The optional repeat mode for the animation. /// The easing function for the animation. /// The easing mode for the animation. /// The current instance. @@ -78,6 +82,7 @@ private AnimationBuilder AddXamlAnimationFactory( T? from, TimeSpan? delay, TimeSpan? duration, + RepeatOption? repeat, EasingType easingType, EasingMode easingMode) where T : unmanaged @@ -88,6 +93,7 @@ private AnimationBuilder AddXamlAnimationFactory( from, delay ?? DefaultDelay, duration ?? DefaultDuration, + repeat ?? RepeatOption.Once, easingType, easingMode); @@ -103,7 +109,8 @@ private AnimationBuilder AddXamlAnimationFactory( /// The final value for the animation. /// The optional starting value for the animation. /// The optional initial delay for the animation. - /// The animation duration. + /// The optional animation duration. + /// The optional repeat mode for the animation. /// The easing function for the animation. /// The easing mode for the animation. /// The current instance. @@ -113,6 +120,7 @@ private AnimationBuilder AddXamlTransformDoubleAnimationFactory( double? from, TimeSpan? delay, TimeSpan? duration, + RepeatOption? repeat, EasingType easingType, EasingMode easingMode) { @@ -122,6 +130,7 @@ private AnimationBuilder AddXamlTransformDoubleAnimationFactory( from, delay ?? DefaultDelay, duration ?? DefaultDuration, + repeat ?? RepeatOption.Once, easingType, easingMode); diff --git a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ClipAnimation.cs b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ClipAnimation.cs index 2e340136c68..8d101103c98 100644 --- a/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ClipAnimation.cs +++ b/Microsoft.Toolkit.Uwp.UI.Animations/Xaml/Default/ClipAnimation.cs @@ -25,6 +25,7 @@ public override AnimationBuilder AppendToBuilder(AnimationBuilder builder, TimeS From, Delay ?? delayHint, Duration ?? durationHint, + Repeat, EasingType ?? easingTypeHint ?? DefaultEasingType, EasingMode ?? easingModeHint ?? DefaultEasingMode); }