I have a small Box in a big Box. The large Box has...
# compose
n
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?
z
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).
👍 1
n
Oh, ok, thanks I will look into that! 🙂
z
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.
n
Nice, I really love Compose! ❤️
z
Me too! 😂
😁 1