EverythingMe / overscroll-decor

Android: iOS-like over-scrolling effect applicable over almost all scrollable Android views.
BSD 2-Clause "Simplified" License
2.85k stars 400 forks source link

ViewPager2 Support? #76

Open SamStenner opened 4 years ago

SamStenner commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

For Java:

if (viewPager2.getChildAt(0) instanceof RecyclerView) {
    OverScrollDecoratorHelper.setUpOverScroll((RecyclerView) viewPager2.getChildAt(0), OverScrollDecoratorHelper.ORIENTATION_HORIZONTAL);
}
forceporquillo commented 3 years ago
// 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!