SavedStateSupport
A class helps to support saved state in Compose.
The clear method will clear all saved state and clear the ViewModelStore. Usually, you should call clear in onDispose
of a androidx.compose.runtime.DisposableEffect that runs in the root @Composable.
The performSave method will save all the saved state. Usually, you should call performSave in onDispose
of a androidx.compose.runtime.DisposableEffect that runs in a child @Composable. That androidx.compose.runtime.DisposableEffect should be at the last of the child @Composable, because SaveableStateRegistry.Entrys are unregistered in reverse order. We want to save state first, before SaveableStateRegistry.Entrys are unregistered.
Example
// Remember a SavedStateSupport instance.
val savedStateSupport = remember { SavedStateSupport() }
// Clear the SavedStateSupport when the root @Composable exits the composition.
savedStateSupport.ClearOnDispose()
// Provide SavedStateSupport as ViewModelStoreOwner, SaveableStateRegistry and SavedStateHandleFactory.
savedStateSupport.ProvideCompositionLocals {
MyApp()
}
Types
Determine when to close a Closeable.
Functions
Clear this SavedStateSupport when the @Composable exits the composition.
Get a Closeable by key.
Provides this as LocalViewModelStoreOwner, LocalSaveableStateRegistry and LocalSavedStateHandleFactory to the content, along with other ProvidedValues.