Skip to content

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

@rokmeglic71

Description

@rokmeglic71

Is there an existing issue for this?

  • I have searched the existing issues

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions