Chris Johnson
10/29/2021, 8:15 PMlet
is broken going from version 1.0.1 of compose to alpha01? Code in thread.Chris Johnson
10/29/2021, 8:17 PMvar composableTitle: (@Composable () -> Unit)? = null,
composableTitle?.let {
it()
} ?: run {
Text(text = title, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
but after migrating to alpha01 this seems to invoke the nullable composable even if it's null and never get to the run block.jim
10/29/2021, 9:37 PMChris Johnson
10/29/2021, 9:38 PMcomposableTitle
is null so actually I would expect a NPE if it runs through the let and tries to invoke it but instead I get nothing. By that I mean when I look in the layout inspector I don't see this composable at all. It's as though it skipped it. Instead I'd expect it to go to the run block. This leads me to believe that composableTitle is an empty lambda but when I debug through it it's null. I haven't changed this code except to upgrade the compose versionjim
10/29/2021, 9:47 PMjim
10/29/2021, 10:57 PMval lambda: (@Composable () -> Unit) = { throw Error("Should not be invoked") }
val v = if(false) { lambda(); } else null
if(v == Unit) throw Error("Should not be Unit")
if(v != null) throw Error("Should be null")
jim
10/29/2021, 11:02 PMUnit
and that logic is wrong.jim
10/29/2021, 11:02 PMjim
10/29/2021, 11:02 PMChris Johnson
10/29/2021, 11:04 PMjim
10/29/2021, 11:05 PMjim
10/29/2021, 11:06 PMvar composableTitle: (@Composable () -> Unit)? = null
composableTitle?.let {
it()
null
} ?: run {
Text(text = title, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
jim
10/29/2021, 11:06 PMnull
as the last statement inside the let block)Chris Johnson
10/29/2021, 11:07 PMif (composableTitle == null) {
Text(text = title, maxLines = 1, overflow = TextOverflow.Ellipsis)
} else {
composableTitle()
}
you're saying this shouldn't work ^?jim
10/29/2021, 11:08 PMjim
10/29/2021, 11:08 PMChris Johnson
10/29/2021, 11:10 PMlets
more loljim
10/29/2021, 11:14 PMjim
10/29/2021, 11:15 PMjim
10/29/2021, 11:15 PMChris Johnson
10/29/2021, 11:17 PMChris Fillmore
11/11/2021, 3:02 PMval myDomainObject by myStateFlow.collectAsState()
myDomainObject?.let {
// Show some UI
} ?: CircularProgressIndicator()
And on upgrade from compose 1.0.1 to 1.1.0-beta02 I lost my progress indicators.
I can get the progress indicator back by adding a null check like:
if (myDomainObject == null) {
CircularProgressIndicator()
}