I'm developing swipe left and right in a custom renderer for android in a xamarin forms project. I have a class that implements an override of method "DispatchTouchEvent(MotionEvent touch)". When MotionEventActions.Up is raised, I do some things. I have implemented a "ItemSelected" event in shared code for my ListView but when I swipe on a element of the listview, it interprets that is a tap and this trigger this event.
How can I differentiate when I tap or swipe in an element?
I have been thinking in differenciate when I swipe in "MotionEventActions.Up" but I don't know how to show a new page from a custom renderer.
This is the code of the renderer:
class SwipeListRenderer : ListViewRenderer
{
bool swipe = false;
bool scroll;
double puntoYinicial = 0.0;
public override bool DispatchTouchEvent(MotionEvent touch)
{
try
{
if (puntoYinicial == 0.0)
puntoYinicial = touch.GetY();
double currentQuota = ((touch.GetX() - TouchDispatcher.StartingBiasX) / (double)this.Width);
float x = touch.GetX();
float y = touch.GetY();
SwipeList.SwipeItemView touchedElement = (TouchDispatcher.TouchingView as SwipeList.SwipeItemView);
switch (touch.ActionMasked)
{
case MotionEventActions.Down:
(this.Element as SwipeList.SwipeListView).RestoreItemPosition();
swipe = false;
scroll = false;
return base.DispatchTouchEvent(touch);
break;
case MotionEventActions.Up:
if (swipe)
touchedElement.CompleteTranslation(currentQuota);
(this.Element as SwipeList.SwipeListView).AppendTouchedElement(touchedElement);
TouchDispatcher.TouchingView = null;
TouchDispatcher.StartingBiasX = 0;
TouchDispatcher.StartingBiasY = 0;
puntoYinicial = 0.0;
break;
case MotionEventActions.Move:
if (touchedElement != null)
TouchDispatcher.TouchingView.PerformTranslation(currentQuota);
break;
}
return base.DispatchTouchEvent(touch);
}
catch (Exception ex)
{
throw;
}
}
}