open class Carousel : EpoxyRecyclerView
This feature is in Beta - please report bugs, feature requests, or other feedback at https://github.com/airbnb/epoxy by creating a new issue. Thanks!
This is intended as a plug and play "Carousel" view - a Recyclerview with horizontal scrolling. It comes with common defaults and performance optimizations and can be either used as a top level RecyclerView, or nested within a vertical recyclerview.
This class provides:
1. Automatic integration with Epoxy. A CarouselModel_ is generated from this class, which you can use in your EpoxyController. Just call #setModels(List) to provide the list of models to show in the carousel.
2. Default padding for carousel peeking, and an easy way to change this padding -
3. Easily control how many items are shown on screen in the carousel at a time -
4. Easy snap support. By default a LinearSnapHelper is used, but you can set a global default for all Carousels with #setDefaultGlobalSnapHelperFactory(SnapHelperFactory)
5. All of the benefits of EpoxyRecyclerView
If you need further flexibility you can subclass this view to change its width, height, scrolling direction, etc. You can annotate a subclass with ModelView to generate a new EpoxyModel.
open class Padding
Used to specify individual padding values programmatically. |
|
abstract class SnapHelperFactory
Provide a SnapHelper implementation you want to use with a Carousel. |
Carousel(context: Context!)Carousel(context: Context!, attrs: AttributeSet?)Carousel(context: Context!, attrs: AttributeSet?, defStyle: Int) |
static val NO_VALUE_SET: Int |
val spacingDecorator: EpoxyItemSpacingDecorator |
open fun clear(): Unit |
|
open fun getDefaultSpacingBetweenItemsDp(): Int
Return the item spacing to use in this carousel, or 0 for no spacing. |
|
open fun getNumViewsToShowOnScreen(): Float |
|
open fun getSnapHelperFactory(): Carousel.SnapHelperFactory?
Return a |
|
open fun init(): Unit |
|
open fun onChildAttachedToWindow(child: View): Unit |
|
open fun onChildDetachedFromWindow(child: View): Unit |
|
open static fun setDefaultGlobalSnapHelperFactory(factory: Carousel.SnapHelperFactory?): Unit
Set a |
|
open static fun setDefaultItemSpacingDp(dp: Int): Unit
Set a global default to use as the item spacing for all Carousels. Set to 0 for no item spacing. |
|
open fun setHasFixedSize(hasFixedSize: Boolean): Unit |
|
open fun setInitialPrefetchItemCount(numItemsToPrefetch: Int): Unit
If you are using a Linear or Grid layout manager you can use this to set the item prefetch count. Only use this if you are not using |
|
open fun setModels(models: List<EpoxyModel<*>>): Unit |
|
open fun setNumViewsToShowOnScreen(viewCount: Float): Unit
Set the number of views to show on screen in this carousel at a time, partial numbers are allowed. |
|
open fun setPadding(padding: Carousel.Padding?): Unit
Use the |
|
open fun setPaddingDp(paddingDp: Int): Unit
Set a DP value to use as the padding on each side of the carousel and in between carousel items. |
|
open fun setPaddingRes(paddingRes: Int): Unit
Set a dimension resource to specify the padding value to use on each side of the carousel and in between carousel items. |
fun <T : EpoxyModel<*>, U : ViewMetadata?, P : PreloadRequestHolder> addPreloader(maxPreloadDistance: Int = 3, errorHandler: PreloadErrorHandler, preloader: EpoxyModelPreloader<T, U, P>, requestHolderFactory: () -> P): Unit
Setup a preloader to fetch content for a model's view before it is bound. This can be called multiple times if you would like to add separate preloaders for different models or content types. |
|
fun buildModelsWith(callback: EpoxyRecyclerView.ModelBuilderCallback): Unit
Allows you to build models via a callback instead of needing to create a new EpoxyController class. This is useful if your models are simple and you would like to simply declare them in your activity/fragment. |
|
fun clearPreloaders(): Unit
Clears all preloaders added with addPreloader |
|
open fun createLayoutManager(): LayoutManager
Create a new androidx.recyclerview.widget.RecyclerView.LayoutManager instance to use for this RecyclerView. |
|
open fun createViewPool(): RecycledViewPool
Create a new instance of a view pool to use with this recyclerview. By default a [ ] is used. |
|
fun dpToPx(dp: Int): Int |
|
open fun onAttachedToWindow(): Unit |
|
open fun onDetachedFromWindow(): Unit |
|
open fun requestLayout(): Unit |
|
fun requestModelBuild(): Unit
Request that the currently set EpoxyController has its models rebuilt. You can use this to avoid saving your controller as a field. |
|
fun resToPx(itemSpacingRes: Int): Int |
|
open fun setAdapter(adapter: Adapter<*>?): Unit |
|
fun setController(controller: EpoxyController): Unit
Set an EpoxyController to populate this RecyclerView. This does not make the controller build its models, that must be done separately via requestModelBuild. |
|
fun setControllerAndBuildModels(controller: EpoxyController): Unit
Set an EpoxyController to populate this RecyclerView, and tell the controller to build models. |
|
fun setDelayMsWhenRemovingAdapterOnDetach(delayMsWhenRemovingAdapterOnDetach: Int): Unit
If .setRemoveAdapterWhenDetachedFromWindow is set to true, this is the delay in milliseconds between when .onDetachedFromWindow is called and when the adapter is actually removed. |
|
fun setItemSpacingDp(dp: Int): Unit |
|
open fun setItemSpacingPx(spacingPx: Int): Unit
Set a pixel value to use as spacing between items. If this is a positive number an item decoration will be added to space all items this far apart from each other. If the value is 0 or negative no extra spacing will be used, and any previous spacing will be removed. |
|
fun setItemSpacingRes(itemSpacingRes: Int): Unit |
|
open fun setLayoutManager(layout: LayoutManager?): Unit |
|
open fun setLayoutParams(params: LayoutParams): Unit |
|
fun setRemoveAdapterWhenDetachedFromWindow(removeAdapterWhenDetachedFromWindow: Boolean): Unit
If set to true, any adapter set on this recyclerview will be removed when this view is detached from the window. This is useful to prevent leaking a reference to this RecyclerView. This is useful in cases where the same adapter can be used across multiple views (views which can be destroyed and recreated), such as with fragments. In that case the adapter is not necessarily cleared from previous RecyclerViews, so the adapter will continue to hold a reference to those views and leak them. More details at https://github.com/airbnb/epoxy/wiki/Avoiding-Memory-Leaks#parent-view |
|
open fun shouldShareViewPoolAcrossContext(): Boolean
To maximize view recycling by default we share the same view pool across all instances in the same Activity. This behavior can be disabled by returning false here. |
|
open fun swapAdapter(adapter: Adapter<*>?, removeAndRecycleExistingViews: Boolean): Unit |
|
fun withModels(buildModels: EpoxyController.() -> Unit): Unit
The simplest way to add models to the RecyclerView without needing to create an EpoxyController. This is intended for Kotlin usage, and has the EpoxyController as the lambda receiver so models can be added easily. |