try making doubletap less sensible

This commit is contained in:
Matthieu 2021-04-20 16:54:57 +02:00
parent e2bbfccda3
commit 349401dee4
2 changed files with 6 additions and 4 deletions

View File

@ -51,7 +51,7 @@ class NestedScrollableHost : ConstraintLayout {
return v as? ViewPager2
}
var doubleTapCallback: ((Unit) -> Unit)? = null
var doubleTapCallback: ((Boolean) -> Unit)? = null
private val child: View? get() = if (childCount > 0) getChildAt(0) else null
@ -79,7 +79,7 @@ class NestedScrollableHost : ConstraintLayout {
if (e.action == MotionEvent.ACTION_DOWN) {
initialX = e.x
initialY = e.y
doubleTapCallback?.invoke(Unit)
doubleTapCallback?.invoke(true)
}
// Early return if child can't scroll in same direction as parent
if (!canChildScroll(orientation, -1f) && !canChildScroll(orientation, 1f)) {
@ -98,6 +98,8 @@ class NestedScrollableHost : ConstraintLayout {
val scaledDy = dy.absoluteValue * if (isVpHorizontal) 1f else .5f
if (scaledDx > touchSlop || scaledDy > touchSlop) {
doubleTapCallback?.invoke(false)
if (isVpHorizontal == (scaledDy > scaledDx)) {
// Gesture is perpendicular, allow all parents to intercept
parent.requestDisallowInterceptTouchEvent(false)

View File

@ -457,7 +457,8 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
//Activate double tap liking
var clicked = false
binding.postPagerHost.doubleTapCallback = {
lifecycleScope.launchWhenCreated {
if(!it) clicked = false
else lifecycleScope.launchWhenCreated {
//Check that the post isn't hidden
if(binding.sensitiveWarning.visibility == View.GONE) {
//Check for double click
@ -480,7 +481,6 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
binding.postPager.handler.postDelayed(fun() { clicked = false }, 500)
}
}
}
}
}