C
C#5mo ago
SpReeD

✅ MAUI - Mutlitap Gesture

I haven't found anything on the net about "Multitap Gestures". I tried a few things, currently using "CommunityToolkit.Maui" with the "TouchBehavior". So I'm left with the question, is it even possible?
9 Replies
Absent_Reality
Absent_Reality5mo ago
Not sure if this is what you are after.
SpReeD
SpReeDOP4mo ago
Thanks, but no. By "Multitap" I mean the feature that recognizes "another" tap while being tapped, e.g. you place one finger on the screen and another afterwards, and so on, all of them should be recognized. At the moment it's like a button pressed, so you cannot press it while being pressed already, which sounds plausible, but Touchscreens don't work this way, you can "press" a button/element while it's being pressed.
Absent_Reality
Absent_Reality4mo ago
Ah. I think I understand. So like you are say holding a finger on one button and tap another button with a different finger?
SpReeD
SpReeDOP4mo ago
Almost, tap the same element with multiple fingers - so that every finger is a tap event. Right now the tap is like a button press (button down & up), if pressed/tap-started, it's not possible to start another one, because it not yet ended (button up). My problem is that the logic of buttons doesn't apply to touchscreens, taps ain't buttons, so it seems to me unlogical to treat them like buttons. Every tap should fire an event (or tapbehavior command), every finger touch should to that. In addition there should be a Count of "taps/fingers" in the EventArgs, but I don't need that, all I need is that every finger fires an event on touch/down. I tried the built-in TapGestures, didn't work, so I gave it a try with the CommunityToolkit approach using TouchBehavior. It has some fancy animation stuff, but doesn't offer actually more features.
<mct:TouchBehavior CurrentTouchStatusChanged="TouchBehavior_CurrentTouchStatusChanged"/>
<mct:TouchBehavior CurrentTouchStatusChanged="TouchBehavior_CurrentTouchStatusChanged"/>
private void TouchBehavior_CurrentTouchStatusChanged(object sender, TouchStatusChangedEventArgs e)
{
if (e.Status != TouchStatus.Started)
{
return;
}

((MainPageViewModel)this.BindingContext).TapCommand.Execute(null);
}
private void TouchBehavior_CurrentTouchStatusChanged(object sender, TouchStatusChangedEventArgs e)
{
if (e.Status != TouchStatus.Started)
{
return;
}

((MainPageViewModel)this.BindingContext).TapCommand.Execute(null);
}
That's my current mess, I tried different events, but with no luck - I accidentally found a way to fire my Command on ButtonUp and ButtonDown (TouchStatus), that's it^^ Apparently nobody seems to have an answer 😦
Absent_Reality
Absent_Reality4mo ago
Tbh, I do not know, am still new to programming. Someone else may have a better idea. I'm looking at something sort of similar. I'm trying to track multi finger touch position. From what I've read, skia sharp had a way to do so, but I haven't tried yet. Not sure if what you are wanting would be in there or not. https://learn.microsoft.com/en-us/samples/dotnet/maui-samples/skiasharpmaui-demos/
.NET MAUI - SkiaSharp - Code Samples
This sample demonstrates the use of SkiaSharp in a .NET MAUI app.
Absent_Reality
Absent_Reality4mo ago
My apologies, that wasn't much of a link
Absent_Reality
Absent_Reality4mo ago
GitHub
GitHub - nor0x/TouchTracking.MAUI: Behavior providing a unified API...
Behavior providing a unified API for (multi-)touch gestures in .NET MAUI - nor0x/TouchTracking.MAUI
SpReeD
SpReeDOP4mo ago
Can't actually believe it, but yeah, that's it!
private void TouchTrackingBehavior_TouchAction(object sender, TouchActionEventArgs e)
{
if (e.Type == TouchActionType.Pressed)
{
((MainPageViewModel)this.BindingContext).TapCommand.Execute(null);
}
}
private void TouchTrackingBehavior_TouchAction(object sender, TouchActionEventArgs e)
{
if (e.Type == TouchActionType.Pressed)
{
((MainPageViewModel)this.BindingContext).TapCommand.Execute(null);
}
}
What's so unbelievable is that it's not natively supported and only found in an unfinished/alpha state fork. But that's MAUI waui ¯\_(ツ)_/¯ Thanks a lot!
Want results from more Discord servers?
Add your server