I want to display a tree view (using standard `Laz...
# compose
m
I want to display a tree view (using standard
LazyColumn
), but because the tree itself is very complicated and reactive, I would also like to use compose-runtime to manage its nodes. I.e. I want to use the compose with custom `NodeApplier`to generate nodes of the tree that I then take and display with the standard (in my case desktop)-compose. Can it be somewhat easily achievable? There is something called
sub-composition
, the `Composition`function also takes a parent `CompositionContext`but I don't quite know how to glue that together. I have looked at https://github.com/JakeWharton/mosaic/ but it uses the compose-runtime standalone, while I want it kind of 'nested'.
z
I'm not sure I understand why you'd need subcomposition here. If your presenter layer is using a custom composition type to generate a custom tree of models, then you can just pass that tree to your UI composition.
You can't directly emit Compose UI nodes from a custom Applier because they're all internal.
m
I want to emit my in-house nodes in a non-UI subtree that sits somewhere inside the UI tree of the application. In the provided repository the first part is done, I just want to integrate the Composition into the main one, so that I don't have to have a separate therad/coroutine etc. and also have `State`s nicely synchronized between these two.
In the meantime I kind of found the answer here: https://github.com/JetBrains/androidx/blob/bc4f98ccbba27171f1bc419f2fb5b920401bc78[…]c/desktopMain/kotlin/androidx/compose/ui/window/Menu.desktop.kt Seems like this solution of CfD resembles mine's, so I might be good to go by following it
z
If I understand correctly, your data flow looks something like this: You have some data in your UI composition. You want to use a separate subcomposition with a different Applier type to turn that data into a tree of nodes, then use those nodes immediately in your UI composition to generate UI. Is that right?
t
This is a tool for composing State, if it helps: https://github.com/cashapp/molecule
Ah, but not for arbitrary trees
m
@Zach Klippenstein (he/him) [MOD] Totally right
z
And so would that last step work? How would you get your nodes back into the UI composition?
m
In the main composition I create `mutableStateListOf<Node>()`and display it, while also modifying it in the custom
Applier
. And so far it indeed works nicely (except it doesn't - I get some weird results when expanding and collapsing the nodes but at least it is responsive!)
z
I would expect there to be a frame of lag, since your custom composition would only invalidate the UI composition when it was applied, which would trigger another recomposition but only on the next frame.
😧 1
m
Gotta say, it was not so easy to set it up properly but at the end this approach works wonderfully. It is very easy to shape the tree, control prefetching and apply other features like searching. I do not notice any (new) lag, but generally CfD is not particularly responsive ATM either so it does not matter much. Looking forward to using compose-runtime in other non-UI fields 🙂