Anyone have experience in displaying a hierarchica...
# compose
m
Anyone have experience in displaying a hierarchical data model (single root node, 2-3 children per parent (or 0 for leaf nodes), max 4 levels deep) in compose (preferably multiplatform)? I essentially want to display it in an upside down tree format, with lines showing the parent-child connections and labelling each node. Is a recursive composable feasible?
z
Yes
m
Thanks, now I see your post here but the images are not available, sadly: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1612634381433100?thread_ts=1612631804.429100&cid=CJLTWPH7S
z
I deleted my Twitter account. I’m not sure recursion would help here though
w
I've done this with recursion. It works exactly how you'd expect if you just want to fill a normal Column similar to Reddit comments. A custom layout with stuff that crosses rows sounds more difficult.
z
if it's a large tree you'll want a lazy list though, which won't work with recursion
w
Yeah, I only lazily added the parent node, children just go into a regular Column. I think it is possible to recurse in a lazy list though, you'd just call
item
instead.
m
I’m looking to make something more like a regular upside down tree where the first child is to the bottom left of the parent, and the last child is to the bottom right. In terms of size, the worst case is 23 nodes (7 levels deep) but the vast majority is one parent with two children (i.e 3 nodes - 2 levels deep). 99% of parents have two children, the other 1% have three children. EDIT: having thought about this some more, I think I will go with the reddit comment thread style instead. Seems much cleaner.