Exemplo n.º 1
0
        /// <summary>
        /// Asynchronously loads a composition from a file stored in /assets.
        /// </summary>
        public static Task <LottieComposition> FromAssetFileNameAsync(Context context, String fileName, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(Task.FromCanceled <LottieComposition>(cancellationToken));
            }

            var tcs        = new TaskCompletionSource <LottieComposition>();
            var cancelable = LottieComposition.FromAssetFileName(context, fileName, (composition) =>
            {
                cancellationToken.ThrowIfCancellationRequested();
                tcs.SetResult(composition);
            });

            cancellationToken.Register(() =>
            {
                if (!tcs.Task.IsCompleted)
                {
                    cancelable.Cancel();
                    tcs.TrySetCanceled(cancellationToken);
                }
            });

            return(tcs.Task);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Asynchronously loads a composition from a file stored in /assets.
 /// </summary>
 public static LottieComposition.ICancellable FromAssetFileName(Context context, String fileName, Action <LottieComposition> onLoaded)
 {
     return(LottieComposition.FromAssetFileName(context, fileName, new ActionCompositionLoaded(onLoaded)));
 }