square / flow

Name UI states, navigate between them, remember where you've been.
Apache License 2.0
2.79k stars 241 forks source link

The purpose of MultiKey #255

Closed Tagakov closed 7 years ago

Tagakov commented 7 years ago

Hi. I am trying to implement a fairly complicated navigation in my app using Flow.

In my app I have several sequential screens, they are "nested" one in another (just like in TreeKey example). It is simple if my understanding of TreeKey is correct. (but why does getParentKey() always return a new instance of parent key rather than get its instance from the constructor, is it a limitation of a state restoring process?)

The complicated part is that every screen can have several different "slave" screens (just like in master\slave case), they are just like ChildFragments from pure android. "Slave" screens can replace each other with complicated rules and animations and the "slave" container should have its own backstack, but when the master screen goes out or is destroyed "slaves" should be hidden or destroyed as well.

Should I use MultiKey for this purpose? Or should I use nested Flow instances (not sure that it is possible)?

Zhuinden commented 7 years ago

(but why does getParentKey() always return a new instance of parent key rather than get its instance from the constructor, is it a limitation of a state restoring process?)

You don't have to do that, you can just provide the parent key as a constructor parameter.

Or should I use nested Flow instances (not sure that it is possible)?

That's not possible.

Should I use MultiKey for this purpose?

I'd assume this is what MultiKey is for, although I somewhat wonder because they are then "multiple children" which is problematic because of https://github.com/square/flow/pull/202 not being merged.

Unfortunately I can't help you on this front.

loganj commented 7 years ago

MultiKey is meant for the purpose you describe.

The fact that MultiKey is itself a key is probably a mistake. See #208. I probably wouldn't bind services to the MultiKey itself. If you have a MultiKey that's essentially (Main,Detail) then you probably want to navigate from (Main, DetailA) to (Main, DetailB). If you want to navigate away entirely, say back to Login, then you nav from (Main, DetailB) -> Login and both Main and DetailB will be cleaned up.