The SwipeGestureRecognizer is not working on the android platform and I found a lot of threads related to that.
I found an alternative solution here and this is the corresponding thread. All the swipes are implemented using a SwipeListener.cs and ISwipeCallBack.cs. But it is only work with a label, when I tried it with a listview the swipe events are not firing.
Here is my sample project to reproduce the issue.
This solution is an old on, so something on the implementation is deprecated, I can't understand what it is. Is there any way to make the swipe work for listviews?
SwipeListener.cs
using System;
using Xamarin.Forms;
namespace SwipeLib
{
public class SwipeListener : PanGestureRecognizer
{
private ISwipeCallBack mISwipeCallback;
private double translatedX = 0, translatedY = 0;
public SwipeListener(View view, ISwipeCallBack iSwipeCallBack)
{
mISwipeCallback = iSwipeCallBack;
var panGesture = new PanGestureRecognizer();
panGesture.PanUpdated += OnPanUpdated;
view.GestureRecognizers.Add(panGesture);
}
void OnPanUpdated(object sender, PanUpdatedEventArgs e)
{
View Content = (View)sender;
switch (e.StatusType) {
case GestureStatus.Running:
try {
translatedX = e.TotalX;
translatedY = e.TotalY;
} catch (Exception err) {
System.Diagnostics.Debug.WriteLine("" + err.Message);
}
break;
case GestureStatus.Completed:
System.Diagnostics.Debug.WriteLine("translatedX : " + translatedX);
System.Diagnostics.Debug.WriteLine("translatedY : " + translatedY);
if (translatedX < 0 && Math.Abs(translatedX) > Math.Abs(translatedY)) {
mISwipeCallback.onLeftSwipe(Content);
} else if (translatedX > 0 && translatedX > Math.Abs(translatedY)) {
mISwipeCallback.onRightSwipe(Content);
} else if (translatedY < 0 && Math.Abs(translatedY) > Math.Abs(translatedX)) {
mISwipeCallback.onTopSwipe(Content);
} else if (translatedY > 0 && translatedY > Math.Abs(translatedX)) {
mISwipeCallback.onBottomSwipe(Content);
} else {
mISwipeCallback.onNothingSwiped(Content);
}
break;
}
}
}
}
ISwipeCallBack.cs
using System;
using Xamarin.Forms;
namespace SwipeLib
{
public interface ISwipeCallBack
{
void onLeftSwipe(View view);
void onRightSwipe(View view);
void onTopSwipe(View view);
void onBottomSwipe(View view);
void onNothingSwiped(View view);
}
}