airbnb / epoxy

Epoxy is an Android library for building complex screens in a RecyclerView
https://goo.gl/eIK82p
Apache License 2.0
8.51k stars 728 forks source link

EpoxyViewPager implementation based on ViewPager2? #866

Open atonamy opened 4 years ago

atonamy commented 4 years ago

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?

ColtonIdle commented 4 years ago

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?

kakai248 commented 4 years ago

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()
}
eboudrant commented 4 years ago

@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).

mariobat88 commented 4 years ago

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