Skip to content

Instantly share code, notes, and snippets.

@brinsche
Last active June 9, 2024 18:01
Show Gist options
  • Save brinsche/770061fa555a9310a07b3416f2d3411b to your computer and use it in GitHub Desktop.
Save brinsche/770061fa555a9310a07b3416f2d3411b to your computer and use it in GitHub Desktop.
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