David
06/25/2024, 9:38 AMclass EditNameDialogViewModel(
...
private val handle: SavedStateHandle
) : ViewModel() {
private val navArgs = EditNameDialogDestination.argsFrom(handle)
private val inputName = handle.getStateFlow("inputName", navArgs.initialName.value)
val uiState = // build ui state from flows
fun onNameChanged(name: String) {
handle["inputName"] = name
}
}
I know there is some solutions like: https://gist.github.com/marcellogalhardo/2a1ec56b7d00ba9af1ec9fd3583d53dc that makes it a bit easier with creating a MutableStateFlow directly, and make it a bit cleaner.
How do peeps here do it?Ian Lake
06/25/2024, 1:46 PMDavid
06/25/2024, 2:00 PMIan Lake
06/25/2024, 2:01 PMDavid
06/25/2024, 2:02 PMIan Lake
06/25/2024, 2:02 PMDavid
06/25/2024, 2:03 PMadb shell am kill <package>
), If I don't update my savedStateHandle it would be reset to the original value right?Ian Lake
06/25/2024, 2:05 PMDavid
06/25/2024, 2:06 PMIan Lake
06/25/2024, 2:08 PMIan Lake
06/25/2024, 2:09 PMby handle.saveable
overloads, which make it possible to have rememberSaveable like APIs backed by your SavedStateHandle: https://developer.android.com/reference/kotlin/androidx/lifecycle/SavedStateHandle#(androidx.lifecycle.SavedStateHandle).saveable(androidx.compose.runtime.saveable.Saver,kotlin.Function0)Ian Lake
06/25/2024, 2:09 PMDavid
06/25/2024, 2:27 PMStylianos Gakis
06/25/2024, 2:28 PMDavid
06/25/2024, 2:39 PMDavid
06/25/2024, 2:40 PMMutableStateFlow
directly from savedStateHandle):
https://issuetracker.google.com/issues/235574686Stylianos Gakis
06/25/2024, 2:40 PMDavid
06/25/2024, 2:48 PMStylianos Gakis
06/25/2024, 2:48 PMDavid
06/25/2024, 2:49 PMStylianos Gakis
06/25/2024, 2:52 PMDavid
06/25/2024, 2:53 PMStylianos Gakis
06/25/2024, 2:54 PMRafael Costa
06/28/2024, 7:22 AMDavid
06/28/2024, 7:48 AMRafael Costa
06/28/2024, 7:49 AM