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
jw
10/01/2023, 6:03 PM
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
hfhbd
10/01/2023, 6:04 PM
Do you have a sample how to create the subcomposition? Is it enough to just pass the parent recomposer?
j
jw
10/01/2023, 6:05 PM
Pretty much
I don't have an example. Dialog from Compose UI does it, although it uses the same applier
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.