Created
August 19, 2021 16:51
-
-
Save abhishekBansal/fbd5b023787d1b575aad2baab1293f5e to your computer and use it in GitHub Desktop.
This file contains 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
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