Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Touch Behavior Cancelled too fast if user just tap it once #2101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

albilaga
Copy link

@albilaga albilaga commented Aug 8, 2024

Description of Change

When user tap the button or element that have TouchBehavior, the TouchBehavior animation didn't respect DefaultAnimationDuration to finish the animation. So basically after user tap it will directly cancel and it will throw 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.

This PR attempt to fix that by waiting with Task.Delay from DefaultAnimationDuration instead of just directly abort it

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Copy link
Member

@pictos pictos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does your change handles double-tap? If so, how is the behavior?

@albilaga albilaga marked this pull request as draft August 9, 2024 05:57
@bijington
Copy link
Contributor

Does your change handles double-tap? If so, how is the behavior?

Based on the referenced issue this fix doesn't solve that problem. I asked the author to open this anyway to show what they had and we work through it. I've added a review comment to show what I think might be the fix. I'll try and test it out later

@pictos
Copy link
Member

pictos commented Aug 10, 2024

Does your change handles double-tap? If so, how is the behavior?

Based on the referenced issue this fix doesn't solve that problem. I asked the author to open this anyway to show what they had and we work through it. I've added a review comment to show what I think might be the fix. I'll try and test it out later

Yeah, I asked that, because (for me) would be odd to have the animation going on after I release the button, or if I double tap it, would that replicates two animations, if yes, that could cause some confusion on the user...

@albilaga
Copy link
Author

albilaga commented Aug 12, 2024

@pictos here is the result when double tap. As you thought it is like handled by two animations. here is the attached result

CleanShot.2024-08-12.at.10.51.39.mp4

so you suggest to like giving throttle to ignore the next tap? or how it should be

Based on the referenced issue this fix doesn't solve that problem. I asked the author to open this anyway to show what they had and we work through it. I've added a review comment to show what I think might be the fix. I'll try and test it out later

@bijington I don't see your review or I miss something?

Btw I change it to draft because I don't think it is ready yet

@albilaga albilaga force-pushed the bugfix/wait_animation branch from e578c6a to 3268083 Compare August 12, 2024 03:56
@pictos
Copy link
Member

pictos commented Aug 12, 2024

@albilaga I believe the control should ignore any other touch while animation is performing. Since this is a single tap instead of a double-tap gesture. For me, at least, feels wrong having that behavior

@albilaga albilaga force-pushed the bugfix/wait_animation branch from 3268083 to 7dc958c Compare August 24, 2024 15:36
@albilaga
Copy link
Author

@pictos testing with native android with button pressed state it will just do pressed state again without ignoring the second tap?
CleanShot 2024-08-24 at 23 04 40

@albilaga albilaga requested a review from pictos August 24, 2024 16:06
@albilaga albilaga marked this pull request as ready for review August 24, 2024 16:06
@dotnet-policy-service dotnet-policy-service bot added stale The author has not responded in over 30 days help wanted This proposal has been approved and is ready to be implemented labels Sep 24, 2024
@brminnick
Copy link
Collaborator

Hi @albilaga! Could you update this PR to resolve the merge conflicts?

We've finally merged the massive .NET 9 PR today and it introduced a few merge conflicts across our open PRs.

@albilaga
Copy link
Author

Hi @brminnick will do. this week hopefully can do resolve merge conflict. still got some fever 🤒🤒🤒

Added a conditional delay based on DefaultAnimationDuration in GestureManager to improve touch animation handling. Updated the sample TouchBehaviorPage to increase the DefaultAnimationDuration from 150ms to 500ms to show case the bug
@albilaga albilaga force-pushed the bugfix/wait_animation branch from 7dc958c to 358b51a Compare December 21, 2024 09:26
@albilaga
Copy link
Author

Hi @brminnick , PR already reabased

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted This proposal has been approved and is ready to be implemented stale The author has not responded in over 30 days
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] TouchBehavior cancel animation even though it is just short tap
4 participants