You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.2 KiB
51 lines
1.2 KiB
3 years ago
|
// @Module:Main
|
||
3 years ago
|
// fixed in https://github.com/JetBrains/androidx/pull/118
|
||
|
|
||
3 years ago
|
import androidx.compose.runtime.Composable
|
||
|
import androidx.compose.runtime.currentComposer
|
||
|
import androidx.compose.runtime.Composer
|
||
|
|
||
|
fun main() {
|
||
3 years ago
|
var called = false
|
||
|
|
||
3 years ago
|
callComposable {
|
||
3 years ago
|
ComposableWithTypedDefaultValue<String>({ it ->
|
||
|
check(it.value == null)
|
||
|
called = true
|
||
|
})
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
require(called) { "Failed when running composables" }
|
||
3 years ago
|
}
|
||
|
|
||
|
// @Module:Lib
|
||
|
import androidx.compose.runtime.Composable
|
||
|
|
||
|
sealed class NullableWrapper<T> {
|
||
|
companion object {
|
||
|
fun <T> of(value: T?): NullableWrapper<T> =
|
||
|
if (value != null) {
|
||
|
NonNullWrapper(value)
|
||
|
} else {
|
||
|
NullWrapper()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
abstract val value: T?
|
||
|
}
|
||
|
|
||
|
class NonNullWrapper<T>(override val value: T) : NullableWrapper<T>()
|
||
|
|
||
|
class NullWrapper<T> : NullableWrapper<T>() {
|
||
|
override val value: T? get() = null
|
||
|
}
|
||
|
|
||
|
@Composable // https://github.com/JetBrains/compose-jb/issues/1226
|
||
|
fun <T> ComposableWithTypedDefaultValue(
|
||
|
onChange: (NullableWrapper<T>) -> Unit,
|
||
|
valueWrapper: NullableWrapper<T> = NullWrapper()
|
||
3 years ago
|
) {
|
||
|
onChange(valueWrapper)
|
||
|
}
|
||
3 years ago
|
|