Vsevolod Ganin

    Vsevolod Ganin

    1 year ago
    Is it ok that
    onSizeChanged
    reports size without padding?
    @Preview
    @Composable
    fun Test() {
        val density = AmbientDensity.current
        Box(
            modifier = Modifier
                .padding(with(density) { 50.toDp() })
                .size(with(density) { 50.toDp() })
                .background(Color.Red)
                .onSizeChanged { println(it) }
        )
    }
    I expect this to print
    150 x 150
    , but get
    50 x 50
    instead.
    Lukas Sztefek

    Lukas Sztefek

    1 year ago
    What about this?
    modifier = Modifier
                .onSizeChanged { println(it) }
                .padding(with(density) { 50.toDp() })
                .size(with(density) { 50.toDp() })
                .background(Color.Red)
    Vsevolod Ganin

    Vsevolod Ganin

    1 year ago
    Tried that, still same output
    Replacing
    onSizeChanged { println(it) }
    with
    layout { measurable, constraints ->
                    val placeable = measurable.measure(constraints)
                    println("${placeable.width} x ${placeable.height}")
                    layout(placeable.width, placeable.height) {
                        placeable.place(0, 0)
                    }
                }
    before
    padding
    and
    size
    did the trick. Seems like a bug in
    onSizeChanged
    , I’ll file