Skip to content

Commit

Permalink
[NUI] add asynchronous tasked animation play
Browse files Browse the repository at this point in the history
  • Loading branch information
everLEEst committed Jan 9, 2025
1 parent 26739b8 commit 4b7a335
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Tizen.NUI/src/public/Animation/Animation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace Tizen.NUI
using System.Reflection;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;

using Tizen.NUI.BaseComponents;

Expand Down Expand Up @@ -61,6 +63,7 @@ public class Animation : BaseHandle
private System.IntPtr finishedCallbackOfNative;

private AnimationProgressReachedEventCallbackType animationProgressReachedEventCallback;
private TaskCompletionSource<bool> animationTaskCompletionSource;

private string[] properties = null;
private string[] destValue = null;
Expand Down Expand Up @@ -1283,6 +1286,36 @@ public void Play()
Stop(EndActions.StopFinal);
}


/// <summary>
/// Plays the animation asynchronously.
/// </summary>
/// <returns>A Task that completes when the animation finishes.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public Task PlayAsync()
{
if (DisableAnimation)
{
return Task.FromCanceled(CancellationToken.None);
}

if (animationTaskCompletionSource != null)
{
animationTaskCompletionSource.SetCanceled();
}
animationTaskCompletionSource = new TaskCompletionSource<bool>();
void finished(object sender, EventArgs e)
{
Finished -= finished;
animationTaskCompletionSource.SetResult(true);
animationTaskCompletionSource = null;
}
Finished += finished;
Play();
return animationTaskCompletionSource.Task;
}


/// <summary>
/// Plays the animation from a given point.<br />
/// The progress must be in the 0-1 interval or in the play range interval if defined,
Expand Down Expand Up @@ -1348,6 +1381,13 @@ public void Clear()
{
Interop.Animation.Clear(SwigCPtr);
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();

if (animationTaskCompletionSource != null)
{
animationTaskCompletionSource.SetCanceled();
animationTaskCompletionSource = null;
}

}

internal object ConvertTo(object value, Type toType)
Expand Down

0 comments on commit 4b7a335

Please sign in to comment.