Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private fun isSwipeAllowed(event: MotionEvent): Boolean {
if (direction === SwipeDirection.ALL) return true
if (direction == SwipeDirection.NONE) //disable any swipe
return false
if (event.action == MotionEvent.ACTION_DOWN) {
initialXValue = event.x
return true
}
if (event.action == MotionEvent.ACTION_MOVE) {
try {
val diffX: Float = event.x - initialXValue
if (diffX > 0 && direction == SwipeDirection.RIGHT) {
// swipe from left to right detected
return false
} else if (diffX < 0 && direction == SwipeDirection.LEFT) {
// swipe from right to left detected
return false
}
} catch (exception: Exception) {
exception.printStackTrace()
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment