square / mortar

A simple library that makes it easy to pair thin views with dedicated controllers, isolated from most of the vagaries of the Activity life cycle.
Apache License 2.0
2.16k stars 156 forks source link

Maintaining Screen State on Backstack? #200

Open ScottPierce opened 7 years ago

ScottPierce commented 7 years ago

We're using flow and mortar, and looking to save some data on a screen that when we come back to it on the backstack can be used to restore some state.

How would you recommend we do this?

ScottPierce commented 7 years ago

@rjrjr ?

Zhuinden commented 7 years ago

@ScottPierce my recommendation is to throw Mortar ViewPresenters out and use Flow's KeyManager exclusively.

ScottPierce commented 7 years ago

@Zhuinden My team has screens within screens sometimes, which is why we added in Mortar to our Flow usage. I'm assuming that KeyManagers doesn't allow for that, right?

Zhuinden commented 7 years ago

KeyManager allows you to put any state into the history entry. It just associates history entries with keys.

Personally when I had multiple views that could persist state, my root view delegated the "state persistence callback" to the ones inside itself. A bit manual, but it worked.

ScottPierce commented 7 years ago

@Zhuinden thanks for the recommendation. I'll look into it and close this if it works.

I'm actually not seeing any documentation for it anywhere in the flow repo. Do you know of where I could see an example of it working?

Zhuinden commented 7 years ago

I think the key manager's state is exposed via Traversal.getState(Key) in the original Flow.