rjrjr / compose-backstack

Simple composable for rendering transitions between backstacks.
Other
501 stars 23 forks source link

Start using UiSavedStateRegistry to preserve screen "view" state. #25

Closed zach-klippenstein closed 4 years ago

zach-klippenstein commented 4 years ago

Currently screens' states are saved as long as the Backstack is in the composition by being kept entirely alive. This is not efficient, it's equivalent to keeping all views in the backstack attached at all times. Ideally we would only keep screens in the composition while they are actually visible, and remove all hidden screens as soon as possible. Unfortunately, until dev08, the only way to preserve view state was to keep these screens composed.

Dev08 introduces rememberSavedInstanceState and savedInstanceState composables. They mirror remember and state, but will restore their values from a UiSavedStateRegistry when they are first composed. This is the standard API for saving view state, much like onSavedInstanceState in the legacy framework, and so the backstack should support it.

This change does a few things:

The keys to making this work are: