Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms swipe gesture recognizer

Xamarin.Forms is very new and very exciting, but for now I see that it has limited documentation and a few samples. I'm trying to make an app with an interface similar to the "MasterDetailPage" one, but also having a right Flyout view, not only the left one.

I've seen that this is not possible using the current API, and so my approach was this:

  1. Create a shared GestureRecognizer interface.
  2. In Android app and iOS in bind this interface to the UIGestureRecognizer on iOS or the OnTouch method on the android.

For iOS this is working but for Android the touch listener over the activity doesn't seem to work.

Is my approach good? Maybe there is another good method to capture touch events directly from the shared code? Or do you have any ideas why the public override bool OnTouchEvent doesn't work in an AndroidActivity?

like image 383
Daniel Avatar asked May 30 '14 11:05

Daniel


1 Answers

For Xamarin.Forms swipe gesture recognizer add SwipeGestureRecognizer

<BoxView Color="Teal" ...>
<BoxView.GestureRecognizers>
    <SwipeGestureRecognizer Direction="Left" Swiped="OnSwiped"/>
</BoxView.GestureRecognizers>
</BoxView>

Here is the equivalent C# code:

var boxView = new BoxView { Color = Color.Teal, ... };
var leftSwipeGesture = new SwipeGestureRecognizer { Direction = SwipeDirection.Left };
leftSwipeGesture.Swiped += OnSwiped;

boxView.GestureRecognizers.Add(leftSwipeGesture);

For more check here : https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/gestures/swipe

like image 88
G.Mich Avatar answered Nov 19 '22 07:11

G.Mich