Back Stack Container
A container view that can display a stream of BackStackScreen instances.
This container supports saving and restoring the view state of each of its subviews corresponding to the renderings in its BackStackScreen. It supports two distinct state mechanisms:
Classic view hierarchy state (View.onSaveInstanceState/View.onRestoreInstanceState)
AndroidX SavedStateRegistry via ViewTreeSavedStateRegistryOwner.
A note about SavedStateRegistry support.
The SavedStateRegistry API involves defining string keys to associate with state bundles. These keys must be unique relative to the instance of the registry they are saved in. To support this requirement, BackStackContainer tries to generate a best-effort unique key by combining its fully-qualified class name with both its view ID and the compatibility key of its rendering. This method isn't guaranteed to give a unique registry key, but it should be good enough: If you need to nest multiple BackStackContainers under the same SavedStateRegistry, just wrap each BackStackScreen with a Named, or give each BackStackContainer a unique view ID.
There's a potential issue here where if our ID is changed to something else, then another BackStackContainer is added with our old ID, that container will overwrite our state. Since they'd both be using the same key, SavedStateRegistry would throw an exception. As long as this container is detached before its ID is changed, it shouldn't be a problem.