Skip to content

Commit 59e25a8

Browse files
committed
Added internal builder support for delay behavior option
1 parent 66c9743 commit 59e25a8

File tree

6 files changed

+49
-13
lines changed

6 files changed

+49
-13
lines changed

Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.KeyFrames.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ public AnimationBuilder NormalizedKeyFrames<T>(
253253
property,
254254
delay,
255255
duration ?? DefaultDuration,
256-
repeatOption ?? RepeatOption.Once);
256+
repeatOption ?? RepeatOption.Once,
257+
DefaultDelayBehavior);
257258

258259
build(builder);
259260

@@ -304,7 +305,8 @@ public AnimationBuilder NormalizedKeyFrames<T, TState>(
304305
property,
305306
delay,
306307
duration ?? DefaultDuration,
307-
repeatOption ?? RepeatOption.Once);
308+
repeatOption ?? RepeatOption.Once,
309+
DefaultDelayBehavior);
308310

309311
build(builder, state);
310312

@@ -346,7 +348,7 @@ public AnimationBuilder TimedKeyFrames<T>(
346348
{
347349
if (layer == FrameworkLayer.Composition)
348350
{
349-
TimedKeyFrameAnimationBuilder<T>.Composition builder = new(property, delay, repeat ?? RepeatOption.Once);
351+
TimedKeyFrameAnimationBuilder<T>.Composition builder = new(property, delay, repeat ?? RepeatOption.Once, DefaultDelayBehavior);
350352

351353
build(builder);
352354

@@ -387,7 +389,7 @@ public AnimationBuilder TimedKeyFrames<T, TState>(
387389
{
388390
if (layer == FrameworkLayer.Composition)
389391
{
390-
TimedKeyFrameAnimationBuilder<T>.Composition builder = new(property, delay, repeatOption ?? RepeatOption.Once);
392+
TimedKeyFrameAnimationBuilder<T>.Composition builder = new(property, delay, repeatOption ?? RepeatOption.Once, DefaultDelayBehavior);
391393

392394
build(builder, state);
393395

Microsoft.Toolkit.Uwp.UI.Animations/Builders/AnimationBuilder.PropertyBuilders.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public AnimationBuilder NormalizedKeyFrames(
8787
Property,
8888
delay,
8989
duration ?? DefaultDuration,
90-
repeatOption ?? RepeatOption.Once);
90+
repeatOption ?? RepeatOption.Once,
91+
DefaultDelayBehavior);
9192

9293
build(builder);
9394

@@ -108,7 +109,8 @@ public AnimationBuilder NormalizedKeyFrames<TState>(
108109
Property,
109110
delay,
110111
duration ?? DefaultDuration,
111-
repeatOption ?? RepeatOption.Once);
112+
repeatOption ?? RepeatOption.Once,
113+
DefaultDelayBehavior);
112114

113115
build(builder, state);
114116

@@ -123,7 +125,7 @@ public AnimationBuilder TimedKeyFrames(
123125
TimeSpan? delay,
124126
RepeatOption? repeatOption)
125127
{
126-
TimedKeyFrameAnimationBuilder<double>.Composition builder = new(Property, delay, repeatOption ?? RepeatOption.Once);
128+
TimedKeyFrameAnimationBuilder<double>.Composition builder = new(Property, delay, repeatOption ?? RepeatOption.Once, DefaultDelayBehavior);
127129

128130
build(builder);
129131

@@ -139,7 +141,7 @@ public AnimationBuilder TimedKeyFrames<TState>(
139141
TimeSpan? delay,
140142
RepeatOption? repeatOption)
141143
{
142-
TimedKeyFrameAnimationBuilder<double>.Composition builder = new(Property, delay, repeatOption ?? RepeatOption.Once);
144+
TimedKeyFrameAnimationBuilder<double>.Composition builder = new(Property, delay, repeatOption ?? RepeatOption.Once, DefaultDelayBehavior);
143145

144146
build(builder, state);
145147

Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Composition.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ internal abstract partial class NormalizedKeyFrameAnimationBuilder<T>
2424
/// <param name="delay">The optional initial delay for the animation.</param>
2525
/// <param name="duration">The animation duration.</param>
2626
/// <param name="repeat">The <see cref="RepeatOption"/> value for the animation</param>
27+
/// <param name="delayBehavior">The delay behavior mode to use.</param>
2728
/// <param name="keyFrames">The list of keyframes to use to build the animation.</param>
2829
/// <returns>A <see cref="CompositionAnimation"/> instance with the specified animation.</returns>
2930
public static CompositionAnimation GetAnimation<TKeyFrame>(
@@ -32,6 +33,7 @@ public static CompositionAnimation GetAnimation<TKeyFrame>(
3233
TimeSpan? delay,
3334
TimeSpan duration,
3435
RepeatOption repeat,
36+
AnimationDelayBehavior delayBehavior,
3537
ArraySegment<TKeyFrame> keyFrames)
3638
where TKeyFrame : struct, IKeyFrameInfo
3739
{
@@ -237,6 +239,7 @@ public static CompositionAnimation GetAnimation<TKeyFrame>(
237239

238240
if (delay.HasValue)
239241
{
242+
animation.DelayBehavior = delayBehavior;
240243
animation.DelayTime = delay!.Value;
241244
}
242245

@@ -251,13 +254,23 @@ public static CompositionAnimation GetAnimation<TKeyFrame>(
251254
/// </summary>
252255
public sealed class Composition : NormalizedKeyFrameAnimationBuilder<T>, AnimationBuilder.ICompositionAnimationFactory
253256
{
257+
/// <summary>
258+
/// The target delay behavior to use.
259+
/// </summary>
260+
private readonly AnimationDelayBehavior delayBehavior;
261+
254262
/// <summary>
255263
/// Initializes a new instance of the <see cref="NormalizedKeyFrameAnimationBuilder{T}.Composition"/> class.
256264
/// </summary>
257-
/// <inheritdoc cref="NormalizedKeyFrameAnimationBuilder{T}"/>
258-
public Composition(string property, TimeSpan? delay, TimeSpan duration, RepeatOption repeat)
265+
/// <param name="property">The target property to animate.</param>
266+
/// <param name="delay">The target delay for the animation.</param>
267+
/// <param name="duration">The target duration for the animation.</param>
268+
/// <param name="repeat">The repeat options for the animation.</param>
269+
/// <param name="delayBehavior">The delay behavior mode to use.</param>
270+
public Composition(string property, TimeSpan? delay, TimeSpan duration, RepeatOption repeat, AnimationDelayBehavior delayBehavior)
259271
: base(property, delay, duration, repeat)
260272
{
273+
this.delayBehavior = delayBehavior;
261274
}
262275

263276
/// <inheritdoc/>
@@ -283,6 +296,7 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo
283296
this.delay,
284297
this.duration,
285298
this.repeat,
299+
this.delayBehavior,
286300
this.keyFrames.GetArraySegment());
287301
}
288302
}

Microsoft.Toolkit.Uwp.UI.Animations/Builders/NormalizedKeyFrameAnimationBuilder{T}.Xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ public sealed class Xaml : NormalizedKeyFrameAnimationBuilder<T>, AnimationBuild
2020
/// <summary>
2121
/// Initializes a new instance of the <see cref="NormalizedKeyFrameAnimationBuilder{T}.Xaml"/> class.
2222
/// </summary>
23-
/// <inheritdoc cref="NormalizedKeyFrameAnimationBuilder{T}"/>
23+
/// <param name="property">The target property to animate.</param>
24+
/// <param name="delay">The target delay for the animation.</param>
25+
/// <param name="duration">The target duration for the animation.</param>
26+
/// <param name="repeat">The repeat options for the animation.</param>
2427
public Xaml(string property, TimeSpan? delay, TimeSpan duration, RepeatOption repeat)
2528
: base(property, delay, duration, repeat)
2629
{

Microsoft.Toolkit.Uwp.UI.Animations/Builders/TimedKeyFrameAnimationBuilder{T}.Composition.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,22 @@ internal abstract partial class TimedKeyFrameAnimationBuilder<T>
1919
/// </summary>
2020
public sealed class Composition : TimedKeyFrameAnimationBuilder<T>, AnimationBuilder.ICompositionAnimationFactory
2121
{
22+
/// <summary>
23+
/// The target delay behavior to use.
24+
/// </summary>
25+
private readonly AnimationDelayBehavior delayBehavior;
26+
2227
/// <summary>
2328
/// Initializes a new instance of the <see cref="TimedKeyFrameAnimationBuilder{T}.Composition"/> class.
2429
/// </summary>
25-
/// <inheritdoc cref="TimedKeyFrameAnimationBuilder{T}"/>
26-
public Composition(string property, TimeSpan? delay, RepeatOption repeat)
30+
/// <param name="property">The target property to animate.</param>
31+
/// <param name="delay">The target delay for the animation.</param>
32+
/// <param name="repeat">The repeat options for the animation.</param>
33+
/// <param name="delayBehavior">The delay behavior mode to use.</param>
34+
public Composition(string property, TimeSpan? delay, RepeatOption repeat, AnimationDelayBehavior delayBehavior)
2735
: base(property, delay, repeat)
2836
{
37+
this.delayBehavior = delayBehavior;
2938
}
3039

3140
/// <inheritdoc/>
@@ -56,6 +65,7 @@ public CompositionAnimation GetAnimation(CompositionObject targetHint, out Compo
5665
this.delay,
5766
duration,
5867
this.repeat,
68+
this.delayBehavior,
5969
keyFrames);
6070
}
6171
}

Microsoft.Toolkit.Uwp.UI.Animations/Extensions/AnimationExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public static class AnimationExtensions
3838
/// </summary>
3939
public const EasingMode DefaultEasingMode = EasingMode.EaseInOut;
4040

41+
/// <summary>
42+
/// The default <see cref="AnimationDelayBehavior"/> value used for animations (only applies to composition animations).
43+
/// </summary>
44+
public const AnimationDelayBehavior DefaultDelayBehavior = AnimationDelayBehavior.SetInitialValueBeforeDelay;
45+
4146
/// <summary>
4247
/// The reusable mapping of control points for easing curves for combinations of <see cref="EasingType"/> and <see cref="EasingMode"/> values.
4348
/// </summary>

0 commit comments

Comments
 (0)