Skip to content

Commit

Permalink
fixed task cancelled crash
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiMisiukevich committed Jun 7, 2019
1 parent c13b9f0 commit 2775d95
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions TouchEffect/TouchVisualManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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));
}));
}
}
}

0 comments on commit 2775d95

Please sign in to comment.