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

Nicolai

12/14/2023, 9:30 AM
I’m doing something wrong here.. I’m trying to make sure that all the columns in my row has the same width and ultimately also fill the available space of the screen. Any input is appreciated 🙏 Code in thread 🧵
Copy code
@Composable
private fun RowScope.ScrollableContent(state: TableUiState, modifier: Modifier) {
    val scrollState: ScrollState = rememberScrollState()

    var width by remember { mutableStateOf(0.dp) }
    Row(
        modifier = modifier
            .background(colors.commonBackground)
            .horizontalScroll(scrollState)
            .weight(1f)
    ) {
        state.items.forEachIndexed { index, tableColumn ->
            val columnModifier = when (width) {
                0.dp -> Modifier
                else -> Modifier.width(width)
            }
            Column(modifier = columnModifier.layout { measurable, constraints ->
                val placeable = measurable.measure(constraints)
                if (placeable.width.dp > width) {
                    width = placeable.width.dp
                }

                // Return the placeable after setting the width
                layout(placeable.width, placeable.height) {
                    placeable.place(0, 0)
                }
            }) {
                tableColumn.items.forEach { tableItem ->
                    TableItemRow(tableItem = tableItem)
                }
            }
        }
    }
}
p

Peter

12/14/2023, 8:25 PM
You can't use
weight(1f)
for every child in your row?
☝️ 1