Thread
#compose
    Nat Strangerweather

    Nat Strangerweather

    1 year ago
    I have a small Box in a big Box. The large Box has a width of
    Modifier.fillMaxWidth
    . The small Box has a width of
    Modifier.fillMaxWidth(1 / 7f)
    . Elsewhere in my code outside my Composable I am defining an animation. There, I need the offset of my small Box to be the same as its width. Is there any way to use
    Modifier.fillMaxWidth
    as a variable? If not, how can I get the right width for my offset?
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    You can use
    Modifier.onSizeChanged
    to get the size of a composable once it’s measured, although the size won’t be available until after the first composition (might be fine depending on your animation). Since your width is also fixed relative to your parent, you could also use
    BoxWithConstraints
    to get the max available width inside your big box and calculate the width for your child yourself (slightly less flexible, but available immediately).
    Nat Strangerweather

    Nat Strangerweather

    1 year ago
    Oh, ok, thanks I will look into that! 🙂
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    I think you might want to take a look at the
    AnimatedVisibility
    code – some of the available transition animations offset a component by its own width, so similar idea.
    Nat Strangerweather

    Nat Strangerweather

    1 year ago
    Nice, I really love Compose! ❤️
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    Me too! 😂