Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ScaleAnimation.cs
1using System;
2using System.Runtime.ExceptionServices;
3using System.Threading;
4using System.Threading.Tasks;
5using Microsoft.Maui.ApplicationModel;
6using Microsoft.Maui.Controls;
7
9{
13 public sealed class ScaleAnimation : TimedViewAnimation
14 {
15 private readonly double? fromScale;
16 private readonly double toScale;
17
25 public ScaleAnimation(TimeSpan Duration, Easing Easing, double? FromScale, double ToScale)
26 : base(Duration, Easing)
27 {
28 if (ToScale < 0)
29 throw new ArgumentOutOfRangeException(nameof(ToScale), "Scale cannot be negative.");
30 if (FromScale.HasValue && FromScale.Value < 0)
31 throw new ArgumentOutOfRangeException(nameof(FromScale), "Scale cannot be negative.");
32
33 this.fromScale = FromScale;
34 this.toScale = ToScale;
35 }
36
38 public override async Task RunAsync(VisualElement Target, IAnimationContext Context, AnimationOptions? Options, CancellationToken Token)
39 {
40 ArgumentNullException.ThrowIfNull(Target);
41 ArgumentNullException.ThrowIfNull(Context);
42
43 if (Context.ReduceMotion && (Options?.ForceMotion != true))
44 {
45 Target.Scale = this.toScale;
46 return;
47 }
48
49 if (this.fromScale.HasValue)
50 Target.Scale = this.fromScale.Value;
51
52 uint DurationMs = this.ResolveDurationMilliseconds(Context, Options);
53 Func<CancellationToken, Task> Execute = _ => Target.ScaleToAsync(this.toScale, DurationMs, this.Easing);
54 ExceptionDispatchInfo? DispatchInfo = null;
55 try
56 {
57 await AnimationRunner.RunAsync(Target, Execute, Token);
58 }
59 catch (Exception Ex)
60 {
61 DispatchInfo = ExceptionDispatchInfo.Capture(Ex);
62 }
63 finally
64 {
65 await this.ApplyFinalScaleAsync(Target);
66 }
67
68 DispatchInfo?.Throw();
69 }
70
71 private Task ApplyFinalScaleAsync(VisualElement Target)
72 {
73 return MainThread.InvokeOnMainThreadAsync(() =>
74 {
75 Target.Scale = this.toScale;
76 });
77 }
78 }
79}
Options applied for an individual animation execution.
bool ForceMotion
Gets or sets a value indicating whether motion should run even when global settings request reduced m...
Helper class providing consistent animation execution semantics.
static async Task RunAsync(VisualElement Target, Func< CancellationToken, Task > Execute, CancellationToken Token)
Executes an animation while wiring cancellation tokens to MAUI animation APIs.
Represents a scale animation.
ScaleAnimation(TimeSpan Duration, Easing Easing, double? FromScale, double ToScale)
Initializes a new instance of the ScaleAnimation class.
override async Task RunAsync(VisualElement Target, IAnimationContext Context, AnimationOptions? Options, CancellationToken Token)
Executes the animation against the specified target. Task tracking execution.
Base class providing timing helpers for view animations.
uint ResolveDurationMilliseconds(IAnimationContext Context, AnimationOptions? Options)
Resolves the duration expressed in milliseconds.
Represents contextual information required when executing an animation.
bool ReduceMotion
Gets a value indicating whether the caller requests reduced motion.
Definition: ImplTypes.g.cs:58