Roberto Leinardi
05/13/2022, 11:20 AMactions: @Composable ColumnScope.() -> Unit
but I have now realized that I need to iterate to each Composable to animate it properly (see here).
Is there a way to iterate over the actions: @Composable ColumnScope.() -> Unit
? Or should I ask for a actions: List<@Composable () -> Unit> = emptyList()
? Or is there a better way to achieve what I need to do?ste
05/13/2022, 12:01 PM*Scope
class, e.g.
@Composable
fun MyThing(content: @Composable MyThingScope.() -> Unit) {
Column {
MyThingScope(this).content()
}
}
class MyThingScope(columnScope: ColumnScope) : ColumnScope by columnScope {
@Composable
fun MyThingItem(content: @Composable () -> Unit) {
// now you can access every item separately
}
}
@Composable
fun MyThing(content: @Composable MyThingScope.() -> Unit) {
val counterState = remember {
mutableStateOf(0)
}
Column(
horizontalAlignment = Alignment.End,
modifier = Modifier
.animateContentSize()
) {
remember {
MyThingScope(counterState, this)
}.content()
}
}
class MyThingScope(counterState: MutableState<Int>, columnScope: ColumnScope) : ColumnScope by columnScope {
private var counter by counterState
@Composable
fun MyThingItem(content: @Composable () -> Unit) {
val isVisible by produceState(false) {
delay(counter++ * 100L)
value = true
}
AnimatedVisibility(visible = isVisible) {
content()
}
}
}
Column
, so you probably need a custom layout for that - otherwise you could ask for the number of items to display, and then calculate a reversed delay to make the first item appear last)Roberto Leinardi
05/13/2022, 12:49 PM