WorkflowSavedStateRegistryAggregator

Manages a group of SavedStateRegistryOwners that are all saved to and restored from a single "parent" SavedStateRegistryOwner. SavedStateRegistryOwner is the new androidx alternative to the View.onSaveInstanceState system, and is required by Compose UI.

This class is designed to support a navigation container view that owns a a set of navigation "frames", where a frame is something that can be navigated to/from. A frame loosely consists of a root View and its SavedStateRegistryOwner. For example:

Note that a SavedStateRegistryOwner works in parallel to a LifecycleOwner. Use WorkflowLifecycleOwner to ensure one is properly installed.

attachToParentRegistry must be called when the container view is attached to a window, and passed the parent registry. detachFromParentRegistry must be called when the container view is detached.

Call installChildRegistryOwnerOn to put a SavedStateRegistryOwner in place on each managed child view, before it is attached to a window. After that:

Note that this class does not offer support for the pre-Jetpack View.onSaveInstanceState mechanism. Container views must handle that themselves.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard

Must be called when the owning container view gets attached to the window. The owning view should find its parentOwner (probably via WorkflowAndroidXSupport.stateRegistryOwnerFromViewTreeOrContext) and determine a string key unique within that parent to save and restore this class in that registry. These values will be cached in this object for detachment later.

Link copied to clipboard

Must be called when the owning view detaches from the window.

Link copied to clipboard
fun installChildRegistryOwnerOn(view: View, key: String, force: Boolean = false)

Puts a new SavedStateRegistryOwner in place on view, registered with its LifecycleOwner. (Use WorkflowLifecycleOwner to ensure one is properly installed.)

Link copied to clipboard
fun pruneAllChildRegistryOwnersExcept(keysToKeep: Collection<String> = emptyList())

Drops all child SavedStateRegistryOwners and their restored state, except those identified in keysToKeep.

Link copied to clipboard

Call this when the View previously registered with key is being dropped, but may be replaced with a new instance before the container is destroyed -- think of pushing and popping in a back stack.