Hello! Is it possible to keep tree of composables ...
# compose
p
Hello! Is it possible to keep tree of composables but not show elements?
a
If you're not using UI, it might be worth looking into molecule
p
I'm using ui, but want to hide some part of it without deleting compise tree, so after some time i can show it at the same state.
a
Not sure I follow
s
Maybe
movableContentOf {}
can be used here? A shot in the dark, but I seem to remember it being somewhat what you describe.
p
I need semantics of
if (visible) compose()
, but in case of else branch not dispose compose.
a
Yeah, without any real reason of what you need out of it, I'm not sure why you're not keen on not running your composable if it doesnt meet a condition
a
You can use a custom layout that doesn't place the content. For example:
Copy code
Modifier.layout { _, _ ->
    layout(0, 0) {}
}
p
Good idea! I'll try with layout. Thanks!
i
if you want to retain the state, then you should be hoisting that up above your if statement
p
For my case I have nested composables with their internal states recursevly. It is very hard to extract it to upper level. I want to keep them in tree hidden.
The solution with layout works perfect for my case! Keep tree and skip rendering. Thanks, Albert!
a
Does custom layout that doesn't place still result with the composables in the tree at 0,0. I thought I saw in the @Preview when I tried that so feared it was still in there to some degree. I have wondered what a similar correct thing to keep some composable active but not in the visible tree, right now we are doing something like putting a size(0).clearandsetsemantics{} modifier on the invisible part of the tree (maybe semantics invisibleToUser instead of clearAndSetSemantics)? The case we have is on a tablet / foldable device, have a dual pane view where each side of the pane has its own navigation graph, and wanting to keep the navigation graph alive even if you rotate to portrait and only have 1 showing (or on a smaller device its always 1 of the 2 showing). We need the graph alive since the navcontroller throws if you try to navigate before the graph has composed, and to retain the backstack on rotation/etc.
a
No, there is no implicit placing.