What is the best way to force children composable ...
# compose
m
What is the best way to force children composable to be placed in their parents ? I'm struggling with text rotation. I decided to rotate a row containing text instead of rotating each individual texts. I managed to keep proportion by switching width and height with a customer modifier, however I can't figure out how to force children element to stay at the position of their parent.
In the figure below, "This is a test" elements don't keep the same position as their parent which is a row
Copy code
val text = "This is a test"
Row(modifier = Modifier
    .border(2.dp, Color.Gray, RectangleShape)
    .removeRotationSpace()
    .rotate(-90f)
) {
    Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) {
        Text(text = text, color = OmegaColors.TextColor)
        Box(
            modifier = Modifier
                .clip(CircleShape)
                .size(5.dp)
                .background(color = OmegaColors.BrandColor)
                .offset()
        )
    }
    Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) {
        Text(text = text, color = OmegaColors.TextColor)
        Box(
            modifier = Modifier
                .clip(CircleShape)
                .size(5.dp)
                .background(color = OmegaColors.BrandColor)
                .offset()
        )
    }
}

fun Modifier.removeRotationSpace() = layout { measurable, constraints ->
    val placeable = measurable.measure(constraints)
    layout(placeable.height, placeable.width) {
        placeable.place(0, 0)
    }
}
z
What does that look like without rotation?
m
@Zach Klippenstein (he/him) [MOD] without rotation and the removeRotationSpace modifier, it looks like this
I figured it out 🙂
Copy code
fun Modifier.removeRotationSpace(
) = layout { measurable, constraints ->
    val placeable = measurable.measure(constraints)
    val yPos = placeable.width / 2 - placeable.height / 2
    val xPos = yPos * -1
    layout(placeable.height, placeable.width) {
        placeable.place(x = xPos, y = yPos)
    }
}
🙌🏻 1