https://github.com/taublast/appomobi.maui.gestures
Library for .NET MAUI to handle gestures. To be consumed in Xaml and code-behind.
https://github.com/taublast/appomobi.maui.gestures
gestures maui
Last synced: 9 months ago
JSON representation
Library for .NET MAUI to handle gestures. To be consumed in Xaml and code-behind.
- Host: GitHub
- URL: https://github.com/taublast/appomobi.maui.gestures
- Owner: taublast
- License: mit
- Created: 2023-06-17T07:31:47.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-14T17:58:19.000Z (about 1 year ago)
- Last Synced: 2025-04-14T18:15:27.521Z (about 1 year ago)
- Topics: gestures, maui
- Language: C#
- Homepage:
- Size: 124 KB
- Stars: 12
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# AppoMobi.Maui.Gestures
Library for .NET MAUI to handle gestures. Can be consumed in Xaml and code-behind. A nuget with the same name is available.
This library is used by [DrawnUI for .NET MAUI](https://github.com/taublast/DrawnUi).
.NET 8 and above compatible.
## What's New - 1.9.7
* Changed TAPPED threshold logic to use velocity instead of distance, which removed occasional fake taps while swiping:
```csharp
///
/// How much finger can move between DOWN and UP for the gestured to be still considered as TAPPED. In points, not pixels.
///
public static float TappedVelocityThresholdPoints = 200f;
```
## Features
* Attachable .NET MAUI effect
* Multi-touch
* Customizable touch mode for cooperation with other views
* Report velocity, distance, time, etc
* All data uses pixels on every platform for better precision
## Gestures
* Down/Up
* Tapping
* Longpressing
* Panning
* Rotation
* Zoom
* Mouse wheel on Windows
The philosophy is to have the more platform agnostic code as possible, by processing platform raw input in a shared code. The library is still in development, i am adding more features when i need them myself, so if you feel that something is missing please feel free to leave a message in Discussions or create a PR.
## Installation
Install the package __AppoMobi.Maui.Gestures__ from NuGet.
After that initialize the library in the MauiProgram.cs file:
```csharp
builder.UseGestures();
```
### Basic Usage
Getures are handled by a Maui Effect. You can just attach properties that would invoke your commands or handlers upon a specific gesture.
#### Xaml
```xml
```
#### Code behind
```csharp
TouchEffect.SetCommandTapped(tabItem, TabItemTappedCommand);
TouchEffect.SetCommandTappedParameter(tabItem, selectedIndex);
```
### Enhanced Usage
## Sharing gestures
In some scenarios, inside a scroll and similar other views might interfere with your gestures processing.
A quick remedy:
```xml
touch:TouchEffect.ShareTouch="Lock"
```
this would lick the input for your view once it was initially passed to it.
## Manual processing
You can opt for processing gestures on a lower level yourself, especially if you are creating a custom control. First we just attach the effect with a special property:
```xml
```
or
```csharp
TouchEffect.SetForceAttach(myView, true);
```
Now you need to implement a buil-it interface __IGestureListener__ in your custom control:
```csharp
public interface IGestureListener
{
public void OnGestureEvent(
TouchActionType type,
TouchActionEventArgs args,
TouchActionResult action);
public bool InputTransparent { get; }
}
```
As you might guess __OnGestureEvent__ will be invoked on every touch detected if your __InputTransparent__ is not returning _True_.
The library passes 2 kinds of gesture type, the "raw" `TouchActionType` and the resulting logical `TouchActionResult` that you most probably would use.
__To note__: Since we detect multi-touch you could receive several Down/Up events, the first one would be recognizable with `NumberOfTouches` being at 1.
You will receive all gesture-related data inside `TouchActionEventArgs args`.
When you get a `TouchActionResult.Panning` you could also have the property `ManipulationInfo Manipulation` filled with scale and rotation data. Otherwise expect it to be `null`.
The public static property `TouchEffect.Density` is used to convert pixels/points, you can you it too as all the data you would get will be in pixels, convert it to points/whatever as you please.
#### Hints
* For a case of your custom control sitting inside a ScrollView there is a TouchMode property to be played with. For example you might want to set it to `TouchHandlingStyle.Lock` so that when your control receives the Down event the parent ScrollView stops receiving gestures until we get an Up, so we can Pan our control at will.
* You can close the keyboard programmatically on Android with a
```csharp
TouchEffect.CloseKeyboard();
```
#### Tweaks
Actually we have some static properties for settings.
* How much finger can move between DOWN and UP for the gestured to be still considered as TAPPED. In points, not pixels.
```csharp
public static float TappedVelocityThresholdPoints = 200f;
```
* How much milliseconds to wait until LongPressing is triggered.
```csharp
TouchEffect.LongPressTimeMsDefault = 1500;
```