Junaid Pathan
Junaid Pathan

Reputation: 4306

How to wait until or know when multiple animations are completed in Xamarin Forms?

I am having a code which handles multiple animations. I want to wait until or know if multiple animations are completed. I am currently using await Task.Delay(1000); and setting it equal to maximum duration of one of the animations.

Here is my C# Code Behind:

new Animation()
{
    { 0, 1, new Animation(a => dialogControl.FadeTo(1, 1000)) },
    { 0, 1, new Animation(a => dialogControl.ScaleTo(1, 1000)) },  
}.Commit(this, "Animation1");

await Task.Delay(1000);
Debug.WriteLine("Do some task after multiple animations are completed");

Is there anyway it would wait until all animations are completed and only proceed then?

Upvotes: 2

Views: 662

Answers (2)

Jason
Jason

Reputation: 89092

from the docs on Commit

public void Commit (Xamarin.Forms.IAnimatable owner, 
    string name, uint rate = 16, uint length = 250,
    Xamarin.Forms.Easing easing = default, 
    Action<double,bool> finished = default, 
    Func<bool> repeat = default);

finished Action<Double,Boolean>

An action to call when the animation is finished.

Upvotes: 1

xleon
xleon

Reputation: 6365

await Task.WhenAll(
    dialogControl.FadeTo(1, 1000), 
    dialogControl.ScaleTo(1, 1000)
);

Debug.WriteLine("Do some task after multiple animations are completed");

Upvotes: 2

Related Questions