Comments (1)
Thanks for your question. The answer is Yes! I add the support for LazyVerticalGrid in Version 0.0.3. I also provide an example of it in the Sample App. You can have a try and let me know if you have any questions!
The Apis are:
fun <T : Any> LazyGridScope.itemPaging(
pagingData: LazyPagingItems<T>,
span: Int,
loadingContent: @Composable (() -> Unit)? = { DefaultLoadingContent() },
noMoreContent: @Composable (() -> Unit)? = { DefaultNoMoreContent() },
errorContent: @Composable ((retry: (() -> Unit)?) -> Unit)? = { retry ->
DefaultErrorContent(
retry
)
},
) {
when (pagingData.loadState.append) {
is LoadState.Loading -> loadingContent?.let { item(span = { GridItemSpan(span) }) { loadingContent() } }
is LoadState.Error -> errorContent?.let { item(span = { GridItemSpan(span) }) { errorContent { pagingData.retry() } } }
is LoadState.NotLoading ->
if (pagingData.loadState.append.endOfPaginationReached && noMoreContent != null) {
item(span = { GridItemSpan(span) }) { noMoreContent() }
}
}
}
fun <T : Any> LazyGridScope.itemsIndexed(
items: LazyPagingItems<T>,
itemContent: @Composable LazyGridItemScope.(index: Int, value: T?) -> Unit
) {
items(items.itemCount) { index ->
itemContent(index, items[index])
}
}
You can use it like that:
@Composable
fun PagingGridScreen(viewModel: MainViewModel = hiltViewModel()) {
val pagerData = viewModel.pager.collectAsLazyPagingItems()
PagingListContainer(pagingData = pagerData) {
LazyVerticalGrid(
columns = GridCells.Fixed(2),
verticalArrangement = Arrangement.spacedBy(10.dp),
horizontalArrangement = Arrangement.spacedBy(10.dp),
contentPadding = PaddingValues(10.dp)
) {
itemsIndexed(pagerData) { index, value ->
Box(
Modifier
.background(if (index.rem(2) == 0) Color.Yellow else Color.Magenta)
.height(128.dp),
contentAlignment = Alignment.Center
) {
Text(text = value.toString())
}
}
if (pagerData.itemCount.rem(2) != 0) {
item { Spacer(Modifier.background(Color.White)) }
}
itemPaging(pagerData, 2)
}
}
}
from compose-paginglist.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from compose-paginglist.