Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mrhungnq95/62bea00ce23e6750ec46b159ec0a9322 to your computer and use it in GitHub Desktop.

Select an option

Save mrhungnq95/62bea00ce23e6750ec46b159ec0a9322 to your computer and use it in GitHub Desktop.
ViewPager2 extension for reducing drag sensitivity
/**
* Reduces drag sensitivity of [ViewPager2] widget
*/
fun ViewPager2.reduceDragSensitivity() {
val recyclerViewField = ViewPager2::class.java.getDeclaredField("mRecyclerView")
recyclerViewField.isAccessible = true
val recyclerView = recyclerViewField.get(this) as RecyclerView
val touchSlopField = RecyclerView::class.java.getDeclaredField("mTouchSlop")
touchSlopField.isAccessible = true
val touchSlop = touchSlopField.get(recyclerView) as Int
touchSlopField.set(recyclerView, touchSlop*8) // "8" was obtained experimentally
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment