-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathTransitions.cs
More file actions
110 lines (96 loc) · 3.74 KB
/
Transitions.cs
File metadata and controls
110 lines (96 loc) · 3.74 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using SimpleToolkit.SimpleShell.Transitions;
namespace Sample.SimpleShell;
public static class Transitions
{
public static PlatformSimpleShellTransition CustomPlatformTransition => new PlatformSimpleShellTransition
{
#if ANDROID
SwitchingEnterAnimation = static (args) => Resource.Animation.nav_default_enter_anim,
SwitchingLeaveAnimation = static (args) => Resource.Animation.nav_default_exit_anim,
PushingEnterAnimation = static (args) => Resource.Animator.flip_right_in,
PushingLeaveAnimation = static (args) => Resource.Animator.flip_right_out,
PoppingEnterAnimation = static (args) => Resource.Animator.flip_left_in,
PoppingLeaveAnimation = static (args) => Resource.Animator.flip_left_out,
#elif IOS || MACCATALYST
SwitchingAnimationDuration = static (args) => 0.3,
SwitchingAnimation = static (args) => static (from, to) =>
{
from.Alpha = 0;
to.Alpha = 1;
},
SwitchingAnimationStarting = static (args) => static (from, to) =>
{
to.Alpha = 0;
},
SwitchingAnimationFinished = static (args) => static (from, to) =>
{
from.Alpha = 1;
},
PushingAnimation = static (args) => new AppleTransitioning(true),
PoppingAnimation = static (args) => new AppleTransitioning(false),
#elif WINDOWS
PushingAnimation = static (args) => new Microsoft.UI.Xaml.Media.Animation.DrillInNavigationTransitionInfo(),
PoppingAnimation = static (args) => new Microsoft.UI.Xaml.Media.Animation.DrillInNavigationTransitionInfo(),
#endif
};
}
#if IOS || MACCATALYST
public class AppleTransitioning : Foundation.NSObject, UIKit.IUIViewControllerAnimatedTransitioning
{
private readonly bool pushing;
public AppleTransitioning(bool pushing)
{
this.pushing = pushing;
}
public void AnimateTransition(UIKit.IUIViewControllerContextTransitioning transitionContext)
{
var fromView = transitionContext.GetViewFor(UIKit.UITransitionContext.FromViewKey);
var toView = transitionContext.GetViewFor(UIKit.UITransitionContext.ToViewKey);
var container = transitionContext.ContainerView;
var duration = TransitionDuration(transitionContext);
if (pushing)
container.AddSubview(toView);
else
container.InsertSubviewBelow(toView, fromView);
var currentFrame = pushing ? toView.Frame : fromView.Frame;
var offsetFrame = new CoreGraphics.CGRect(x: currentFrame.Location.X, y: currentFrame.Height, width: currentFrame.Width, height: currentFrame.Height);
if (pushing)
{
toView.Frame = offsetFrame;
toView.Alpha = 0;
}
var animations = () =>
{
UIKit.UIView.AddKeyframeWithRelativeStartTime(0.0, 1, () =>
{
if (pushing)
{
toView.Frame = currentFrame;
toView.Alpha = 1;
}
else
{
fromView.Frame = offsetFrame;
fromView.Alpha = 0;
}
});
};
UIKit.UIView.AnimateKeyframes(
duration,
0,
UIKit.UIViewKeyframeAnimationOptions.CalculationModeCubic,
animations,
(finished) =>
{
container.AddSubview(toView);
transitionContext.CompleteTransition(!transitionContext.TransitionWasCancelled);
toView.Alpha = 1;
fromView.Alpha = 1;
});
}
public double TransitionDuration(UIKit.IUIViewControllerContextTransitioning transitionContext)
{
return 0.25;
}
}
#endif