-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathRevealAnimation.cs
More file actions
93 lines (77 loc) · 2.66 KB
/
Copy pathRevealAnimation.cs
File metadata and controls
93 lines (77 loc) · 2.66 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System.Transactions;
using Trimble.Modus.Components.Popup.Animations.Base;
namespace Trimble.Modus.Components.Popup.Animations;
public class RevealAnimation : BaseAnimation
{
private double desiredHeight;
private double _defaultOpacity;
public bool HasBackgroundAnimation { get; set; } = true;
public RevealAnimation(double desiredHeight)
{
this.desiredHeight = desiredHeight;
}
public override void Preparing(View content, PopupPage page)
{
if (HasBackgroundAnimation)
{
_defaultOpacity = page.Opacity;
//page.HeightRequest = 0;
}
else if (content != null)
{
_defaultOpacity = content.Opacity;
content.Opacity = 1;
}
}
public override void Disposing(View content, PopupPage page)
{
if (HasBackgroundAnimation || content != null)
{
page.Opacity = _defaultOpacity;
}
}
public override Task Appearing(View content, PopupPage page)
{
if (HasBackgroundAnimation)
{
return RevealAnimations.HeightTo(content, desiredHeight);
}
if (content != null)
{
return RevealAnimations.HeightTo(content, desiredHeight);
}
return Task.CompletedTask;
}
public override Task Disappearing(View content, PopupPage page)
{
_defaultOpacity = page.Opacity;
if (double.IsNaN(_defaultOpacity))
_defaultOpacity = 1;
if (HasBackgroundAnimation)
{
return RevealAnimations.HeightTo(content, 0, 0);
}
if (content != null)
{
return RevealAnimations.HeightTo(content, 0, 0);
}
return Task.CompletedTask;
}
}
public static class RevealAnimations
{
public static async Task<bool> HeightTo(this View view, double height, uint duration = 250, Easing easing = null)
{
var tcs = new TaskCompletionSource<bool>();
var heightAnimation = new Animation(x => view.HeightRequest = x, view.Height, height);
heightAnimation.Commit(view, "HeightAnimation", 10, duration, easing, (finalValue, finished) => { tcs.SetResult(finished); });
return await tcs.Task;
}
public static async Task<bool> WidthTo(this View view, double width, uint duration = 250, Easing easing = null)
{
var tcs = new TaskCompletionSource<bool>();
var heightAnimation = new Animation(x => view.WidthRequest = x, view.Height, width);
heightAnimation.Commit(view, "WidthAnimation", 10, duration, easing, (finalValue, finished) => { tcs.SetResult(finished); });
return await tcs.Task;
}
}