https://kotlinlang.org logo
#compose
Title
# compose
t

tjohnn

07/25/2020, 5:43 PM
A simple gridview implementation with compose, anyone?
t

Timo Drick

07/25/2020, 6:57 PM
Here very basic but easy to adjust for your needs:
Copy code
@Composable
fun <T>ViewTableList(columns: Int = 2, item: List<T>, itemCallback: @Composable() (T) -> Unit) {
    key(item, columns) {
        LazyColumnItems(items = item.chunked(columns)) { rowList ->
            Row {
                rowList.forEach {
                    itemCallback(it)
                }
                val emptyRows = (columns - rowList.size)
                repeat(emptyRows) {
                    Spacer(modifier = Modifier.weight(1f))
                }
            }
        }
    }
}
t

tjohnn

07/25/2020, 9:26 PM
Thanks.
2 Views