ursus
03/07/2026, 5:18 PMNav3 docs say
> When to use a decorator (in jetpack compose nav3)
>
> Use a decorator to:
> ...
> Scope an object to multiple NavEntrys. For example, to share a ViewModel between multiple entries.
Is this the case of.. say I want to share some object between "registration flow" nav entries?
If so, how?
To map down keys to a common value and then use remember(common value) { .. } , like this
class RegistrationFlowDecorator : NavEntryDecorator<Any>(
decorate = { entry ->
val isRegistration = when (val key = entry.key) {
is RegistrationEmail,
is RegistrationPassword -> true
else -> false
}
if (isRegistration) {
val sharedThing = remember(isRegistration) { RegistrationSharedThing() }
CompositionLocalProvider(LocalRegistrationSharedThing provides sharedThing) {
entry.Content()
}
}
}
)
?
I'm not sure about the if (isRegistration) though