Stylianos Gakis

    Stylianos Gakis

    10 months ago
    Trying to work on a custom
    Layout()
    . Have some problems with constraints, more in thread 🧵
    Given my code that looks approx like this:
    Layout(
        modifier = Modifier.size(40.dp),
        content = {
            Image(
                painterResource(R.drawable.ic_something_with_24dp_size),
                contentDescription = null,
                modifier = Modifier.size(24.dp)
            )
            Box(modifier = Modifier.size(12.dp)) {}
        },
    ) { measurables, constraints ->
        val image = measurables[0].measure(constraints)
        val circle = measurables[1].measure(constraints)
        // etc.
    }
    What should I do to mage image and circle measure with 24 and 12 dp respectively? Now it gives them both 40.dp size just because the constraints allow it, but I have explicitly given them 24 and 12dp instead.
    I just rubber ducked myself 😅 Setting the constraints as
    val image = measurables[0].measure(constraints.copy(minWidth = 0, minHeight = 0))
    val circle = measurables[1].measure(constraints.copy(minWidth = 0, minHeight = 0))
    Fixes the problem, as before the constraints passed down were min AND max 110 (aka 40.dp). Very interesting that it was like that, it’s probably because the
    .size()
    modifier sets both min and max size for the item.