Zoltan Demant
09/27/2021, 8:57 AMZoltan Demant
09/27/2021, 8:58 AMval LocalStep = compositionLocalOf<Step> {
throw NullPointerException()
}
@Composable
fun <T> Property(
modifier: Modifier = Modifier,
step: Step = LocalStep.current, //crashes
input: Input<T>,
onUpdate: (Input<T>) -> Unit,
label: String? = null,
style: InputStyle? = null,
fill: Boolean = false
) {
val step = LocalStep.current //works
}
adjpd
09/27/2021, 9:04 AMthrow NullPOinterException()
as a value of the composition local, so perhaps that's the difference.Zoltan Demant
09/27/2021, 9:09 AMZoltan Demant
09/27/2021, 9:10 AMCLOVIS
09/27/2021, 11:27 AMZoltan Demant
09/27/2021, 12:29 PMtheapache64
09/27/2021, 12:47 PMcompositionLocal
from parent scope (using default argument) as well as composable scope. It works for me.
data class User(val name: String)
val LocalUser = compositionLocalOf<User> { throw NullPointerException() }
@Preview
@Composable
fun A() {
CompositionLocalProvider(LocalUser provides User(name = "Adam")) {
Column {
B()
C()
}
}
}
@Composable
fun B(
user: User = LocalUser.current
) {
Text(text = "B says user is ${user.name}")
}
@Composable
fun C(){
val user = LocalUser.current
Text(text = "C says user is ${user.name}")
}
Can you share a reproducible code like the above?Zoltan Demant
09/27/2021, 12:59 PM@JvmInline
value class User(val name: String)
Zach Klippenstein (he/him) [MOD]
09/27/2021, 3:22 PMProperty
function being called from somewhere that LocalStep
is actually provided? If so, what’s the exception thrown in the default parameter case?theapache64
09/27/2021, 3:24 PMvalue
class with compositionLocal
before. I am curious why it didn’t work with the inline class 🤔Zoltan Demant
09/27/2021, 3:44 PMParameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter step
and everything works if I just make it a data class instead of inline. Im using inline classes in other cases, the issue seems to only come up when using them as default values with compositionLocal.current.Zach Klippenstein (he/him) [MOD]
09/27/2021, 3:59 PMZoltan Demant
09/28/2021, 5:28 AMZach Klippenstein (he/him) [MOD]
09/28/2021, 2:11 PMZach Klippenstein (he/him) [MOD]
09/28/2021, 2:12 PM