Is there different behaviour for modifier weight r...
# compose-ios
c
Is there different behaviour for modifier weight rounding on iOS than Android? I'm getting different layouts between platforms when using many elements (80 equal weights in a Row). Curious if this sounds familiar before I dive deeper into it
For example, these render differently on iOS and Android:
Copy code
@Composable
fun Example() {
    val colors = listOf(Color.DarkGray, Color.LightGray)
    val height = 32.dp
    val n = 72
    Column(Modifier.fillMaxWidth()) {

        // Weights
        Row(Modifier.fillMaxWidth()) {
            for (i in 0 until n) {
                Box(Modifier.weight(1f).height(height).background(colors[i.mod(2)])) {}
            }
        }

        // size.width / n
        Box(modifier = Modifier.fillMaxWidth().drawWithCache {
            val segmentWidth = size.width / (n)
            onDrawBehind {
                for (i in 0 until n) {
                    drawRect(
                        color = colors[i.mod(2)],
                        topLeft = Offset(i * segmentWidth, 0f),
                        size = Size(width = segmentWidth, height = height.toPx())
                    )
                }
            }
        })
    }
}
Though now I'm wondering if it's just a bit of luck that the two methods are aligned on Android (device size, density, etc). Perhaps the segment width on the canvas should implement the same rounding logic as the modifier.weight() under the hood
j
Could you attach screenshots of the difference between iOS and Android?