Browse Source

feat: Allow stopping composition animation (#20074)

* feat: Allow stopping composition animation

* docs: Add XML comment

* fix: Fix nullability

* feat: Add StopAnimationGroup

* docs: Add XML comments

---------

Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
pull/18827/head
Betta_Fish 3 months ago
committed by GitHub
parent
commit
e351303d1f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 33
      src/Avalonia.Base/Rendering/Composition/CompositionObject.cs

33
src/Avalonia.Base/Rendering/Composition/CompositionObject.cs

@ -65,6 +65,18 @@ namespace Avalonia.Rendering.Composition
throw new ArgumentException("Unknown property " + propertyName); throw new ArgumentException("Unknown property " + propertyName);
} }
/// <summary>Disconnects an animation from the specified property and stops the animation.</summary>
/// <param name="propertyName">The name of the property to disconnect the animation from.</param>
public void StopAnimation(string propertyName)
{
if (propertyName is null)
throw new ArgumentNullException(nameof(propertyName));
if (Server is not ServerObject srv)
return;
var prop = srv.GetCompositionProperty(propertyName) ?? throw new ArgumentException("Unknown property " + propertyName);
srv.Animations?.RemoveAnimationForProperty(prop);
}
/// <summary> /// <summary>
/// Starts an animation group. /// Starts an animation group.
/// The StartAnimationGroup method on CompositionObject lets you start CompositionAnimationGroup. /// The StartAnimationGroup method on CompositionObject lets you start CompositionAnimationGroup.
@ -126,6 +138,27 @@ namespace Avalonia.Rendering.Composition
throw new ArgumentException(); throw new ArgumentException();
} }
/// <summary>Stops an animation group.</summary>
/// <param name="grp">The animation group to stop.</param>
public void StopAnimationGroup(ICompositionAnimationBase grp)
{
if (grp is CompositionAnimation animation)
{
if (animation.Target == null)
throw new ArgumentException("Animation Target can't be null");
StopAnimation(animation.Target);
}
else if (grp is CompositionAnimationGroup group)
{
foreach (var a in group.Animations)
{
if (a.Target == null)
throw new ArgumentException("Animation Target can't be null");
StopAnimation(a.Target);
}
}
}
protected void RegisterForSerialization() protected void RegisterForSerialization()
{ {
if (Server == null) if (Server == null)

Loading…
Cancel
Save