Is there a way to get the height of a composable? Not the min and max height but the measured height? Code in thread.
Alex
07/05/2021, 5:32 PM
Copy code
BoxWithConstraints {
TopAppBar(
...
)
}
I would like to get the height of the TopAppBar here and store it in a
remember{ mutableStateOf() }
to use in other parts of the code.
d
dimsuz
07/05/2021, 5:32 PM
You can use
Modifier.onGloballyPositioned
➕ 1
b
brandonmcansh
07/05/2021, 6:40 PM
There is a default available for app bar height as well. AppBarDefaults (as long as your not creating your own composable or causing it to grow in height.
brandonmcansh
07/05/2021, 6:40 PM
App bar is generally a static height unless it's being animated
c
cb
07/05/2021, 7:57 PM
Depends why you need the size. If you need the size to influence composition of sibling content you can use
SubcomposeLayout
(
Scaffold
is a good example). If you don't need to influence composition you can use
Layout().
Modifier.onSizeChanged()
or
onGloballyPositioned()
can easily result in composition loops, so should only be used as a last resort and with care.