Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViewPager2 Support? #76

Open
SamStenner opened this issue Jul 14, 2020 · 3 comments
Open

ViewPager2 Support? #76

SamStenner opened this issue Jul 14, 2020 · 3 comments

Comments

@SamStenner
Copy link

Hi, I've noticed only the legacy viewpager is supported. Given this project has recently seen more activity, it would be great to add this. I tried implementing my own ViewPager2OverScrollDecorAdapter by following the basic structure of ViewPagerOverScrollDecorAdapter but it doesn't seem to work. Would be awesome if this could be added.

@vokilam
Copy link

vokilam commented Oct 27, 2020

ViewPager2 is backed by RecyclerView. By knowing this we could implement the following workaround:

// WARN: we use knowledge of internal structure of ViewPager2 to setup overscroll behavior
viewPager2.children.filterIsInstance<RecyclerView>().firstOrNull()?.let {
    OverScrollDecoratorHelper.setUpOverScroll(it, ORIENTATION_VERTICAL)
}

@moisoni97
Copy link

moisoni97 commented Jun 15, 2021

For Java:

if (viewPager2.getChildAt(0) instanceof RecyclerView) {
    OverScrollDecoratorHelper.setUpOverScroll((RecyclerView) viewPager2.getChildAt(0), OverScrollDecoratorHelper.ORIENTATION_HORIZONTAL);
}

@forceporquillo
Copy link

// WARN: we use knowledge of internal structure of ViewPager2 to setup overscroll behavior
viewPager2.children.filterIsInstance<RecyclerView>().firstOrNull()?.let {
    OverScrollDecoratorHelper.setUpOverScroll(it, ORIENTATION_VERTICAL)
}

Perfect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants