Skip to content

Commit 59d0b12

Browse files
committed
Expanded delay behavior option to keyframe helpers
1 parent 59e25a8 commit 59d0b12

File tree

3 files changed

+73
-28
lines changed

3 files changed

+73
-28
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ public IPropertyAnimationBuilder<Vector2> Size()
236236
/// <param name="delay">The optional initial delay for the animation.</param>
237237
/// <param name="duration">The animation duration.</param>
238238
/// <param name="repeatOption">The repeat option for the animation (defaults to one iteration).</param>
239+
/// <param name="delayBehavior">The delay behavior to use (ignored if <paramref name="layer"/> is <see cref="FrameworkLayer.Xaml"/>).</param>
239240
/// <param name="layer">The target framework layer to animate.</param>
240241
/// <returns>The current <see cref="AnimationBuilder"/> instance.</returns>
241242
public AnimationBuilder NormalizedKeyFrames<T>(
@@ -244,6 +245,7 @@ public AnimationBuilder NormalizedKeyFrames<T>(
244245
TimeSpan? delay = null,
245246
TimeSpan? duration = null,
246247
RepeatOption? repeatOption = null,
248+
AnimationDelayBehavior? delayBehavior = null,
247249
FrameworkLayer layer = FrameworkLayer.Composition)
248250
where T : unmanaged
249251
{
@@ -254,7 +256,7 @@ public AnimationBuilder NormalizedKeyFrames<T>(
254256
delay,
255257
duration ?? DefaultDuration,
256258
repeatOption ?? RepeatOption.Once,
257-
DefaultDelayBehavior);
259+
delayBehavior ?? DefaultDelayBehavior);
258260

259261
build(builder);
260262

@@ -287,6 +289,7 @@ public AnimationBuilder NormalizedKeyFrames<T>(
287289
/// <param name="delay">The optional initial delay for the animation.</param>
288290
/// <param name="duration">The animation duration.</param>
289291
/// <param name="repeatOption">The repeat option for the animation (defaults to one iteration).</param>
292+
/// <param name="delayBehavior">The delay behavior to use (ignored if <paramref name="layer"/> is <see cref="FrameworkLayer.Xaml"/>).</param>
290293
/// <param name="layer">The target framework layer to animate.</param>
291294
/// <returns>The current <see cref="AnimationBuilder"/> instance.</returns>
292295
public AnimationBuilder NormalizedKeyFrames<T, TState>(
@@ -296,6 +299,7 @@ public AnimationBuilder NormalizedKeyFrames<T, TState>(
296299
TimeSpan? delay = null,
297300
TimeSpan? duration = null,
298301
RepeatOption? repeatOption = null,
302+
AnimationDelayBehavior? delayBehavior = null,
299303
FrameworkLayer layer = FrameworkLayer.Composition)
300304
where T : unmanaged
301305
{
@@ -306,7 +310,7 @@ public AnimationBuilder NormalizedKeyFrames<T, TState>(
306310
delay,
307311
duration ?? DefaultDuration,
308312
repeatOption ?? RepeatOption.Once,
309-
DefaultDelayBehavior);
313+
delayBehavior ?? DefaultDelayBehavior);
310314

311315
build(builder, state);
312316

@@ -336,19 +340,25 @@ public AnimationBuilder NormalizedKeyFrames<T, TState>(
336340
/// <param name="build">The callback to use to construct the custom animation.</param>
337341
/// <param name="delay">The optional initial delay for the animation.</param>
338342
/// <param name="repeat">The repeat option for the animation (defaults to one iteration).</param>
343+
/// <param name="delayBehavior">The delay behavior to use (ignored if <paramref name="layer"/> is <see cref="FrameworkLayer.Xaml"/>).</param>
339344
/// <param name="layer">The target framework layer to animate.</param>
340345
/// <returns>The current <see cref="AnimationBuilder"/> instance.</returns>
341346
public AnimationBuilder TimedKeyFrames<T>(
342347
string property,
343348
Action<ITimedKeyFrameAnimationBuilder<T>> build,
344349
TimeSpan? delay = null,
345350
RepeatOption? repeat = null,
351+
AnimationDelayBehavior? delayBehavior = null,
346352
FrameworkLayer layer = FrameworkLayer.Composition)
347353
where T : unmanaged
348354
{
349355
if (layer == FrameworkLayer.Composition)
350356
{
351-
TimedKeyFrameAnimationBuilder<T>.Composition builder = new(property, delay, repeat ?? RepeatOption.Once, DefaultDelayBehavior);
357+
TimedKeyFrameAnimationBuilder<T>.Composition builder = new(
358+
property,
359+
delay,
360+
repeat ?? RepeatOption.Once,
361+
delayBehavior ?? DefaultDelayBehavior);
352362

353363
build(builder);
354364

@@ -376,6 +386,7 @@ public AnimationBuilder TimedKeyFrames<T>(
376386
/// <param name="build">The callback to use to construct the custom animation.</param>
377387
/// <param name="delay">The optional initial delay for the animation.</param>
378388
/// <param name="repeatOption">The repeat option for the animation (defaults to one iteration).</param>
389+
/// <param name="delayBehavior">The delay behavior to use (ignored if <paramref name="layer"/> is <see cref="FrameworkLayer.Xaml"/>).</param>
379390
/// <param name="layer">The target framework layer to animate.</param>
380391
/// <returns>The current <see cref="AnimationBuilder"/> instance.</returns>
381392
public AnimationBuilder TimedKeyFrames<T, TState>(
@@ -384,12 +395,17 @@ public AnimationBuilder TimedKeyFrames<T, TState>(
384395
Action<ITimedKeyFrameAnimationBuilder<T>, TState> build,
385396
TimeSpan? delay = null,
386397
RepeatOption? repeatOption = null,
398+
AnimationDelayBehavior? delayBehavior = null,
387399
FrameworkLayer layer = FrameworkLayer.Composition)
388400
where T : unmanaged
389401
{
390402
if (layer == FrameworkLayer.Composition)
391403
{
392-
TimedKeyFrameAnimationBuilder<T>.Composition builder = new(property, delay, repeatOption ?? RepeatOption.Once, DefaultDelayBehavior);
404+
TimedKeyFrameAnimationBuilder<T>.Composition builder = new(
405+
property,
406+
delay,
407+
repeatOption ?? RepeatOption.Once,
408+
delayBehavior ?? DefaultDelayBehavior);
393409

394410
build(builder, state);
395411

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

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ public AnimationBuilder NormalizedKeyFrames(
3232
Action<INormalizedKeyFrameAnimationBuilder<T>> build,
3333
TimeSpan? delay,
3434
TimeSpan? duration,
35-
RepeatOption? repeatOption)
35+
RepeatOption? repeatOption,
36+
AnimationDelayBehavior? delayBehavior)
3637
{
37-
return Builder.NormalizedKeyFrames(Property, build, delay, duration, repeatOption, Layer);
38+
return Builder.NormalizedKeyFrames(Property, build, delay, duration, repeatOption, delayBehavior, Layer);
3839
}
3940

4041
/// <inheritdoc/>
@@ -43,28 +44,31 @@ public AnimationBuilder NormalizedKeyFrames<TState>(
4344
Action<INormalizedKeyFrameAnimationBuilder<T>, TState> build,
4445
TimeSpan? delay,
4546
TimeSpan? duration,
46-
RepeatOption? repeatOption)
47+
RepeatOption? repeatOption,
48+
AnimationDelayBehavior? delayBehavior)
4749
{
48-
return Builder.NormalizedKeyFrames(Property, state, build, delay, duration, repeatOption, Layer);
50+
return Builder.NormalizedKeyFrames(Property, state, build, delay, duration, repeatOption, delayBehavior, Layer);
4951
}
5052

5153
/// <inheritdoc/>
5254
public AnimationBuilder TimedKeyFrames(
5355
Action<ITimedKeyFrameAnimationBuilder<T>> build,
5456
TimeSpan? delay,
55-
RepeatOption? repeatOption)
57+
RepeatOption? repeatOption,
58+
AnimationDelayBehavior? delayBehavior)
5659
{
57-
return Builder.TimedKeyFrames(Property, build, delay, repeatOption, Layer);
60+
return Builder.TimedKeyFrames(Property, build, delay, repeatOption, delayBehavior, Layer);
5861
}
5962

6063
/// <inheritdoc/>
6164
public AnimationBuilder TimedKeyFrames<TState>(
6265
TState state,
6366
Action<ITimedKeyFrameAnimationBuilder<T>, TState> build,
6467
TimeSpan? delay,
65-
RepeatOption? repeatOption)
68+
RepeatOption? repeatOption,
69+
AnimationDelayBehavior? delayBehavior)
6670
{
67-
return Builder.TimedKeyFrames(Property, state, build, delay, repeatOption, Layer);
71+
return Builder.TimedKeyFrames(Property, state, build, delay, repeatOption, delayBehavior, Layer);
6872
}
6973
}
7074

@@ -81,14 +85,15 @@ public AnimationBuilder NormalizedKeyFrames(
8185
Action<INormalizedKeyFrameAnimationBuilder<double>> build,
8286
TimeSpan? delay,
8387
TimeSpan? duration,
84-
RepeatOption? repeatOption)
88+
RepeatOption? repeatOption,
89+
AnimationDelayBehavior? delayBehavior)
8590
{
8691
NormalizedKeyFrameAnimationBuilder<double>.Composition builder = new(
8792
Property,
8893
delay,
8994
duration ?? DefaultDuration,
9095
repeatOption ?? RepeatOption.Once,
91-
DefaultDelayBehavior);
96+
delayBehavior ?? DefaultDelayBehavior);
9297

9398
build(builder);
9499

@@ -103,14 +108,15 @@ public AnimationBuilder NormalizedKeyFrames<TState>(
103108
Action<INormalizedKeyFrameAnimationBuilder<double>, TState> build,
104109
TimeSpan? delay,
105110
TimeSpan? duration,
106-
RepeatOption? repeatOption)
111+
RepeatOption? repeatOption,
112+
AnimationDelayBehavior? delayBehavior)
107113
{
108114
NormalizedKeyFrameAnimationBuilder<double>.Composition builder = new(
109115
Property,
110116
delay,
111117
duration ?? DefaultDuration,
112118
repeatOption ?? RepeatOption.Once,
113-
DefaultDelayBehavior);
119+
delayBehavior ?? DefaultDelayBehavior);
114120

115121
build(builder, state);
116122

@@ -123,9 +129,14 @@ public AnimationBuilder NormalizedKeyFrames<TState>(
123129
public AnimationBuilder TimedKeyFrames(
124130
Action<ITimedKeyFrameAnimationBuilder<double>> build,
125131
TimeSpan? delay,
126-
RepeatOption? repeatOption)
132+
RepeatOption? repeatOption,
133+
AnimationDelayBehavior? delayBehavior)
127134
{
128-
TimedKeyFrameAnimationBuilder<double>.Composition builder = new(Property, delay, repeatOption ?? RepeatOption.Once, DefaultDelayBehavior);
135+
TimedKeyFrameAnimationBuilder<double>.Composition builder = new(
136+
Property,
137+
delay,
138+
repeatOption ?? RepeatOption.Once,
139+
delayBehavior ?? DefaultDelayBehavior);
129140

130141
build(builder);
131142

@@ -139,9 +150,14 @@ public AnimationBuilder TimedKeyFrames<TState>(
139150
TState state,
140151
Action<ITimedKeyFrameAnimationBuilder<double>, TState> build,
141152
TimeSpan? delay,
142-
RepeatOption? repeatOption)
153+
RepeatOption? repeatOption,
154+
AnimationDelayBehavior? delayBehavior)
143155
{
144-
TimedKeyFrameAnimationBuilder<double>.Composition builder = new(Property, delay, repeatOption ?? RepeatOption.Once, DefaultDelayBehavior);
156+
TimedKeyFrameAnimationBuilder<double>.Composition builder = new(
157+
Property,
158+
delay,
159+
repeatOption ?? RepeatOption.Once,
160+
delayBehavior ?? DefaultDelayBehavior);
145161

146162
build(builder, state);
147163

@@ -182,7 +198,8 @@ public AnimationBuilder NormalizedKeyFrames(
182198
Action<INormalizedKeyFrameAnimationBuilder<double>> build,
183199
TimeSpan? delay,
184200
TimeSpan? duration,
185-
RepeatOption? repeatOption)
201+
RepeatOption? repeatOption,
202+
AnimationDelayBehavior? _)
186203
{
187204
NormalizedKeyFrameAnimationBuilder<double>.Xaml builder = new(
188205
Property,
@@ -203,7 +220,8 @@ public AnimationBuilder NormalizedKeyFrames<TState>(
203220
Action<INormalizedKeyFrameAnimationBuilder<double>, TState> build,
204221
TimeSpan? delay,
205222
TimeSpan? duration,
206-
RepeatOption? repeatOption)
223+
RepeatOption? repeatOption,
224+
AnimationDelayBehavior? _)
207225
{
208226
NormalizedKeyFrameAnimationBuilder<double>.Xaml builder = new(
209227
Property,
@@ -222,7 +240,8 @@ public AnimationBuilder NormalizedKeyFrames<TState>(
222240
public AnimationBuilder TimedKeyFrames(
223241
Action<ITimedKeyFrameAnimationBuilder<double>> build,
224242
TimeSpan? delay,
225-
RepeatOption? repeatOption)
243+
RepeatOption? repeatOption,
244+
AnimationDelayBehavior? _)
226245
{
227246
TimedKeyFrameAnimationBuilder<double>.Xaml builder = new(Property, delay, repeatOption ?? RepeatOption.Once);
228247

@@ -238,7 +257,8 @@ public AnimationBuilder TimedKeyFrames<TState>(
238257
TState state,
239258
Action<ITimedKeyFrameAnimationBuilder<double>, TState> build,
240259
TimeSpan? delay,
241-
RepeatOption? repeatOption)
260+
RepeatOption? repeatOption,
261+
AnimationDelayBehavior? _)
242262
{
243263
TimedKeyFrameAnimationBuilder<double>.Xaml builder = new(Property, delay, repeatOption ?? RepeatOption.Once);
244264

Microsoft.Toolkit.Uwp.UI.Animations/Builders/Interfaces/IPropertyAnimationBuilder{T}.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using Windows.UI.Composition;
67

78
namespace Microsoft.Toolkit.Uwp.UI.Animations
89
{
@@ -19,12 +20,14 @@ public interface IPropertyAnimationBuilder<in T>
1920
/// <param name="delay">The optional initial delay for the animation.</param>
2021
/// <param name="duration">The animation duration.</param>
2122
/// <param name="repeat">The repeat option for the animation (defaults to one iteration).</param>
23+
/// <param name="delayBehavior">The delay behavior to use (ignored if the animation is not being executed on the composition layer).</param>
2224
/// <returns>The current <see cref="AnimationBuilder"/> instance.</returns>
2325
AnimationBuilder NormalizedKeyFrames(
2426
Action<INormalizedKeyFrameAnimationBuilder<T>> build,
2527
TimeSpan? delay = null,
2628
TimeSpan? duration = null,
27-
RepeatOption? repeat = null);
29+
RepeatOption? repeat = null,
30+
AnimationDelayBehavior? delayBehavior = null);
2831

2932
/// <summary>
3033
/// Adds a custom animation based on normalized keyframes ot the current schedule.
@@ -35,25 +38,29 @@ AnimationBuilder NormalizedKeyFrames(
3538
/// <param name="delay">The optional initial delay for the animation.</param>
3639
/// <param name="duration">The animation duration.</param>
3740
/// <param name="repeat">The repeat option for the animation (defaults to one iteration).</param>
41+
/// <param name="delayBehavior">The delay behavior to use (ignored if the animation is not being executed on the composition layer).</param>
3842
/// <returns>The current <see cref="AnimationBuilder"/> instance.</returns>
3943
AnimationBuilder NormalizedKeyFrames<TState>(
4044
TState state,
4145
Action<INormalizedKeyFrameAnimationBuilder<T>, TState> build,
4246
TimeSpan? delay = null,
4347
TimeSpan? duration = null,
44-
RepeatOption? repeat = null);
48+
RepeatOption? repeat = null,
49+
AnimationDelayBehavior? delayBehavior = null);
4550

4651
/// <summary>
4752
/// Adds a custom animation based on timed keyframes to the current schedule.
4853
/// </summary>
4954
/// <param name="build">The callback to use to construct the custom animation.</param>
5055
/// <param name="delay">The optional initial delay for the animation.</param>
5156
/// <param name="repeat">The repeat option for the animation (defaults to one iteration).</param>
57+
/// <param name="delayBehavior">The delay behavior to use (ignored if the animation is not being executed on the composition layer).</param>
5258
/// <returns>The current <see cref="AnimationBuilder"/> instance.</returns>
5359
AnimationBuilder TimedKeyFrames(
5460
Action<ITimedKeyFrameAnimationBuilder<T>> build,
5561
TimeSpan? delay = null,
56-
RepeatOption? repeat = null);
62+
RepeatOption? repeat = null,
63+
AnimationDelayBehavior? delayBehavior = null);
5764

5865
/// <summary>
5966
/// Adds a custom animation based on timed keyframes to the current schedule.
@@ -63,11 +70,13 @@ AnimationBuilder TimedKeyFrames(
6370
/// <param name="build">The callback to use to construct the custom animation.</param>
6471
/// <param name="delay">The optional initial delay for the animation.</param>
6572
/// <param name="repeat">The repeat option for the animation (defaults to one iteration).</param>
73+
/// <param name="delayBehavior">The delay behavior to use (ignored if the animation is not being executed on the composition layer).</param>
6674
/// <returns>The current <see cref="AnimationBuilder"/> instance.</returns>
6775
AnimationBuilder TimedKeyFrames<TState>(
6876
TState state,
6977
Action<ITimedKeyFrameAnimationBuilder<T>, TState> build,
7078
TimeSpan? delay = null,
71-
RepeatOption? repeat = null);
79+
RepeatOption? repeat = null,
80+
AnimationDelayBehavior? delayBehavior = null);
7281
}
7382
}

0 commit comments

Comments
 (0)