Zhuinden / simple-stack

[ACTIVE] Simple Stack, a backstack library / navigation framework for simpler navigation and state management (for fragments, views, or whatevers).
Apache License 2.0
1.36k stars 75 forks source link

Simple-stack on a multi-module architecture #238

Closed mradzinski closed 3 years ago

mradzinski commented 3 years ago

Hey Gabor! How's it going? I was wondering how easily achievable it is to have simple-stack manage the navigation between screens on a multi-module project where DefaultFragmentKey have to be stored per module/feature. How would one access such keys without creating intertwined module dependencies?

I guess we could create some globally available interfaces and relay on DI to retrieve the actual DefaultFragmentKey implementation, but it would be great to know if you already had to solve this scenario and how did you solve it.

Thanks!

Zhuinden commented 3 years ago

Hey!

One time I had to set up a scenario where there was a global module with all the keys in it, but I'd say that's actually trickier because it requires map multibinding (the key and the fragment type live in separate modules, and the navigation modules with the keys would not actually see the fragment types), very similar to this experiment.

If the key is next to the fragment, then it's actually fairly straightforward, it's the same approach as outlined here ("theoretical correct solution") namely that the module would expose an interface that is handled by a common parent (probably :app) with an implementation that is provided to the child module by DI.

retrieve the actual DefaultFragmentKey implementation

I don't think you need to expose the keys, what you need to expose is the intention to cross module boundaries via an action. 🤔

mradzinski commented 3 years ago

I kind of agree on the "theoretical correct solution", though I find it to be a bit crippling. If you wanna provide a constructor to the key (to build a Fragment, for example), an interface will not be able to implement such constructor. So I guess most of the times you'll end up either with an abstract class, or some other kind of implementation

Zhuinden commented 3 years ago

Actually, any argument that needs to be passed to the key can be an argument of the method in the interface. So constructor parameters (and therefore bundle arguments for the fragment) are still possible in a typesafe way.

Zhuinden commented 3 years ago

Did that answer your question?

mradzinski commented 3 years ago

Indeed @Zhuinden. Let's close this issue. Thanks for your help and feedback.