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:
a back stack container view will own an instance of WorkflowSavedStateRegistryAggregator, and use it to assign a SavedStateRegistryOwner for its top view.
a container view managing a set of windows will own an instance of WorkflowSavedStateRegistryAggregator, and use it to assign a SavedStateRegistryOwner to each dialog's content view.
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:
call saveAndPruneChildRegistryOwner if the child is removed from service but may be restored before detachFromParentRegistry is called (as when a back stack pushes and pops)
call pruneAllChildRegistryOwnersExcept when views are permanently removed from service, taking care to identify the set that remain active
Note that this class does not offer support for the pre-Jetpack View.onSaveInstanceState mechanism. Container views must handle that themselves.
Functions
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.
Must be called when the owning view detaches from the window.
Puts a new SavedStateRegistryOwner in place on view, registered with its LifecycleOwner. (Use WorkflowLifecycleOwner to ensure one is properly installed.)
Drops all child SavedStateRegistryOwners and their restored state, except those identified in keysToKeep.
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.