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.
71 lines
1.8 KiB
71 lines
1.8 KiB
3 years ago
|
// @Module:Main
|
||
|
import androidx.compose.runtime.Composable
|
||
|
import androidx.compose.runtime.currentComposer
|
||
|
import androidx.compose.runtime.Composer
|
||
|
|
||
|
fun main() {
|
||
|
callComposable {
|
||
|
FooTakesLambda()
|
||
|
InlineFooTakesLambda()
|
||
|
|
||
|
FooTakesComposableLambda()
|
||
|
InlineFooTakesComposableLambda()
|
||
|
|
||
|
FooTakesTypedExtesionComposableLambdaWithExplicitTypesAndDefaultLambda("4", 5)
|
||
|
ComposableWithDifferentDefaultValuesForParameters(a = Any())
|
||
|
ComposableWithReturnAndWithDefaultLambda().invoke()
|
||
|
}
|
||
3 years ago
|
require(setOf(1, 2, 3, 4, 5, 6, 7) == set) { "Failed when running composables - ${set.joinToString()}" }
|
||
3 years ago
|
}
|
||
|
|
||
|
// @Module:Lib
|
||
|
import androidx.compose.runtime.Composable
|
||
|
|
||
3 years ago
|
var set = mutableSetOf<Int>()
|
||
|
|
||
3 years ago
|
@Composable
|
||
3 years ago
|
fun FooTakesLambda(block: () -> Unit = { set.add(1) }) {
|
||
3 years ago
|
block()
|
||
|
}
|
||
|
|
||
|
@Composable
|
||
3 years ago
|
inline fun InlineFooTakesLambda(block: () -> Unit = { set.add(2) }) {
|
||
3 years ago
|
block()
|
||
|
}
|
||
|
|
||
|
@Composable
|
||
3 years ago
|
fun FooTakesComposableLambda(composable: @Composable () -> Unit = { set.add(3) }) {
|
||
3 years ago
|
composable()
|
||
|
}
|
||
|
|
||
|
@Composable
|
||
3 years ago
|
inline fun InlineFooTakesComposableLambda(composable: @Composable () -> Unit = { set.add(4) }) {
|
||
3 years ago
|
composable()
|
||
|
}
|
||
|
|
||
|
@Composable
|
||
|
fun FooTakesTypedExtesionComposableLambdaWithExplicitTypesAndDefaultLambda(
|
||
3 years ago
|
t: String, k: Int, composable: @Composable String.(Int) -> Double = {
|
||
|
set.add(5)
|
||
|
(this + ".$it").toDouble()
|
||
|
}
|
||
3 years ago
|
) {
|
||
|
t.composable(k)
|
||
|
}
|
||
|
|
||
|
@Composable
|
||
|
fun ComposableWithDifferentDefaultValuesForParameters(
|
||
|
a: Any, i: Int = 1, b: Boolean = false, s: String = "s",
|
||
|
u: Unit = Unit, a2: Any = Any(), l: List<Any> = listOf("1")
|
||
|
) {
|
||
3 years ago
|
set.add(6)
|
||
3 years ago
|
a.toString() + "$i $b $s $u $a2 $l"
|
||
|
}
|
||
|
|
||
|
@Composable
|
||
|
fun ComposableWithReturnAndWithDefaultLambda(
|
||
3 years ago
|
l: @Composable () -> (@Composable () -> Unit) = { { set.add(7) } }
|
||
3 years ago
|
): @Composable () -> Unit {
|
||
3 years ago
|
return { l().invoke() }
|
||
3 years ago
|
}
|