From bb4842ff288d4b7aad10b2e80f86a82bccbca233 Mon Sep 17 00:00:00 2001 From: Matthieu <24-artectrex@users.noreply.shinice.net> Date: Mon, 10 May 2021 16:04:06 +0200 Subject: [PATCH] adapt NestedScrollableHost to changed touchSlope --- app/src/main/java/org/pixeldroid/app/MainActivity.kt | 4 +++- .../org/pixeldroid/app/posts/NestedScrollableHost.kt | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/pixeldroid/app/MainActivity.kt b/app/src/main/java/org/pixeldroid/app/MainActivity.kt index 6df31512..77977123 100644 --- a/app/src/main/java/org/pixeldroid/app/MainActivity.kt +++ b/app/src/main/java/org/pixeldroid/app/MainActivity.kt @@ -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>){ diff --git a/app/src/main/java/org/pixeldroid/app/posts/NestedScrollableHost.kt b/app/src/main/java/org/pixeldroid/app/posts/NestedScrollableHost.kt index b76a179d..fa0157d7 100644 --- a/app/src/main/java/org/pixeldroid/app/posts/NestedScrollableHost.kt +++ b/app/src/main/java/org/pixeldroid/app/posts/NestedScrollableHost.kt @@ -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 + } } \ No newline at end of file