-
Notifications
You must be signed in to change notification settings - Fork 19
/
SimpleSnapHelper.kt
29 lines (23 loc) · 852 Bytes
/
SimpleSnapHelper.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package cz.intik.overflowindicator
import androidx.recyclerview.widget.PagerSnapHelper
import androidx.recyclerview.widget.RecyclerView
/**
* SnapHelper which allows snapping of pages, customized with notifying of [OverflowPagerIndicator]
* when position is snapped
*
* @author Petr Introvic <[email protected]>
* created 07.10.2017.
*/
class SimpleSnapHelper(private val overflowPagerIndicator: OverflowPagerIndicator) :
PagerSnapHelper() {
override fun findTargetSnapPosition(
layoutManager: RecyclerView.LayoutManager,
velocityX: Int,
velocityY: Int
): Int {
val position = super.findTargetSnapPosition(layoutManager, velocityX, velocityY)
// Notify OverflowPagerIndicator about changed page
overflowPagerIndicator.onPageSelected(position)
return position
}
}