I'm using ViewPager2 and want to detect when the user swipes either to the left on the first page or the right on the last page.
I know this can be implemented using the old ViewPager
like discussed here, but this approach is not feasible since ViewPager2
is final and can't be subclassed.
ViewPager2
provides the OnPageChangeCallback but this can't be used either since there are no page events when swiping out of bounds.
Am I missing something?
I figured out a (slighly hacky) solution while I was typing this question.
It is based on the observation that the state
SCROLL_STATE_SETTLING
is only reached when the viewpager really settles on a new page. If there is only fruitless dragging on the first or last page then only the statesSCROLL_STATE_DRAGGING
and finallySCROLL_STATE_IDLE
are passed.I'm not entirely happy, but this is the best I came across so far.