Any `SubcomposeLayout` specialists here? Trying to...
# compose
a
Any
SubcomposeLayout
specialists here? Trying to get the height of an inner child, code in 🧵
Suppose I have the following code:
Copy code
TopAppBar(
    modifier = Modifier
        .onSizeChanged { topAppBarSize = it },
    title = {
        Text(
            modifier = Modifier
                .fillMaxWidth()
                .wrapContentHeight()
                .onSizeChanged { appBarTitleSize = it }
                .onGloballyPositioned { appBarTitlePos = it.positionInRoot() }
        )
    }
)
I now want to optimize a layout using
SubcomposeLayout
to get rid of the
onSizeChanged
and
onGloballyPositioned
modifiers, because other composables require these values for their layout and I don't want to go through multiple composition passes. The trouble comes when I require both the size of the outer layout (
TopAppBar
), which is easy to measure by just `subcompose`ing it, but also the size and global position of the inner child (
Text
), which I cannot just
subcompose
because it's contained inside the
TopAppBar
layout. My approach would be to figure out the constraints for the
Text
(not sure yet how though) and then subcompose the text next to the
TopAppBar
Is there maybe something special that I can do here or some approach that would work better?
a
SubcomposeLayout
gives you the size but doesn't give you the global position so I think you have to use
onGloballyPositioned
anyway.
a
It wouldn't give me the position, that's true, I would have to position it in the
SubcomposeLayout
myself anyways. I guess I might have to build a completely custom layout here
👍 1