wealthfront/magellan

Question: when calling Navigator.goTo() the previous view is destroyed. How can I return to that view when calling Navigator.goBack

Closed this issue · 1 comments

So, when I call goTo() to go to a new Screen, the old View is destroyed. When I try to goBack(), that old View is recreated. This in effect causes the view to lose its state.
So for instance if a Calendar app is showing a calendar view, and the user has picked a date which is in the past and then he taps that date a new Screen enters. If the user will now go back, the calendar view is recreated and he will lose the date location he picked before.
My question is, other than saving the actual View in onCreateView() and using that when the Screen loads again, is there any other method to preserve the previous view when navigating back to it?
Other than that... BRILLIANT library! I love it :)

Hey, sorry for the delay!

One of the core ideas of Magellan is that views are disposable and should be able to be recreated at any time. So in that sense, we don't recommend preserving view objects when they're not displayed.

That said, there are plenty of ways you can save the view state! In your example, you could store the date clicked on the calendar screen and make sure that that date is shown by the view in onShow. Or your calendar view could save its view state via Android's built-in mechanism, onSaveInstanceState. Magellan respects this mechanism, using it in the same way that the Android system does.

If you only use your calendar view on the one screen, it's probably easier to store the data in the screen. If you're using it on multiple screens, it's probably best to put it in onSaveInstanceState of the calendar view so you can't accidentally forget it later.