Maui: [BUG] TouchBehavior cancel animation even though it is just short tap
Is there an existing issue for this?
- I have searched the existing issues
Did you read the “Reporting a bug” section on Contributing file?
- I have read the “Reporting a bug” section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
Touch behavior when set DefaultAnimationDuration and user just tap the element, it will just abort the animation and throw TaskCanceledException even though the animation is not finished. I am not sure if this is expected behavior. Because from user perspective if I just tap it, it should show and finish the animation within the duration of DefaultAnimationDuration. Here it is in current implementation even though I increase the DefaultAnimationDuration to be 500
https://github.com/user-attachments/assets/cd4f37a4-55b4-4515-a46b-4866f9de4077
And here is the stacktrace
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at CommunityToolkit.Maui.Behaviors.GestureManager.SetScale(TouchBehavior sender, TouchState touchState, HoverState hoverState, TimeSpan duration, Easing easing, CancellationToken token) in /Users/albilaga/Documents/Personal/CommunityToolkit.Maui/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/GestureManager.shared.cs:line 475
at CommunityToolkit.Maui.Behaviors.GestureManager.RunAnimationTask(TouchBehavior sender, TouchState touchState, HoverState hoverState, CancellationToken token, Nullable`1 durationMultiplier) in /Users/albilaga/Documents/Personal/CommunityToolkit.Maui/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/GestureManager.shared.cs:line 799
at CommunityToolkit.Maui.Behaviors.GestureManager.ChangeStateAsync(TouchBehavior sender, Boolean animated, CancellationToken token) in /Users/albilaga/Documents/Personal/CommunityToolkit.Maui/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/GestureManager.shared.cs:line 118
at CommunityToolkit.Maui.Behaviors.TouchBehavior.ForceUpdateState(CancellationToken token, Boolean animated) in /Users/albilaga/Documents/Personal/CommunityToolkit.Maui/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.methods.shared.cs:line 65
System.Threading.Tasks.TaskCanceledException: A task was canceled.
Expected Behavior
TouchBehavior should finish the animation in DefaultAnimationDuration and not just directly abort the animation. It should be doing something like this.
https://github.com/user-attachments/assets/3553c111-770c-4681-8499-5e154c51a5ce
Steps To Reproduce
- Open and run the project in here https://github.com/albilaga/CommunityToolkit.Maui/tree/bugfix/wait_animation
- Open the side menu -> Behaviors -> TouchBehavior
- Scroll to the most bottom of view and tap the
Lorem Ipsumview. It will just directly cancel the animation after we tap it
Link to public reproduction project repository
https://github.com/albilaga/CommunityToolkit.Maui/tree/bugfix/wait_animation
Environment
- .NET MAUI CommunityToolkit: 9.0.2
- OS: MacOS Sonoma 14.5
- .NET MAUI: 8.0.60
Anything else?
For now the workaround I have as seen in this commit https://github.com/CommunityToolkit/Maui/commit/033416b67383e13c8854499105bffc78fa310c62 is I just waiting with Task.Delay(DefaultAnimationDuration if touch status is completed. This is still not handling if user tap the view more than once in duration of DefaultAnimationDuration so that’s why I am not publishing the PR in here. And I am also not sure if this bug is intended or not. Help is appreciated also. Thank you
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 18 (7 by maintainers)
@bijington just created PR in here https://github.com/CommunityToolkit/Maui/pull/2101
@Axemasta [One week later] I “think” I remember where in the app was current when I was triggering that problem with a resize…but today I’m not seeing it happen. 😃 BUT…2 days after that post I updated from 9.0.1 to 9.0.3 and so maybe that’s the difference…
My logs are littered with these.
FWIW I am getting an unhandled exception with the exact same stack trace shown in the original report - while resizing the window frame running on Windows. Not sure how the touch behavior is getting triggered by the resize but that’s the stack trace I’m seeing in the exception. And even though the unhandled exception is “handled” the app becomes useless at that point.
Hi @Axemasta I’ve reproduced issue on following repo https://github.com/osaleem303/TouchEffectDemo
and also attached a screen recording on reproducing of that issue. Let me know if you need any further info on that.
@bijington I think this is something that might have been broken during the pr review of the effect. It used to play the full animation even after lifting from a click (something I’d expect personally).
The task cancelled exception is really just noise, but it does happen a lot especially if you are relying on this control so I probably need to go back to a commit that was working on my end and see what’s changed, then pr it back in.
I’m not aware of any crashes or issues with non responsiveness on mac catalyst, @osaleem303 can you provide a reproduction?