Epoxy: EpoxyViewPager implementation based on ViewPager2?

Created on 6 Nov 2019  路  4Comments  路  Source: airbnb/epoxy

Since ViewPager2 is built on RecyclerView component. Maybe is good reason to create EpoxyViewPager view? Which can work with epoxy controllers and immutable models?

I believe is pretty cool idea to bring epoxy to the new level with ViewPager support.

What do you think? Shall we deserve to have EpoxyViewPager together with EpoxyRecyclerVIew?

Most helpful comment

I wrote two extensions that pretty much covered my needs:

inline fun ViewPager2.setController(controller: EpoxyController) {
    adapter = controller.adapter
}

inline fun ViewPager2.setControllerAndBuildModels(controller: EpoxyController) {
    setController(controller)
    controller.requestModelBuild()
}

All 4 comments

Just my 2 cents since I haven't worked with ViewPager 1 or 2, but wouldn't just using an Epoxy Carousel essentially give you what you want here? If ViewPager2 is built on RecyclerView then it doesn't seem necessary to need a ViewPager at all. Is there something specific you require?

I wrote two extensions that pretty much covered my needs:

inline fun ViewPager2.setController(controller: EpoxyController) {
    adapter = controller.adapter
}

inline fun ViewPager2.setControllerAndBuildModels(controller: EpoxyController) {
    setController(controller)
    controller.requestModelBuild()
}

@ColtonIdle my motivation to use the ViewPager2 over RecyclerView in Epoxy would be to have the ability to use the PageTransformer (I think this is the way to do page margin from original ViewPager: https://developer.android.com/reference/androidx/viewpager2/widget/MarginPageTransformer).

Just use the EpoxyController and set the adapter to the ViewPager like you would for a RecyclerView. Works for me!

Was this page helpful?
0 / 5 - 0 ratings