I have a layout that represents a tree of answers which may have other sub-answers. I was inspired by this question and use a nested LazyColumn
like this:
@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.
However, is it possible to animate the visibility of such a group of sub-answers?
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)
}
}