3using Microsoft.Maui.Controls;
18 ArgumentNullException.ThrowIfNull(Registry);
20 RegisterShellAnimations(Registry);
21 RegisterViewSwitcherAnimations(Registry);
26 TimeSpan PageDuration = TimeSpan.FromMilliseconds(300);
27 Easing PageEasing = Easing.Linear;
39 TimeSpan.FromMilliseconds(250),
41 Context => CreateHorizontalSlideTransition(Context, SlideDirection.Left)));
45 TimeSpan.FromMilliseconds(250),
47 Context => CreateHorizontalSlideTransition(Context, SlideDirection.Right)));
49 RegisterPopupAnimations(Registry);
50 RegisterToastAnimations(Registry);
53 private static void RegisterViewSwitcherAnimations(IAnimationRegistry Registry)
55 TimeSpan Duration = TimeSpan.FromMilliseconds(250);
56 Easing Easing = Easing.Linear;
57 Registry.Register(
new TransitionAnimationDescriptor
59 AnimationKeys.ViewSwitcher.CrossFade,
62 _ =>
new TransitionAnimation(
63 new FadeAnimation(Duration, Easing, 0, 1),
64 new FadeAnimation(Duration, Easing,
null, 0))
69 private static void RegisterPopupAnimations(IAnimationRegistry Registry)
71 TimeSpan FadeDuration = TimeSpan.FromMilliseconds(150);
72 TimeSpan ScaleDuration = TimeSpan.FromMilliseconds(200);
74 Registry.Register(
new ViewAnimationDescriptor(
75 AnimationKeys.Shell.PopupShowFade,
78 _ =>
new FadeAnimation(FadeDuration, Easing.CubicOut, 0, 1)));
80 Registry.Register(
new ViewAnimationDescriptor(
81 AnimationKeys.Shell.PopupHideFade,
84 _ =>
new FadeAnimation(FadeDuration, Easing.CubicIn,
null, 0)));
86 Registry.Register(
new ViewAnimationDescriptor(
87 AnimationKeys.Shell.PopupShowScale,
90 _ =>
new CompositeViewAnimation(
92 new List<IViewAnimation>
94 new FadeAnimation(ScaleDuration, Easing.CubicOut, 0, 1),
95 new ScaleAnimation(ScaleDuration, Easing.CubicOut, 0.9, 1)
98 Registry.Register(
new ViewAnimationDescriptor(
99 AnimationKeys.Shell.PopupHideScale,
100 TimeSpan.FromMilliseconds(150),
102 _ =>
new CompositeViewAnimation(
104 new List<IViewAnimation>
106 new FadeAnimation(TimeSpan.FromMilliseconds(150), Easing.CubicIn, null, 0),
107 new ScaleAnimation(TimeSpan.FromMilliseconds(150), Easing.CubicIn, null, 0.9)
110 Registry.Register(
new ViewAnimationDescriptor(
111 AnimationKeys.Shell.PopupShowSlideUp,
116 double StartY = Context.ViewportHeight > 0 ? Context.ViewportHeight * 0.5 : 200;
117 return new CompositeViewAnimation(
118 AnimationCompositionMode.Parallel,
119 new List<IViewAnimation>
121 new FadeAnimation(ScaleDuration, Easing.CubicOut, 0, 1),
122 new TranslateAnimation(ScaleDuration, Easing.CubicOut, null, StartY, 0, 0)
126 Registry.Register(
new ViewAnimationDescriptor(
127 AnimationKeys.Shell.PopupHideSlideUp,
128 TimeSpan.FromMilliseconds(150),
130 Context =>
new CompositeViewAnimation(
132 new List<IViewAnimation>
134 new FadeAnimation(TimeSpan.FromMilliseconds(150), Easing.CubicIn, null, 0),
135 new TranslateAnimation(TimeSpan.FromMilliseconds(150), Easing.CubicIn, null, null, 0, 50)
139 private static void RegisterToastAnimations(IAnimationRegistry Registry)
141 TimeSpan FadeDuration = TimeSpan.FromMilliseconds(150);
143 Registry.Register(
new ViewAnimationDescriptor(
144 AnimationKeys.Shell.ToastShowFade,
147 _ =>
new FadeAnimation(FadeDuration, Easing.CubicOut, 0, 1)));
149 Registry.Register(
new ViewAnimationDescriptor(
150 AnimationKeys.Shell.ToastHideFade,
153 _ =>
new FadeAnimation(FadeDuration, Easing.CubicIn,
null, 0)));
155 Registry.Register(
new ViewAnimationDescriptor(
156 AnimationKeys.Shell.ToastShowSlideTop,
159 _ =>
new CompositeViewAnimation(
161 new List<IViewAnimation>
163 new FadeAnimation(FadeDuration, Easing.CubicOut, 0, 1),
164 new TranslateAnimation(FadeDuration, Easing.CubicOut, null, -40, 0, 0)
167 Registry.Register(
new ViewAnimationDescriptor(
168 AnimationKeys.Shell.ToastHideSlideTop,
171 _ =>
new CompositeViewAnimation(
173 new List<IViewAnimation>
175 new FadeAnimation(FadeDuration, Easing.CubicIn, null, 0),
176 new TranslateAnimation(FadeDuration, Easing.CubicIn, null, null, 0, -40)
179 Registry.Register(
new ViewAnimationDescriptor(
180 AnimationKeys.Shell.ToastShowSlideBottom,
183 _ =>
new CompositeViewAnimation(
185 new List<IViewAnimation>
187 new FadeAnimation(FadeDuration, Easing.CubicOut, 0, 1),
188 new TranslateAnimation(FadeDuration, Easing.CubicOut, null, 40, 0, 0)
191 Registry.Register(
new ViewAnimationDescriptor(
192 AnimationKeys.Shell.ToastHideSlideBottom,
195 _ =>
new CompositeViewAnimation(
197 new List<IViewAnimation>
199 new FadeAnimation(FadeDuration, Easing.CubicIn, null, 0),
200 new TranslateAnimation(FadeDuration, Easing.CubicIn, null, null, 0, 40)
204 private enum SlideDirection
210 private static TransitionAnimation CreateHorizontalSlideTransition(IAnimationContext Context, SlideDirection Direction)
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);
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.
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.
AnimationCompositionMode
Defines how composite animations should execute child animations.