adapt NestedScrollableHost to changed touchSlope

This commit is contained in:
Matthieu 2021-05-10 16:04:06 +02:00
parent aa985edbd5
commit bb4842ff28
2 changed files with 11 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.view.GravityCompat
import androidx.core.view.NestedScrollingChild
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.paging.ExperimentalPagingApi
@ -42,6 +43,7 @@ import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader
import com.mikepenz.materialdrawer.util.DrawerImageLoader
import com.mikepenz.materialdrawer.widget.AccountHeaderView
import org.ligi.tracedroid.sending.sendTraceDroidStackTracesIfExist
import org.pixeldroid.app.posts.NestedScrollableHost
import retrofit2.HttpException
import java.io.IOException
@ -281,7 +283,7 @@ class MainActivity : BaseActivity() {
val touchSlopField = RecyclerView::class.java.getDeclaredField("mTouchSlop")
touchSlopField.isAccessible = true
val touchSlop = touchSlopField.get(recyclerView) as Int
touchSlopField.set(recyclerView, touchSlop*2)
touchSlopField.set(recyclerView, touchSlop*NestedScrollableHost.touchSlopModifier)
}
private fun setupTabs(tab_array: List<() -> Fragment>){

View File

@ -94,11 +94,12 @@ class NestedScrollableHost : ConstraintLayout {
val isVpHorizontal = orientation == ORIENTATION_HORIZONTAL
// assuming ViewPager2 touch-slop is 2x touch-slop of child
val scaledDx = dx.absoluteValue * if (isVpHorizontal) .5f else 1f
val scaledDy = dy.absoluteValue * if (isVpHorizontal) 1f else .5f
val scaledDx = dx.absoluteValue * if (isVpHorizontal) .5f/ touchSlopModifier else 1f
val scaledDy = dy.absoluteValue * if (isVpHorizontal) 1f else .5f/touchSlopModifier
if(dx.absoluteValue * .5f > touchSlop || scaledDy > touchSlop) doubleTapCallback?.invoke(false)
if (scaledDx > touchSlop || scaledDy > touchSlop) {
doubleTapCallback?.invoke(false)
if (isVpHorizontal == (scaledDy > scaledDx)) {
// Gesture is perpendicular, allow all parents to intercept
@ -116,4 +117,8 @@ class NestedScrollableHost : ConstraintLayout {
}
}
}
companion object {
const val touchSlopModifier = 2
}
}