nhaarman / acorn

Mastering Android navigation :chipmunk:
https://nhaarman.github.io/acorn
Apache License 2.0
181 stars 7 forks source link

Skipping certain Scenes/Navigators when saving state #119

Closed nhaarman closed 5 years ago

nhaarman commented 5 years ago

For some Scenes and Navigators it may not make sense to restore for, and it may be easier/more fitting to just not save them.

The existing navigators in the extension artifacts currently always save their internal state, and if possible (if the child supports state saving) save the childrens' state with it.

For the StackNavigator for example, it may not make sense to preserve the entire stack but only up to a certain point. Say Scene C does not want to preserve its state in a stack [A, B, C, D] one could argue that only [A, B] should be restored.

nhaarman commented 5 years ago

Since most of the base implementations implement Savable* to allow easy state saving, this doesn't really allow intentionally not supporting state saving: the easiest of checks is whether the component implements Savable* and then actually calling saveInstanceState() on it.

Two solutions come to mind:

abstract class StackNavigator(...) :  Navigator {
  /* ... */
  open fun saveInstanceState() : NavigatorState {
    return /* ... */
  }
}

class MyStackNavigator : StackNavigator(...), SavableNavigator {
  /* ... */
}

The latter doesn't really confidently provide a stable API however.