Skip to content

Instantly share code, notes, and snippets.

@MarcosCobena
Created October 30, 2017 15:12
Show Gist options
  • Select an option

  • Save MarcosCobena/6305465bfdfd02d939099d1b5b2fd310 to your computer and use it in GitHub Desktop.

Select an option

Save MarcosCobena/6305465bfdfd02d939099d1b5b2fd310 to your computer and use it in GitHub Desktop.
A platform-independent implementation of left & right swipe gestures in Xamarin.Forms
void HandleLeftAndRightSwipeGestures(object sender, Xamarin.Forms.PanUpdatedEventArgs e)
{
    switch (e.StatusType)
    {
        case GestureStatus.Started:
            lastPanStartedX = e.TotalX;
            break;
        case GestureStatus.Running:
            lastPanRunningX = e.TotalX;
            break;
        case GestureStatus.Completed:
            var difference = lastPanRunningX - lastPanStartedX;
            if (Math.Abs(difference) >= ThresholdToFireSwipeGesture)
            {
                if (difference < 0)
                {
                    Carousel.MoveRight();
                }
                else
                {
                    Carousel.MoveLeft();
                }
            }
            lastPanStartedX = 0;
            lastPanRunningX = 0;
            break;
        default:
            break;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment