https://kotlinlang.org logo
a

alorma

10/23/2020, 9:16 AM
Is there a "tab" or GridLayout for compose?
a

allan.conda

10/23/2020, 9:37 AM
there’s TabBar, but no GridLayout. Compose-samples uses
FlowRow
for each row in the grid in a
LazyColumnFor
a

alorma

10/23/2020, 9:39 AM
uhm, experimental...
i will wait then
s

Spikey Sanju

10/23/2020, 11:29 AM
@Composable
fun <T> GridView(
cols: Int = 1,
list: List<T>,
rowModifier: Modifier = Modifier,
colModifier: Modifier = Modifier,
child: @Composable (dataModal: T) -> Unit
) {
val rows = (list.size / cols) + (if (list.size % cols > 0) 1 else 0)
ScrollableColumn {
for (r in 0 until rows) {
Row(modifier = rowModifier, horizontalArrangement = Arrangement.SpaceAround) {
for (cell in 0 until cols) {
val i = (r * cols) + cell
if (i < list.size) {
child(list[i])
} else {
break
}
}
}
}
}
}
I'm currently using this approach 🙂 @alorma
👍 1
a

allan.conda

10/23/2020, 11:31 AM
I use
list.chunked(numColumns).forEach { /* render each item in row */ }
💡 3
z

Zach Klippenstein (he/him) [MOD]

10/23/2020, 3:32 PM
uhm, experimental...
Compose itself is effectively experimental at the moment
3 Views