icerockdev / moko-units

Composing units into list and show in RecyclerView/UITableView/UICollectionView. Control your lists from common code for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
25 stars 12 forks source link

Multiple RecyclerView UnitItems #11

Closed mpivchev closed 4 years ago

mpivchev commented 4 years ago

I'd like to implement pagination on the RV, however I am not sure how to add a second unit (or a viewholder) for the loading view , that I then remove when more items are loaded.

Currently I only have a method to create a single ViewHolder (tile)

interface UnitsFactory<T> {
        fun createItemTile(data: T): CollectionUnitItem
    }
Alex009 commented 4 years ago

hi! you can have any units in list wich you sent to adapter. so just add aditional method in unit factory:

interface UnitsFactory<T> {
        fun createItemTile(data: T): CollectionUnitItem
        fun createLoadingTile(): CollectionUnitItem
}

and then just combine this items in List:

myData.map { unitsFactory.createItemTile(it) }.plus(unitsFactory.createLoadingTile())

for example.

also pagination sample with moko-units already exist in moko-paging - https://github.com/icerockdev/moko-paging/blob/master/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/ListViewModel.kt