Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
AnimationCatalog.cs
1using System;
3using Microsoft.Maui.Controls;
4
6{
10 public static class AnimationCatalog
11 {
16 public static void RegisterDefaults(IAnimationRegistry Registry)
17 {
18 ArgumentNullException.ThrowIfNull(Registry);
19
20 RegisterShellAnimations(Registry);
21 RegisterViewSwitcherAnimations(Registry);
22 }
23
24 private static void RegisterShellAnimations(IAnimationRegistry Registry)
25 {
26 TimeSpan PageDuration = TimeSpan.FromMilliseconds(300);
27 Easing PageEasing = Easing.Linear;
28
31 PageDuration,
32 PageEasing,
33 Context => new TransitionAnimation(
34 new FadeAnimation(PageDuration, PageEasing, 0, 1),
35 new FadeAnimation(PageDuration, PageEasing, null, 0))));
36
39 TimeSpan.FromMilliseconds(250),
40 Easing.CubicOut,
41 Context => CreateHorizontalSlideTransition(Context, SlideDirection.Left)));
42
45 TimeSpan.FromMilliseconds(250),
46 Easing.CubicOut,
47 Context => CreateHorizontalSlideTransition(Context, SlideDirection.Right)));
48
49 RegisterPopupAnimations(Registry);
50 RegisterToastAnimations(Registry);
51 }
52
53 private static void RegisterViewSwitcherAnimations(IAnimationRegistry Registry)
54 {
55 TimeSpan Duration = TimeSpan.FromMilliseconds(250);
56 Easing Easing = Easing.Linear;
57 Registry.Register(new TransitionAnimationDescriptor
58 (
59 AnimationKeys.ViewSwitcher.CrossFade,
60 Duration,
61 Easing,
62 _ => new TransitionAnimation(
63 new FadeAnimation(Duration, Easing, 0, 1),
64 new FadeAnimation(Duration, Easing, null, 0))
65 )
66 );
67 }
68
69 private static void RegisterPopupAnimations(IAnimationRegistry Registry)
70 {
71 TimeSpan FadeDuration = TimeSpan.FromMilliseconds(150);
72 TimeSpan ScaleDuration = TimeSpan.FromMilliseconds(200);
73
74 Registry.Register(new ViewAnimationDescriptor(
75 AnimationKeys.Shell.PopupShowFade,
76 FadeDuration,
77 Easing.CubicOut,
78 _ => new FadeAnimation(FadeDuration, Easing.CubicOut, 0, 1)));
79
80 Registry.Register(new ViewAnimationDescriptor(
81 AnimationKeys.Shell.PopupHideFade,
82 FadeDuration,
83 Easing.CubicIn,
84 _ => new FadeAnimation(FadeDuration, Easing.CubicIn, null, 0)));
85
86 Registry.Register(new ViewAnimationDescriptor(
87 AnimationKeys.Shell.PopupShowScale,
88 ScaleDuration,
89 Easing.CubicOut,
90 _ => new CompositeViewAnimation(
92 new List<IViewAnimation>
93 {
94 new FadeAnimation(ScaleDuration, Easing.CubicOut, 0, 1),
95 new ScaleAnimation(ScaleDuration, Easing.CubicOut, 0.9, 1)
96 })));
97
98 Registry.Register(new ViewAnimationDescriptor(
99 AnimationKeys.Shell.PopupHideScale,
100 TimeSpan.FromMilliseconds(150),
101 Easing.CubicIn,
102 _ => new CompositeViewAnimation(
104 new List<IViewAnimation>
105 {
106 new FadeAnimation(TimeSpan.FromMilliseconds(150), Easing.CubicIn, null, 0),
107 new ScaleAnimation(TimeSpan.FromMilliseconds(150), Easing.CubicIn, null, 0.9)
108 })));
109
110 Registry.Register(new ViewAnimationDescriptor(
111 AnimationKeys.Shell.PopupShowSlideUp,
112 ScaleDuration,
113 Easing.CubicOut,
114 Context =>
115 {
116 double StartY = Context.ViewportHeight > 0 ? Context.ViewportHeight * 0.5 : 200;
117 return new CompositeViewAnimation(
118 AnimationCompositionMode.Parallel,
119 new List<IViewAnimation>
120 {
121 new FadeAnimation(ScaleDuration, Easing.CubicOut, 0, 1),
122 new TranslateAnimation(ScaleDuration, Easing.CubicOut, null, StartY, 0, 0)
123 });
124 }));
125
126 Registry.Register(new ViewAnimationDescriptor(
127 AnimationKeys.Shell.PopupHideSlideUp,
128 TimeSpan.FromMilliseconds(150),
129 Easing.CubicIn,
130 Context => new CompositeViewAnimation(
132 new List<IViewAnimation>
133 {
134 new FadeAnimation(TimeSpan.FromMilliseconds(150), Easing.CubicIn, null, 0),
135 new TranslateAnimation(TimeSpan.FromMilliseconds(150), Easing.CubicIn, null, null, 0, 50)
136 })));
137 }
138
139 private static void RegisterToastAnimations(IAnimationRegistry Registry)
140 {
141 TimeSpan FadeDuration = TimeSpan.FromMilliseconds(150);
142
143 Registry.Register(new ViewAnimationDescriptor(
144 AnimationKeys.Shell.ToastShowFade,
145 FadeDuration,
146 Easing.CubicOut,
147 _ => new FadeAnimation(FadeDuration, Easing.CubicOut, 0, 1)));
148
149 Registry.Register(new ViewAnimationDescriptor(
150 AnimationKeys.Shell.ToastHideFade,
151 FadeDuration,
152 Easing.CubicIn,
153 _ => new FadeAnimation(FadeDuration, Easing.CubicIn, null, 0)));
154
155 Registry.Register(new ViewAnimationDescriptor(
156 AnimationKeys.Shell.ToastShowSlideTop,
157 FadeDuration,
158 Easing.CubicOut,
159 _ => new CompositeViewAnimation(
161 new List<IViewAnimation>
162 {
163 new FadeAnimation(FadeDuration, Easing.CubicOut, 0, 1),
164 new TranslateAnimation(FadeDuration, Easing.CubicOut, null, -40, 0, 0)
165 })));
166
167 Registry.Register(new ViewAnimationDescriptor(
168 AnimationKeys.Shell.ToastHideSlideTop,
169 FadeDuration,
170 Easing.CubicIn,
171 _ => new CompositeViewAnimation(
173 new List<IViewAnimation>
174 {
175 new FadeAnimation(FadeDuration, Easing.CubicIn, null, 0),
176 new TranslateAnimation(FadeDuration, Easing.CubicIn, null, null, 0, -40)
177 })));
178
179 Registry.Register(new ViewAnimationDescriptor(
180 AnimationKeys.Shell.ToastShowSlideBottom,
181 FadeDuration,
182 Easing.CubicOut,
183 _ => new CompositeViewAnimation(
185 new List<IViewAnimation>
186 {
187 new FadeAnimation(FadeDuration, Easing.CubicOut, 0, 1),
188 new TranslateAnimation(FadeDuration, Easing.CubicOut, null, 40, 0, 0)
189 })));
190
191 Registry.Register(new ViewAnimationDescriptor(
192 AnimationKeys.Shell.ToastHideSlideBottom,
193 FadeDuration,
194 Easing.CubicIn,
195 _ => new CompositeViewAnimation(
197 new List<IViewAnimation>
198 {
199 new FadeAnimation(FadeDuration, Easing.CubicIn, null, 0),
200 new TranslateAnimation(FadeDuration, Easing.CubicIn, null, null, 0, 40)
201 })));
202 }
203
204 private enum SlideDirection
205 {
206 Left,
207 Right
208 }
209
210 private static TransitionAnimation CreateHorizontalSlideTransition(IAnimationContext Context, SlideDirection Direction)
211 {
212 double Width = Context.ViewportWidth > 0 ? Context.ViewportWidth : 400;
213 double EnterFrom = Direction == SlideDirection.Left ? Width : -Width;
214 double ExitTo = Direction == SlideDirection.Left ? -Width : Width;
215 TimeSpan Duration = TimeSpan.FromMilliseconds(250);
216 Easing SlideEasing = Easing.CubicOut;
217 IViewAnimation EnterAnimation = new TranslateAnimation(Duration, SlideEasing, EnterFrom, 0, 0, 0);
218 IViewAnimation ExitAnimation = new TranslateAnimation(Duration, SlideEasing, 0, 0, ExitTo, 0);
219 return new TransitionAnimation(EnterAnimation, ExitAnimation);
220 }
221 }
222}
Helper responsible for registering default animation descriptors.
static void RegisterDefaults(IAnimationRegistry Registry)
Registers default animation descriptors with the supplied registry.
Keys for shell-level animations.
static AnimationKey PageSlideLeft
Page slide from right to left transition key.
static AnimationKey PageCrossFade
Page cross-fade transition key.
static AnimationKey PageSlideRight
Page slide from left to right transition key.
Provides strongly typed animation key definitions.
Definition: AnimationKeys.cs:7
Represents an opacity animation.
Descriptor defining a reusable transition animation profile.
Represents a pair of animations used for transitions.
Registry abstraction for animation descriptors.
void Register(ViewAnimationDescriptor Descriptor, string? Platform=null, string? Theme=null)
Registers a view animation descriptor.
Definition: ImplTypes.g.cs:58
AnimationCompositionMode
Defines how composite animations should execute child animations.