:wave: I believe I read about this somewhere a whi...
# compose-destinations
m
👋 I believe I read about this somewhere a while back, but right now I can't find it. Is there a way for us to annotate something so that it becomes sort of a "prerequisite" to a destination? A typical example would be to have a "check if user is still logged in", which could route the user to a login navgraph if the check fails, for example, or just display a pin code full screen or something.
r
Hi @Magnus Gudmandsen There is what we call "Destination wrappers". Everytime you have logic or compose UI you would like to wrap multiple annotated Composables around, you can use that. I'm in the process of documenting this feature for v2.. until then, let me find you the release notes.
m
Thank you! I knew I read it somewhere 😄
👍 1
r
Let me know if the feature was helpful or if you need any help!
s
A question for this feature. Say you’ve come back into the app after being away for a bit, so now you have to show the pin screen. The backstack which you are in is
A > B > C > D > E
. Let’s assume
B, C, D, E
need to have this pin but
A
does not. So you are now on
E
and you show the pin since
pinEnteredCorrectly
is false. If you at that point do a system back 5 times one at a time, will the user see after each back ->
Pin screen
,
Pin screen
,
Pin screen
,
Pin screen
,
A screen
,
Exit the app
?
r
Depends on how you code the wrapper. This in the end is no different than what you can do with official lib:
Copy code
NavHost(...) {
    composable("route") {
        PinWrapper {
            ScreenComposable()
        }
    }
}
👍 1
PinWrapper could for example use a VM tied to the graph/activity where the logic of whether or not to show Pin is centralized.
So you can avoid what you mention.
s
I was trying to base this off of what the code here https://github.com/raamcosta/compose-destinations/releases/tag/1.8.33-beta is showing. If the VM that is used is tied to the activity, that wouldn’t change the fact that the backstack still has those 4 destinations that are all behind the pin authentication right?
r
I didn't want to complicate it for the example. Yes, it doens't solve it by itself, but its a first step to centralize that logic, then I'm sure you can come up with a way to avoid it. Wrapper is inside a
DestinationScope
which contains a lot of stuff, from the
navController
to the
destination
being wrapped. You should have everything needed to do whatever you need.
PinWrapper is just an example. You could use this for a lot of stuff. Even to show a top bar:
Copy code
Wrapper code stuff ... {
    Column {
        TopAppBar()
        screenContent()
    }
}
👍 2