If I have a composable with a lambda param like th...
# compose
t
If I have a composable with a lambda param like this:
compact: @Composable () -> Unit
, and sometimes it can not render anything:
Copy code
compact = {
    uiModel?: return@ContentFadeBottomSheet
    MyComposable(uiModel)
}
Is there a way to know that the
compact()
changed (when uiModel is not null anymore) so I can remeasure the height? I tried to use
key(compact)
but didn’t work
s
If you do
Copy code
Box(Modifier.onPlaced { storeSizeHere }) {
 compact()
}
on the function which receives the lambda, does it do what you want?
z
compact
should recompose when
uiModel
changes automatically if
uiModel
is snapshot state, and if that emits or removes layout nodes your parent should automatically remeasure. So you shouldn’t have to do anything special.
At one point there was a bug with early returns in composable functions, I’m not sure if that was fixed so you might be running into that here. If you change it to this, does it work?
Copy code
if (uiModel != null) {
  MyComposable(uiModel)
}
t
Sorry for taking long to reply. @Zach Klippenstein (he/him) [MOD] unfortunately changing it to an
if
also didn’t work. In the end I used some other flag based in the uiModel not being null to trigger a
key(isShowing)
so it would recalculate what I needed, not sure if it’s ideal but it works 😬
z
Where's
uiModel
coming from?