Suppose I have a composable responsible for laying...
# compose
m
Suppose I have a composable responsible for laying out another composable (passed in as an arg). The passed-in composable may be empty or not. If it is empty, then it should take up no space in the layout. If it is not empty, then the layout composable dictates the space that the composable should take up (and it should fillMaxSize). How best to communicate this without passing explicit values?
My initial thoughts are that the passed-in composable should just use
Modifier.fillMaxSize()
when non-empty, and so push the problem over to the layout composable. Perhaps the composable doing the laying out should use
Modifier.layout
in order to discover whether the passed-in composable actually has content, and so, if it does, only then make the necessary calculations regarding what space the passed-in composable should occupy.
z
We typically make those kind of composable parameters nullable
The only other way to know for sure is to use subcomposition, but that’s very expensive