Grigorii Yurkov
08/02/2024, 9:34 AMremember
works, so I created this simple example.
Here, every time I click on Switch
I get a new random number. AFAIU this happens because remember
gets removed from the tree, so it forgets the value it remembered.
How can I get around it? I need something similar to the View.GONE
that doesn't remove the node from the tree, but makes it non interactable.Stylianos Gakis
08/02/2024, 9:39 AMif (bool)
line.
So:
val text = remember { Random...}
if (bool) {
Text(text = text)
} else {
Text(text = text)
}
This would persist the text across recompositions, and even if bool changes back and forthGrigorii Yurkov
08/02/2024, 9:47 AMStylianos Gakis
08/02/2024, 10:01 AMGrigorii Yurkov
08/02/2024, 10:12 AMWebView
itself. I just used it so you cannot "cheat your way out" by extracting remember
function 🙂
I just want to understand, can I remove a node from the tree without reseting remember
or AndroidView
Konstantin Tskhovrebov
08/02/2024, 10:17 AMGrigorii Yurkov
08/02/2024, 10:26 AMViewModels
so store the state. But what about Views
themselves? They are not cheap to create. Should I implement my own view pool then?Konstantin Tskhovrebov
08/02/2024, 10:34 AMMR3Y
08/02/2024, 11:33 AMTL;DR
use SaveableStateHolder
which being utilized by most navigation libraries under the hood to save state for destinations that aren't currently visible but still exist on the backstackshikasd
08/02/2024, 12:49 PMWebView
case you could also try movableContentOf
to preserve the state, but it can get funky when view gets involved.Trym Nilsen
08/02/2024, 1:40 PM