In `nav3` I intend to have separe `NavDisplay`s to...
# compose
u
In
nav3
I intend to have separe `NavDisplay`s to physically separate logged out and logged in sections of app. Good idea? If so, would you create separate base nav keys for each section? i.e.
interface LoggedInNavKey
,
object Dashboard : LoggesInNavKey
so they cannot mix?
j
What's the benefit of having separate backstacks for the two use cases?
u
So they cant mix
j
You have full control of your backstack in Nav3. If they mix you have a bug/programming error.
u
Exactly, to prevent those
j
You're missing my point. You're adding additional complexity where it's not needed. Since you own your back stack you can verify that only certain screens are accessible without having to NavDisplay.
1
u
Are you talking about some Navigator type which will observe app state and decide if the requested navigation call is legal etc? i.e. to prevent logged out screen to push a logged in screen without being logged in?
j
Effectively yes. This way you have your navigation related code centralized and you don’t need to worry about keeping back stacks up to date. If you want to add a new “use case” that requires a “distinct” backstack you won’t have to worry about your NavDisplays needing updating. Either way this is my 2 cents. Go with what works the best for you.
u
Btw how do you then discern target sections? Do you have some sort of base interface extending nav key?
interface LoggedInNavKey : NavKey
etc?
j
It's up to you. You can create a series of helper functions that returns a list of "Nav Keys" that are appropriate to the current app state. Another option could be to create a set of "Nav Keys" that are restricted and you filter the rest of your keys against it. Using an interface also works pretty well but you might limit yourself if you are not care with how you utilize them. For example, if you have more than two "use cases" and some screens are valid for multiple, an interface might get tricky to properly filter "Nav keys".
u
idk, having a whitelist of allowed screens will most certainly break over time as new come in if nothing is forcing you to think about it no?