I have a remember mutablestateof variable which is...
# compose
p
I have a remember mutablestateof variable which is being reseted and I don't understand why:
Copy code
var centerInLocationPending by remember { mutableStateOf(true) }
I only set it to false one time, never set it to true, but for some reason my map composable in which is being declared this var is being recomposed but resetting this var to true again. Which explanation haves this? supposedly by remember must do that this variable never goes to true anymore
z
probably something higher in the composition removing and readding this composable
p
it's inside a ListDetailPaneScaffold, maybe it's that
how can I avoid this to happen? the map is always visible on the right of the ListDetailPaneScaffold as it's the detail pane
I don't want it to recenter the location on the user more than one time
z
i'm not familiar with that component. It's really hard to say without seeing your code
p
it's a list on the left and a map on the right, every item you click on the list, loads different pois on the map of the right
the issue here is that the map is constantly visible
but under the hood is being removed and readded
or reseting composition
z
you could hoist your
centerInLocationPending
to above the scaffold, or make your own list/detail layout that doesn't reset the detail
or it might work to put your whole detail pane in a
movableContentOf
, although that's probably the least efficient solution
p
I think hoisting that var seems to be a very good idea
thank you
I'll study it
it worked, but not totally
now I have another issue related with this one
I have a NavigationSuiteScaffold and the user can navigate using a lower bar with buttons
if I'm on my places screen with a place selected in with the onetimecenter hoisted, it works when I'm on that screen and move between items of the list
but if I navigate to another screen, and return back, then, the screen is displaying which is the selected item, but the onetimecenter value is reseted again
I suposse I must move it to the viewmodel, but, is this normal?
coming back from another screen using navigation should recreate the entire composable reseting all the by remember values stored on it?
not seems a normal behaviour
z
To persist values when you navigate away then back, use rememberSaveable
p
ouch
well I already migrated everything to the viewmodel uistate
is better to move back to the composables using var remembersaveable for these kind of things?
z
View model probably makes the most sense
p
can you take a look on this please? https://kotlinlang.slack.com/archives/CJLTWPH7S/p1740178855795309 it's related with this issue
z
As I said, I’m not familiar with that component