Nikky
06/26/2024, 3:27 PMrememberSaveable
works
but i have a few tabs in my app set up with a when (index) 0 -> tabOne() 1 -> tabTwo() }
to switch the content
in the content of these tabs i use var text by rememberSaveable(key = "textfield") { mutableStateOf(TextFieldValue("")) }
but every time the tab changes and come back the value resets to empty?
does this get wiped every time it does not get rendered ?
how would i solve this in a way that does not involve storing my own global state (mutablestateflow) for each thing ?MR3Y
06/26/2024, 4:50 PMeygraber
06/26/2024, 4:51 PMrememberSaveable
?MR3Y
06/26/2024, 4:54 PMrememberSaveable
helps you in saving things like scrolling position on desktop and of course surviving config changes on Android
but basically when you do something like this:
when(something) {
1 -> show some composable
2 -> show another composable
}
the two conditions are mutually exclusive so they won't be in composition at the same time.MR3Y
06/26/2024, 4:55 PMrememberSaveable
here you'll need to hoist it somewhere up the treeNikky
06/26/2024, 4:55 PMMR3Y
06/26/2024, 4:55 PMNikky
06/26/2024, 4:56 PMNikky
06/26/2024, 4:58 PMhttps://nikky.catgirl.host/i/cgau2vw8.pngâ–¾
Nikky
06/26/2024, 5:04 PMprivate val expandedStates = mutableStateMapOf<String, Boolean>()
fixed the problem.. and now i also understand why, thanksSaurabhS
06/26/2024, 5:33 PMrememberSaveable
with tabs you can use:
https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/SaveableStateHolderNikky
06/26/2024, 5:39 PMAlexander Maryanovsky
06/26/2024, 6:57 PM