How do you generate a different typed tree? The Ap...
# compose
h
How do you generate a different typed tree? The Applier interface expects only one type parameter, ideally with a MutableList of the same type. Is it possible to create different appliers, each using a different type, or should I refactor my existing tree, eg with a sealed class, to only use one applier?
j
It depends what the split is. You can use a subcomposition to get a new composition hosted within another with a different tree type. Otherwise you need to support all node types in your one applier.
h
Do you have a sample how to create the subcomposition? Is it enough to just pass the parent recomposer?
j
Pretty much
I don't have an example. Dialog from Compose UI does it, although it uses the same applier
h
Thank you, I will take a look
d
I mix a couple appliers here https://github.com/msink/kotlin-libui/pull/51 .
z
Subcomposition currently has quite a bit of overhead, if you’re expecting your trees to change “applied types” often it’s going to be expensive. Eg in compose ui it’s used for: • dialogs because they have to be entirely separate host views, in different windows, so it’s not possible for them to be in the same composition. • Vector graphics because they’re a specific type of leaf content, not containers used to compose complex layouts • BoxWithConstraints because has to in order to pass layout info to composition in the same frame.