-
Notifications
You must be signed in to change notification settings - Fork 728
Paging Support
Epoxy integrates with the Android Paging Library to load large data sets efficiently.
Paging support is a separate Epoxy module that you must add with
dependencies {
implementation 'com.airbnb.android:epoxy-paging:2.18.0' // Use latest epoxy version here
}
To use it, extend PagedListEpoxyController<T>
and implement fun buildItemModel(currentPosition: Int, item: T?): EpoxyModel<*>
. The T
type parameter represents the type of the list that is being used. Then, call submitList
to set aPagedList
(from the Paging Library) as a data source.
The notify thread of your PagedList (from setNotifyExecutor
in the PagedList Builder) must be the same as the buildModels
thread of your PagedListEpoxyController. Otherwise Epoxy will crash.
PagedListEpoxyController
is written in Kotlin, and works best if used with Kotlin.
The PagedListEpoxyController listens to the PagedList, and intelligently builds models as more data is loaded, or rebuilds models as data changes. Previously built models are cached, so they do not need to be rebuilt when more data pages are loaded.
Epoxy tells the PagedList to load more pages as you scroll. Models can be built and diffed asynchronously be passing EpoxyAsyncUtil#getAsyncBackgroundHandler
when instantiating the controller.
If you would like to mix in other view types, such as headers, you can override addModels
. You can call requestModelBuild
to rebuild these mixed in views whenever you liked (the paged item models are cached and not rebuilt).