Thread
#compose
    j

    julioromano

    1 year ago
    Box {
      One()
      Two()
    }
    I have 2 composables inside a
    Box()
    . I’d like the Box to set its size to the size of
    One()
    and I’d also like that
    Two()
    adapts its size to the size of
    One()
    . Is this possible?
    Piotr Prus

    Piotr Prus

    1 year ago
    Could you give us a graphic example?
    j

    julioromano

    1 year ago
    Not really but I can explain with different words:
    Two()
    is the actual Box content (a bunch of Text composables neatly arranged in a few Rows and Columns).
    One()
    is the background image which should fill the the size occupied by
    Two()
    . Right now if I set One()’s modifier to
    fillMaxSize()
    it will expand and take up the whole screen, but I’d just like for it to expand to the same size as
    Two()
    .
    Dominaezzz

    Dominaezzz

    1 year ago
    I think there's a wrapcontent modifier.
    j

    julioromano

    1 year ago
    I’ve tried it but it doesn’t make things any better
    Dominaezzz

    Dominaezzz

    1 year ago
    Why not use the background modifier?
    j

    julioromano

    1 year ago
    Yupp! Just randomly tried that too and it works!
    pavi2410

    pavi2410

    1 year ago
    In order to do that, I would have used ConstrainLayout
    Archie

    Archie

    1 year ago
    you can possibly work around this by either:1. Creating your own Composable:
    Layout(...)
    2. or
    var oneSize by remember { mutableStateOf(IntSize(0, 0)) }
    val dpWidth = with(density) { dropDownSize.width.toDp() }
    val dpHeight = with(density) { dropDownSize.height.toDp() }
    
    Box{ 
       One(modifier = Modifier.onSizeChanged { oneSize = it })
       Two(modifier = Modifier.size(width = dpWidth, height = dpHeight)
    }