Alex
10/15/2021, 6:37 PMSubcomposeLayout
specialists here? Trying to get the height of an inner child, code in 🧵Alex
10/15/2021, 6:40 PMTopAppBar(
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?Albert Chang
10/16/2021, 3:41 AMSubcomposeLayout
gives you the size but doesn't give you the global position so I think you have to use onGloballyPositioned
anyway.Alex
10/16/2021, 1:35 PMSubcomposeLayout
myself anyways. I guess I might have to build a completely custom layout here