Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skipping certain Scenes/Navigators when saving state #119

Closed
nhaarman opened this issue Feb 10, 2019 · 1 comment · Fixed by #133
Closed

Skipping certain Scenes/Navigators when saving state #119

nhaarman opened this issue Feb 10, 2019 · 1 comment · Fixed by #133
Labels
priority:medium This issue has a medium priority type:enhancement A proposed enhancement to the api or behavior

Comments

@nhaarman
Copy link
Owner

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 nhaarman added type:enhancement A proposed enhancement to the api or behavior priority:low This issue has a low priority labels Feb 10, 2019
@nhaarman nhaarman added priority:medium This issue has a medium priority and removed priority:low This issue has a low priority labels Apr 7, 2019
@nhaarman
Copy link
Owner Author

nhaarman commented Apr 7, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:medium This issue has a medium priority type:enhancement A proposed enhancement to the api or behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant