airbnb / epoxy

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

Carousel padding values #349

Closed josh-burton closed 6 years ago

josh-burton commented 6 years ago

The Carousel seems to only support one padding value which affects all sides.

It would be great to be able to specify padding values for top, left, bottom and right.

elihart commented 6 years ago

Noted. I would like to avoid having too many different methods for setting padding, but I think we can support this by having another setPadding overload that passes a custom object as a param - that object can specify padding in each direction (in either px, dp, or dimenRes) as well as item spacing

vikrama commented 6 years ago

I have this class that removes the top & bottom padding from the horizontal recyclerview and it seems to be working fine.

class JobCarouselModel: CarouselModel_() {
    override fun onViewAttachedToWindow(view: Carousel?) {
        super.onViewAttachedToWindow(view)
        val pad = view?.context?.resources?.getDimensionPixelSize(R.dimen.padding_base) ?: 0
        view?.setPadding(pad, 0, pad ,0)
    }
}

and adding it this way:

JobCarouselModel().paddingRes(R.dimen.padding_base).id("jobs").models(models)

The above will continue to give the item spacing for the elements in recyclerview. But I wish it was easier than creating a custom model just to support our padding requirements.

elihart commented 6 years ago

I should have a solution up tomorrow

elihart commented 6 years ago

This is what I have in mind https://github.com/airbnb/epoxy/pull/369

elihart commented 6 years ago

Merged

vikrama commented 6 years ago

Thanks. Does the new method also propagate to the CarouselModel? Is it possible to do? ```CarouselModel().padding(Padding(....))```

elihart commented 6 years ago

Yes, notice it is annotated with @ModelProp

vikrama commented 6 years ago

Cool, thanks again. Closed.