Is it even possible to remember LazyColumn scrolling position in such a case?
@Composable
fun ScreenComposable(state: State<ScreenUiState>) {
val stateValue = state.value
val lazyItems: LazyPagingItems<Item> = stateValue.pagingItems.collectAsLazyPagingItems()
LazyColumn {
lazyItems.apply {
when (loadState.refresh) {
is LoadState.NotLoading -> {
for (position in 0 until lazyItems.itemCount) {
item {
ScreenItemComposable()
}
}
}
}
}
}
}
where
data class ScreenUiState(
// inside ViewModel there's pagingItems = getPagedData()
val pagingItems: Flow<PagingData<Item>> = flow { PagingData.empty<Item>() },
)
override fun getPagedData(): Flow<PagingData<Item>> {
return Pager(
PagingConfig(
(...)
),
) {
ScreenPagingSource()
}.flow
}
It's standard Paging3 + Compose implementation, but even if, I haven't found working solution for keeping scroll state. I successfully used verticalScroll(verticalScrollState)
, where verticalScrollState
is kept in ScreenUiState
for Column
composable (without Paging3), but it doesn't work in aforementioned case.
I find it quite complex (and interesting) case, because one have to keep what was Paged already. Otherwise all paging would have to happen once again which is not UX-friendly solution. Maybe Paging should be kept in a Room
local database? Any ideas?