Closed nhaarman closed 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:
Include a property isStateSavable
to the Savable*
interfaces to indicate whether an implementation actually supports state saving. The interfaces can return true
by default. This leads to some contradictive semantics though: A SavableScene
that returns false
for isStateSavable
doesn't really make sense.
Don't let the base implementations actually implement Savable*
, but do provide the saveInstanceState()
implementation without overriding. Implementing classes can then just slap a Savable*
on their class definition without having to override saveInstanceState()
:
abstract class StackNavigator(...) : Navigator {
/* ... */
open fun saveInstanceState() : NavigatorState {
return /* ... */
}
}
class MyStackNavigator : StackNavigator(...), SavableNavigator {
/* ... */
}
The latter doesn't really confidently provide a stable API however.
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.