2using System.Collections.Concurrent;
53 private readonly ConcurrentDictionary<string, ViewAnimationDescriptor> viewDescriptors =
new(StringComparer.Ordinal);
54 private readonly ConcurrentDictionary<string, TransitionAnimationDescriptor> transitionDescriptors =
new(StringComparer.Ordinal);
59 ArgumentNullException.ThrowIfNull(Context);
62 if (Descriptor is
null)
75 ArgumentNullException.ThrowIfNull(Context);
78 if (Descriptor is
null)
91 ArgumentNullException.ThrowIfNull(Descriptor);
92 string Key = ComposeKey(Descriptor.
Key, Platform, Theme);
93 this.viewDescriptors[Key] = Descriptor;
99 ArgumentNullException.ThrowIfNull(Descriptor);
100 string Key = ComposeKey(Descriptor.
Key, Platform, Theme);
101 this.transitionDescriptors[Key] = Descriptor;
104 private static TDescriptor? ResolveDescriptor<TDescriptor>(ConcurrentDictionary<string, TDescriptor> Descriptors,
AnimationKey Key,
IAnimationContext Context)
107 string BaseKey = Key.Value;
108 string PlatformKey =
string.IsNullOrWhiteSpace(Context.Platform) ? string.Empty : Context.Platform;
109 string? ThemeKey = Context.Theme;
111 List<string> Candidates =
new List<string>();
113 if (!
string.IsNullOrWhiteSpace(PlatformKey) && !
string.IsNullOrWhiteSpace(ThemeKey))
114 Candidates.Add(ComposeKey(BaseKey, PlatformKey, ThemeKey));
116 if (!
string.IsNullOrWhiteSpace(PlatformKey))
117 Candidates.Add(ComposeKey(BaseKey, PlatformKey,
null));
119 if (!
string.IsNullOrWhiteSpace(ThemeKey))
120 Candidates.Add(ComposeKey(BaseKey,
null, ThemeKey));
122 Candidates.Add(BaseKey);
124 foreach (
string Candidate
in Candidates)
126 if (Descriptors.TryGetValue(Candidate, out TDescriptor Descriptor))
133 private static string ComposeKey(AnimationKey Key,
string? Platform,
string? Theme)
135 return ComposeKey(Key.Value, Platform, Theme);
138 private static string ComposeKey(
string BaseKey,
string? Platform,
string? Theme)
140 StringBuilder Builder =
new StringBuilder(BaseKey);
141 if (!
string.IsNullOrWhiteSpace(Platform))
144 Builder.Append(Platform);
147 if (!
string.IsNullOrWhiteSpace(Theme))
150 Builder.Append(Theme);
153 return Builder.ToString();
Base class for animation descriptors.
AnimationKey Key
Gets the descriptor key.
Default implementation of IAnimationRegistry.
void Register(ViewAnimationDescriptor Descriptor, string? Platform=null, string? Theme=null)
Registers a view animation descriptor.
void Register(TransitionAnimationDescriptor Descriptor, string? Platform=null, string? Theme=null)
Registers a transition animation descriptor.
bool TryCreateViewAnimation(AnimationKey Key, IAnimationContext Context, out IViewAnimation Animation)
Attempts to create a view animation for the given key and context. True if an animation could be crea...
bool TryCreateTransition(AnimationKey Key, IAnimationContext Context, out ITransitionAnimation Animation)
Attempts to create a transition animation for the given key and context. True if an animation could b...
Descriptor defining a reusable transition animation profile.
ITransitionAnimation CreateExecutor(IAnimationContext Context)
Creates an executor for the given context.
Descriptor defining a reusable view animation profile.
IViewAnimation CreateExecutor(IAnimationContext Context)
Creates an executor for the given context.
Represents contextual information required when executing an animation.
Registry abstraction for animation descriptors.
bool TryCreateViewAnimation(AnimationKey Key, IAnimationContext Context, out IViewAnimation Animation)
Attempts to create a view animation for the given key and context.
void Register(TransitionAnimationDescriptor Descriptor, string? Platform=null, string? Theme=null)
Registers a transition animation descriptor.
bool TryCreateTransition(AnimationKey Key, IAnimationContext Context, out ITransitionAnimation Animation)
Attempts to create a transition animation for the given key and context.
void Register(ViewAnimationDescriptor Descriptor, string? Platform=null, string? Theme=null)
Registers a view animation descriptor.
Defines a transition animation executor.
Defines a view-based animation executor.
Represents a strongly typed key used for identifying animations.