Last active
June 9, 2024 18:01
-
-
Save brinsche/770061fa555a9310a07b3416f2d3411b 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
var lastY = 0f | |
editText.setOnTouchListener { v, event -> | |
v.parent.requestDisallowInterceptTouchEvent(true) | |
when (event.actionMasked) { | |
MotionEvent.ACTION_DOWN -> { | |
// store initial y position | |
lastY = event.y | |
} | |
MotionEvent.ACTION_MOVE -> { | |
val deltaY = event.y - lastY | |
val scrollDirection = if (deltaY < 0) 1 else -1 | |
val canScrollFurther = v.canScrollVertically(scrollDirection) | |
if (canScrollFurther.not()) { | |
v.parent.requestDisallowInterceptTouchEvent(false) | |
} | |
lastY = event.y | |
} | |
MotionEvent.ACTION_UP -> { | |
v.parent.requestDisallowInterceptTouchEvent(false) | |
} | |
} | |
false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment