AppoMobi.Maui.Gestures 1.2.1.1

dotnet add package AppoMobi.Maui.Gestures --version 1.2.1.1
NuGet\Install-Package AppoMobi.Maui.Gestures -Version 1.2.1.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AppoMobi.Maui.Gestures" Version="1.2.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AppoMobi.Maui.Gestures --version 1.2.1.1
#r "nuget: AppoMobi.Maui.Gestures, 1.2.1.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AppoMobi.Maui.Gestures as a Cake Addin
#addin nuget:?package=AppoMobi.Maui.Gestures&version=1.2.1.1

// Install AppoMobi.Maui.Gestures as a Cake Tool
#tool nuget:?package=AppoMobi.Maui.Gestures&version=1.2.1.1

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.

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:

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
<Label Text="Hello World!" 
	    touch:TouchEffect.CommandLongPressing="{Binding Source={x:Reference ThisPage}, Path=BindingContext.CommandGoToAnotherPage}" 
	    touch:TouchEffect.CommandTapped="{Binding Source={x:Reference ThisPage}, Path=BindingContext.CommandGoToAnotherPage}" 
	    touch:TouchEffect.CommandTappedParameter="{Binding .}" />

Code behind
TouchEffect.SetCommandTapped(tabItem, TabItemTappedCommand);
TouchEffect.SetCommandTappedParameter(tabItem, selectedIndex);

Enhanced Usage

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:

    <draw:Canvas
        touch:TouchEffect.ForceAttach="True">

or

 TouchEffect.SetForceAttach(myView, true);

Now you need to implement a buil-it interface IGestureListener in your custom control:

    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 static property TouchEffect.Density is used internally 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

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.
TouchEffect.TappedWhenMovedThresholdPoints = 10f;
  • How much milliseconds to wait until LongPressing is triggered.
TouchEffect.LongPressTimeMsDefault = 1500;
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-android33.0 is compatible.  net7.0-ios was computed.  net7.0-ios16.1 is compatible.  net7.0-maccatalyst was computed.  net7.0-maccatalyst16.1 is compatible.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net7.0-windows10.0.19041 is compatible.  net8.0 is compatible.  net8.0-android was computed.  net8.0-android34.0 is compatible.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-ios17.2 is compatible.  net8.0-maccatalyst was computed.  net8.0-maccatalyst17.2 is compatible.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net8.0-windows10.0.19041 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on AppoMobi.Maui.Gestures:

Package Downloads
AppoMobi.Maui.DrawnUi

Cross-platform rendering engine for .NET MAUI to draw your UI with SkiaSharp

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.1.1 39 5/12/2024
1.0.8.4 229 4/3/2024
1.0.8.3 86 4/3/2024
1.0.8.2 253 3/4/2024
1.0.5.3 1,131 1/20/2024
1.0.5.2 298 1/10/2024
1.0.5.1 203 1/10/2024
1.0.5 221 1/7/2024
1.0.4.18 167 1/4/2024
1.0.4.10 107 12/29/2023
1.0.4.9 88 12/29/2023
1.0.4.1-pre 700 11/20/2023
1.0.3.1-pre 529 10/23/2023
1.0.1.3 585 9/7/2023
1.0.1.2-pre 257 6/25/2023
1.0.1.1-pre 104 6/17/2023