Forked from AlShevelev/gist:ea43096e8f66b0ec45a0ec0dd1e8cacc
Created
May 13, 2024 07:14
-
-
Save mrhungnq95/62bea00ce23e6750ec46b159ec0a9322 to your computer and use it in GitHub Desktop.
ViewPager2 extension for reducing drag sensitivity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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