Skip to content

Commit 882ace6

Browse files
Andreas0xffffVladislavAntonyukjfversluis
authored
Allow user interaction during animation to enable faster tap repetitions. (xamarin#1760)
Co-authored-by: Vladislav Antonyuk <33021114+VladislavAntonyuk@users.noreply.github.com> Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
1 parent 77eca83 commit 882ace6

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/PlatformTouchEffect.ios.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -247,21 +247,24 @@ public async Task HandleTouch(TouchStatus status, TouchInteractionStatus? intera
247247
defaultShadowRadius = (float?)(defaultShadowRadius ?? renderer.Layer.ShadowRadius);
248248
defaultShadowOpacity ??= renderer.Layer.ShadowOpacity;
249249

250-
await UIView.AnimateAsync(.2, () =>
251-
{
252-
if (color == Color.Default)
253-
renderer.Layer.Opacity = isStarted ? 0.5f : (float)control.Opacity;
254-
else
255-
renderer.Layer.BackgroundColor = (isStarted ? color : control.BackgroundColor).ToCGColor();
256-
257-
renderer.Layer.CornerRadius = isStarted ? radius : defaultRadius.GetValueOrDefault();
258-
259-
if (shadowRadius >= 0)
250+
var tcs = new TaskCompletionSource<UIViewAnimatingPosition>();
251+
UIViewPropertyAnimator.CreateRunningPropertyAnimator(.2, 0, UIViewAnimationOptions.AllowUserInteraction,
252+
() =>
260253
{
261-
renderer.Layer.ShadowRadius = isStarted ? shadowRadius : defaultShadowRadius.GetValueOrDefault();
262-
renderer.Layer.ShadowOpacity = isStarted ? 0.7f : defaultShadowOpacity.GetValueOrDefault();
263-
}
264-
});
254+
if (color == Color.Default)
255+
renderer.Layer.Opacity = isStarted ? 0.5f : (float)control.Opacity;
256+
else
257+
renderer.Layer.BackgroundColor = (isStarted ? color : control.BackgroundColor).ToCGColor();
258+
259+
renderer.Layer.CornerRadius = isStarted ? radius : defaultRadius.GetValueOrDefault();
260+
261+
if (shadowRadius >= 0)
262+
{
263+
renderer.Layer.ShadowRadius = isStarted ? shadowRadius : defaultShadowRadius.GetValueOrDefault();
264+
renderer.Layer.ShadowOpacity = isStarted ? 0.7f : defaultShadowOpacity.GetValueOrDefault();
265+
}
266+
}, endPos => tcs.SetResult(endPos));
267+
await tcs.Task;
265268
}
266269
}
267270

0 commit comments

Comments
 (0)