Created
October 30, 2017 15:12
-
-
Save MarcosCobena/6305465bfdfd02d939099d1b5b2fd310 to your computer and use it in GitHub Desktop.
A platform-independent implementation of left & right swipe gestures in Xamarin.Forms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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