Maui icon indicating copy to clipboard operation
Maui copied to clipboard

[BUG] TouchBehavior: Tap and LongPress conflict (Tap fires after LongPress, or LongPress misfires as Tap)

Open ghost opened this issue 3 months ago • 2 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

  • [x] 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

When using TouchBehavior to handle both tap and long‑press gestures on the same control, the events/commands overlap in unexpected ways.

  • If you attach both TouchGestureCompleted and LongPressCompleted, a long press triggers both handlers.

  • If you mix TapGestureRecognizer with TouchBehavior.LongPressCommand, sometimes a long press also triggers a tap, or two quick taps are mis‑interpreted as a long press.

This makes it difficult to reliably distinguish between a quick tap and a long press.

Expected Behavior

Expected behavior Quick tap → only OnTapCompleted fires.

Long press → only OnLongPressCompleted fires.

Steps To Reproduce

Reproduction MainPage.xaml

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             x:Class="TouchBugDemo.MainPage">

    <Grid Padding="40">
        <Grid.Behaviors>
            <toolkit:TouchBehavior 
                LongPressDuration="5000"
                TouchGestureCompleted="OnTapCompleted"
                LongPressCompleted="OnLongPressCompleted" />
        </Grid.Behaviors>

        <Border Stroke="Gray" StrokeThickness="2" Padding="20">
            <Label Text="Tap or Long Press me"
                   HorizontalOptions="Center"
                   VerticalOptions="Center" />
        </Border>
    </Grid>
</ContentPage>

MainPage.xaml.cs

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    private void OnTapCompleted(object sender, EventArgs e)
    {
        Console.WriteLine("Tap fired");
    }

    private void OnLongPressCompleted(object sender, EventArgs e)
    {
        Console.WriteLine("Long press fired");
    }
}
  1. Open the project
  2. Tap on Grid multiple times with minimal delay between taps - you will see Long press fired also
  3. Long press - you will see normal tap fired also

Link to public reproduction project repository

https://github.com/rokmeglic71/Tap-and-LongPress-conflict-Tap-fires-after-LongPress-or-LongPress-misfires-as-Tap-

Environment

- .NET MAUI CommunityToolkit: 12.2.0
- OS: Microsoft Windows 10 Pro - 10.0.19045 Graditev 19045
- .NET MAUI: 9.0.110

Anything else?

Sometimes if you do fast taps, then do a long press. You will get multiple long press fired in a short amount of time (less then the LongPressDuration).

Thank you for CoPilot who prepared everything.

ghost avatar Sep 29 '25 10:09 ghost

https://github.com/user-attachments/assets/bc587818-5824-40d3-8ecd-013721c5db8d

ghost avatar Sep 29 '25 10:09 ghost

@bijington any chance somebody could look at this issue?

ghost avatar Oct 08 '25 11:10 ghost

@jamesbrooksbank @TheCodeTraveler — polite bump.

The ticket hasn’t received any comments yet, so I just wanted to check whether you will have a chance to look at the details above. Thank you!

development-jantar avatar Dec 18 '25 09:12 development-jantar