adapt NestedScrollableHost to changed touchSlope
This commit is contained in:
parent
aa985edbd5
commit
bb4842ff28
|
@ -11,6 +11,7 @@ import android.widget.ImageView
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.GravityCompat
|
import androidx.core.view.GravityCompat
|
||||||
|
import androidx.core.view.NestedScrollingChild
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.paging.ExperimentalPagingApi
|
import androidx.paging.ExperimentalPagingApi
|
||||||
|
@ -42,6 +43,7 @@ import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader
|
||||||
import com.mikepenz.materialdrawer.util.DrawerImageLoader
|
import com.mikepenz.materialdrawer.util.DrawerImageLoader
|
||||||
import com.mikepenz.materialdrawer.widget.AccountHeaderView
|
import com.mikepenz.materialdrawer.widget.AccountHeaderView
|
||||||
import org.ligi.tracedroid.sending.sendTraceDroidStackTracesIfExist
|
import org.ligi.tracedroid.sending.sendTraceDroidStackTracesIfExist
|
||||||
|
import org.pixeldroid.app.posts.NestedScrollableHost
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
|
@ -281,7 +283,7 @@ class MainActivity : BaseActivity() {
|
||||||
val touchSlopField = RecyclerView::class.java.getDeclaredField("mTouchSlop")
|
val touchSlopField = RecyclerView::class.java.getDeclaredField("mTouchSlop")
|
||||||
touchSlopField.isAccessible = true
|
touchSlopField.isAccessible = true
|
||||||
val touchSlop = touchSlopField.get(recyclerView) as Int
|
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>){
|
private fun setupTabs(tab_array: List<() -> Fragment>){
|
||||||
|
|
|
@ -94,11 +94,12 @@ class NestedScrollableHost : ConstraintLayout {
|
||||||
val isVpHorizontal = orientation == ORIENTATION_HORIZONTAL
|
val isVpHorizontal = orientation == ORIENTATION_HORIZONTAL
|
||||||
|
|
||||||
// assuming ViewPager2 touch-slop is 2x touch-slop of child
|
// assuming ViewPager2 touch-slop is 2x touch-slop of child
|
||||||
val scaledDx = dx.absoluteValue * if (isVpHorizontal) .5f else 1f
|
val scaledDx = dx.absoluteValue * if (isVpHorizontal) .5f/ touchSlopModifier else 1f
|
||||||
val scaledDy = dy.absoluteValue * if (isVpHorizontal) 1f else .5f
|
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) {
|
if (scaledDx > touchSlop || scaledDy > touchSlop) {
|
||||||
doubleTapCallback?.invoke(false)
|
|
||||||
|
|
||||||
if (isVpHorizontal == (scaledDy > scaledDx)) {
|
if (isVpHorizontal == (scaledDy > scaledDx)) {
|
||||||
// Gesture is perpendicular, allow all parents to intercept
|
// Gesture is perpendicular, allow all parents to intercept
|
||||||
|
@ -116,4 +117,8 @@ class NestedScrollableHost : ConstraintLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val touchSlopModifier = 2
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue