:wave: I have a layout representing a tree of answers that may have other sub-answers. I use a neste...
h
👋 I have a layout representing a tree of answers that may have other sub-answers. I use a nested LazyColumn ✏️ like this:
Copy code
@Composable
fun Questionnaire(answers: List<Answer>) {
    LazyColumn {
        nodes(answers)
    }
}

fun LazyListScope.nodes(answers: List<Answer>) {
    nodes.forEach { answer ->
        node(answer)
    }
}

fun LazyListScope.node(answer: Answer) {
    item {
        Text(answer.content)
    }

    if(answer.selected) {
        nodes(answer.subAnswers)
    }
}
As you can see, sub-answers are visible only if the parent answer is selected. It works well, however, is it possible to animate the visibility of such a group of sub-answers? Something like this:
Copy code
fun LazyListScope.node(answer: Answer) {
    item {
        Text(answer.content)
    }

    // Needs context of a @Composable function, will not compile
    AnimatedVisibility(visible = answer.selected) {
        nodes(answer.subAnswers)
    }
}
I will appreciate any help 🙏
s
You cannot use AnimatedVisibility directly in lazy layout block, but can wrap each individual item instead