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)); + })); } } }