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 00f0133
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 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 animationTaskCompletionSource;

private string[] properties = null;
private string[] destValue = null;
Expand Down Expand Up @@ -1348,6 +1351,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 All @@ -1365,6 +1375,33 @@ internal object ConvertTo(object value, Type toType)
return ConvertTo(value, toType, getConverter);
}

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

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

internal object ConvertTo(object value, Type toType, Func<object> getConverter)
{
if (value == null)
Expand Down

0 comments on commit 00f0133

Please sign in to comment.