Skip to content

Instantly share code, notes, and snippets.

@abhishekBansal
Created August 19, 2021 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhishekBansal/fbd5b023787d1b575aad2baab1293f5e to your computer and use it in GitHub Desktop.
Save abhishekBansal/fbd5b023787d1b575aad2baab1293f5e to your computer and use it in GitHub Desktop.
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