Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
TranslateAnimation.cs
1using System;
2using System.Runtime.ExceptionServices;
3using System.Threading;
4using System.Threading.Tasks;
5using Microsoft.Maui.ApplicationModel;
6using Microsoft.Maui.Controls;
7
9{
14 {
15 private readonly double? fromX;
16 private readonly double? fromY;
17 private readonly double toX;
18 private readonly double toY;
19
29 public TranslateAnimation(TimeSpan Duration, Easing Easing, double? FromX, double? FromY, double ToX, double ToY)
30 : base(Duration, Easing)
31 {
32 this.fromX = FromX;
33 this.fromY = FromY;
34 this.toX = ToX;
35 this.toY = ToY;
36 }
37
39 public override async Task RunAsync(VisualElement Target, IAnimationContext Context, AnimationOptions? Options, CancellationToken Token)
40 {
41 ArgumentNullException.ThrowIfNull(Target);
42 ArgumentNullException.ThrowIfNull(Context);
43
44 if (Context.ReduceMotion && (Options?.ForceMotion != true))
45 {
46 Target.TranslationX = this.toX;
47 Target.TranslationY = this.toY;
48 return;
49 }
50
51 if (this.fromX.HasValue)
52 Target.TranslationX = this.fromX.Value;
53 if (this.fromY.HasValue)
54 Target.TranslationY = this.fromY.Value;
55
56 uint DurationMs = this.ResolveDurationMilliseconds(Context, Options);
57 Func<CancellationToken, Task> Execute = _ => Target.TranslateToAsync(this.toX, this.toY, DurationMs, this.Easing);
58 ExceptionDispatchInfo? DispatchInfo = null;
59 try
60 {
61 await AnimationRunner.RunAsync(Target, Execute, Token);
62 }
63 catch (Exception Ex)
64 {
65 DispatchInfo = ExceptionDispatchInfo.Capture(Ex);
66 }
67 finally
68 {
69 await this.ApplyFinalTranslationAsync(Target);
70 }
71
72 DispatchInfo?.Throw();
73 }
74
75 private Task ApplyFinalTranslationAsync(VisualElement Target)
76 {
77 return MainThread.InvokeOnMainThreadAsync(() =>
78 {
79 Target.TranslationX = this.toX;
80 Target.TranslationY = this.toY;
81 });
82 }
83 }
84}
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.
Base class providing timing helpers for view animations.
uint ResolveDurationMilliseconds(IAnimationContext Context, AnimationOptions? Options)
Resolves the duration expressed in milliseconds.
Represents a translation animation affecting the X and Y axes.
TranslateAnimation(TimeSpan Duration, Easing Easing, double? FromX, double? FromY, double ToX, double ToY)
Initializes a new instance of the TranslateAnimation class.
override async Task RunAsync(VisualElement Target, IAnimationContext Context, AnimationOptions? Options, CancellationToken Token)
Executes the animation against the specified target. Task tracking execution.
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