Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/softlion/XamarinFormsGesture

Xamarin Form Gesture Effects
https://github.com/softlion/XamarinFormsGesture

android double-tap gesture ios long-press swipe tap uwp xamarin-forms

Last synced: 29 days ago
JSON representation

Xamarin Form Gesture Effects

Awesome Lists containing this project

README

        

# New version for MAUI here: https://github.com/vapolia/MauiGestures/

### Below is version for Xamarin.Forms

[![Build status](https://ci.appveyor.com/api/projects/status/8t8m8n0do3p0304n?svg=true)](https://ci.appveyor.com/project/softlion/xamarinformsgesture)

[![NuGet](https://img.shields.io/nuget/v/Vapolia.XamarinFormsGesture.svg?style=for-the-badge)](https://www.nuget.org/packages/Vapolia.XamarinFormsGesture/)
[![NuGet](https://img.shields.io/nuget/vpre/Vapolia.XamarinFormsGesture.svg?style=for-the-badge)](https://www.nuget.org/packages/Vapolia.XamarinFormsGesture/)
![Nuget](https://img.shields.io/nuget/dt/Vapolia.XamarinFormsGesture)

# Supported Platforms

iOS, Android, UWP

# Xamarin Form Gesture Effects

Add "advanced" gestures to Xamarin Forms. Available on all views.
Most gesture commands include the event position.

```xaml

```
Or in code:
```csharp
var label = new Label();
Vapolia.Lib.Ui.Gesture.SetTapCommand(label, new Command(() => { /*your code*/ }));
```

# Quick start
Add the above nuget package to your Xamarin Forms project (only the netstandard one is enough).

In your platform projects (android,ios,uwp), before initializing xamarin forms, call `Vapolia.Lib.Effects.PlatformGestureEffect.Init();` to force the discovery of this extension by the Xamarin Forms plugin engine.

The views on which the gesture is applied should have the property **IsEnabled="True"** and **InputTransparent="False"** which activates user interaction on them.

# Examples

Add Gesture.TapCommand on any supported xaml view:
```xaml



```
Declare the corresponding namespace:
```xaml

```
And in the viewmodel:
```csharp
public Command OpenLinkCommand => new Command(() =>
{
//do something
});
```
# Supported Gestures

* `TapCommand (ICommand)`
* `DoubleTapCommand (ICommand)`
* `PanCommand (ICommand)`
* `LongPressCommand (ICommand)`
* `TapPointCommand (ICommand or Command)` where point is the absolute tap position relative to the view
* `DoubleTapPoinCommand (ICommand or Command)` where point is the absolute double tap position relative to the view
* `PanPointCommand (ICommand or Command)` where point is the absolute position relative to the view
* `LongPressPointCommand (ICommand or Command) ` where point is the absolute tap position relative to the view
* `SwipeLeftCommand`
* `SwipeRightCommand`
* `SwipeTopCommand`
* `SwipeBottomCommand`
* `PinchCommand (Command)` where `PinchEventArg` contains `StartingPoints`, `CurrentPoints`, `Center`, `Scale`, `RotationRadians`, `RotationDegrees`, `Status`

Properties:

* `IsPanImmediate` Set to true to receive the PanCommand or PanPointCommand event on touch down, instead of after a minimum move distance. Default to false.

# Examples

## Somme commands in XAML

```xml

```

In the viewmodel:

```csharp
public ICommand OpenCommand => new Command(async () =>
{
//...
});

public ICommand OpenPointCommand => new Command(point =>
{
PanX = point.X;
PanY = point.Y;
//...
});

public ICommand PanPointCommand => new Command(args =>
{
var point = args.Point;
PanX = point.X;
PanY = point.Y;
//...
});

```

## Exemple in C# on a Grid containing an horizontal slider (set value on tap)

```csharp
//Tap anywhere to set value
Gesture.SetTapPointCommand(this, new Command(pt =>
{
var delta = (pt.X - Padding.Left) / (Width - Padding.Left - Padding.Right);
if(delta<0 || delta>1)
return;
Value = (int)Math.Round((Maximum - Minimum) * delta);
}));
```

# Limitations

Only commands are supported (PR welcome for events). No .NET events.
So you must use the MVVM pattern (https://developer.xamarin.com/guides/xamarin-forms/xaml/xaml-basics/data_bindings_to_mvvm/).

Swipe commands are not supported on UWP due to a bug (event not received). If you find it, notify me!
PinchCommand is not supported (yet) on UWP. PR welcome.

If your command is not receiving events, make sure that:
- you used the correct handler. Ie: the `LongPressPointCommand` should be `new Command(pt => ...)`
- you set IsEnabled="True" and InputTransparent="False" on the element

UWP requires fall creator update

# Breaking changes

Version 3.3.3 has breaking changes:
- Point commands now gives a `PointEventArgs` instead of a Point. ie: `Command`
- Initialization namespace is unified across platforms: `Vapolia.Lib.Effects.PlatformGestureEffect.Init();`

Version 3.3.0 has breaking changes:
- Command names have changed
- PanPointCommand returns an absolute position, not a relative position anymore. It also returns the gesture state. The gesture can also be cancelled.