open class EpoxyRecyclerView : RecyclerView
A RecyclerView implementation that makes for easier integration with Epoxy. The goal of this class is to reduce boilerplate in setting up a RecyclerView by applying common defaults. Additionally, several performance optimizations are made.
Improvements in this class are:
interface ModelBuilderCallback
A callback for creating models without needing a custom EpoxyController class. Used with buildModelsWith |
EpoxyRecyclerView(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0)
A RecyclerView implementation that makes for easier integration with Epoxy. The goal of this class is to reduce boilerplate in setting up a RecyclerView by applying common defaults. Additionally, several performance optimizations are made. |
val spacingDecorator: EpoxyItemSpacingDecorator |
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. |
|
open fun clear(): Unit
Clear the currently set EpoxyController or Adapter as well as any models that are displayed. |
|
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 init(): Unit |
|
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 |
|
open fun setModels(models: List<EpoxyModel<*>>): Unit
Set a list of EpoxyModel's to show in this RecyclerView. |
|
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. |
fun <T : EpoxyModel<*>, U : ViewMetadata?, P : PreloadRequestHolder> RecyclerView.addEpoxyPreloader(epoxyController: EpoxyController, maxPreloadDistance: Int = 3, errorHandler: PreloadErrorHandler = { context, err -> if (!context.isDebuggable) throw err }, preloader: EpoxyModelPreloader<T, U, P>, requestHolderFactory: () -> P): Unit
Helper to create and add an EpoxyPreloader to this RecyclerView. |
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! |