-
Notifications
You must be signed in to change notification settings - Fork 428
/
Copy pathBaseAnimation.shared.cs
67 lines (58 loc) · 2.29 KB
/
BaseAnimation.shared.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
namespace CommunityToolkit.Maui.Animations;
/// <summary>
/// Abstract class for animation types to inherit.
/// </summary>
/// <typeparam name="TAnimatable">The <see cref="VisualElement"/> that the behavior can be applied to</typeparam>
public abstract class BaseAnimation<TAnimatable> : BindableObject where TAnimatable : IAnimatable
{
readonly uint defaultLength;
/// <summary>
/// Backing BindableProperty for the <see cref="Length"/> property.
/// </summary>
public static readonly BindableProperty LengthProperty =
BindableProperty.Create(nameof(Length), typeof(uint), typeof(BaseAnimation<TAnimatable>), 250u,
BindingMode.OneWay, defaultValueCreator: bindable => ((BaseAnimation<TAnimatable>)bindable).defaultLength);
/// <summary>
/// Backing BindableProperty for the <see cref="Easing"/> property.
/// </summary>
public static readonly BindableProperty EasingProperty =
BindableProperty.Create(nameof(Easing), typeof(Easing), typeof(BaseAnimation<TAnimatable>), Easing.Linear, BindingMode.OneWay);
/// <summary>
/// Initialize BaseAnimation
/// </summary>
/// <param name="defaultLength">The default time, in milliseconds, over which to animate the transition</param>
protected BaseAnimation(uint defaultLength = 250u) => this.defaultLength = defaultLength;
/// <summary>
/// The time, in milliseconds, over which to animate the transition.
/// </summary>
public uint Length
{
get => (uint)GetValue(LengthProperty);
set => SetValue(LengthProperty, value);
}
/// <summary>
/// The easing function to use for the animation
/// </summary>
public Easing Easing
{
get => (Easing)GetValue(EasingProperty);
set => SetValue(EasingProperty, value);
}
/// <summary>
/// Performs the animation on the View
/// </summary>
/// <param name="view">The view to perform the animation on.</param>
/// <param name="token"> <see cref="CancellationToken"/>.</param>
public abstract Task Animate(TAnimatable view, CancellationToken token = default);
}
/// <inheritdoc/>
public abstract class BaseAnimation : BaseAnimation<VisualElement>
{
/// <summary>
/// Initialize BaseAnimation
/// </summary>
/// <param name="defaultLength">The default time, in milliseconds, over which to animate the transition</param>
protected BaseAnimation(uint defaultLength = 250u) : base(defaultLength)
{
}
}