Rohan
07/21/2023, 2:39 PMdata class commentNode (
var children: MutableList<CommentNode>? = mutableListOf(),
var collapsed: Boolean = false
) {}
And all of this is contained in a variable that looks something like so:
var tree: MutableList<CommentNode> = mutableListOf()
As you can imagine, this would produce a nested tree-like structure.
So, using state, how would I trigger recomposition when changing the value collapsed in any nested CommentNode?
Any help is appreciated :)alaershov
07/21/2023, 2:46 PMCommentNode to implement State in a custom way and notify its observers about changes?
I'd suggest a different approach and make your CommentNode immutable, and just pass it as a regular @Stable class. Then just pass it to a composable function, and it will recompose on any change. Of course, you'd have to "change" it using copy()Rohan
07/21/2023, 2:49 PMcopy(), would that still cause the screen to recompose?alaershov
07/21/2023, 2:52 PMImmutableList<CommentNode> if you take immutable approach, or mutableStateListOf<CommentNode>() if you insist on mutabilityalaershov
07/21/2023, 2:53 PMdata class CommentNode (
val children: ImmutableList<CommentNode> = persistentListOf(),
val collapsed: Boolean = false
)Rohan
07/21/2023, 2:56 PM