From 2775d9515dcf764dfad82e77cc22ff64ac08ddb8 Mon Sep 17 00:00:00 2001 From: Andrei Misiukevich Date: Sat, 8 Jun 2019 00:32:02 +0300 Subject: [PATCH] fixed task cancelled crash --- TouchEffect/TouchVisualManager.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/TouchEffect/TouchVisualManager.cs b/TouchEffect/TouchVisualManager.cs index 585e8b9..b6e84aa 100644 --- a/TouchEffect/TouchVisualManager.cs +++ b/TouchEffect/TouchVisualManager.cs @@ -341,13 +341,15 @@ private async Task SetRotationYAsync(ITouchEff sender, TouchState state, int dur private Task GetAnimationTask(ITouchEff sender, TouchState state, double? durationMultiplier = null) { + var token = _animationTokenSource.Token; + var duration = (state == TouchState.Regular ? sender.RegularAnimationDuration : sender.PressedAnimationDuration).AdjustDurationMultiplier(durationMultiplier); sender.RaiseAnimationStarted(state, duration); return Task.WhenAll( - _customAnimationTaskGetter?.Invoke(sender, state, duration, _animationTokenSource.Token) ?? Task.FromResult(true), + _customAnimationTaskGetter?.Invoke(sender, state, duration, token) ?? Task.FromResult(true), SetBackgroundColorAsync(sender, state, duration), SetOpacityAsync(sender, state, duration), SetScaleAsync(sender, state, duration), @@ -363,11 +365,14 @@ private Task GetAnimationTask(ITouchEff sender, TouchState state, double? durati for (var progress = AnimationProgressDelay; progress < duration; progress += AnimationProgressDelay) { await Task.Delay(AnimationProgressDelay).ConfigureAwait(false); + if (token.IsCancellationRequested) + { + return; + } _animationProgress = (double)progress / duration; } _animationProgress = 1; - - }, _animationTokenSource.Token)); + })); } } }