galex
06/07/2025, 1:23 PMIan Lake
06/07/2025, 2:25 PMEntryProviderBuilder
that is used in the DSL: https://developer.android.com/guide/navigation/navigation-3/basics#use_the_entryprovider_dsl
So your code would look like
entryProvider {
homeModuleEntries()
profileModuleEntries()
}
Ian Lake
06/07/2025, 2:26 PMIan Lake
06/07/2025, 2:28 PMgalex
06/07/2025, 2:49 PMIan Lake
06/07/2025, 2:56 PMStylianos Gakis
06/07/2025, 3:31 PMgalex
06/07/2025, 3:34 PMfun NavBackStack.navigateToEntrance() {
add(EntranceNavigation.Login)
}
internal object EntranceNavigation {
@Serializable data object Login: NavKey
@Serializable data object Signup: NavKey
@Serializable data object ForgotPassword: NavKey
@Serializable data object CompleteAccount: NavKey
}
fun EntryProviderBuilder<NavKey>.authModuleEntries(
navigateTo: (NavKey) -> Unit,
replace: (toRemove: NavKey, toAdd: NavKey) -> Unit,
popBackStack: () -> Unit,
) {
entry(EntranceNavigation.Login) {
LoginScreen(
onSignUpClick = { replace(EntranceNavigation.Login, EntranceNavigation.Signup) },
onForgotPasswordClick = { navigateTo(EntranceNavigation.ForgotPassword) },
onAuthSuccess = { popBackStack() },
)
}
entry(EntranceNavigation.Signup) {
SignUpScreen(
onBackClick = { popBackStack() },
onSignUpSuccess = {
replace(
EntranceNavigation.Signup,
EntranceNavigation.CompleteAccount
)
}
)
}
entry(EntranceNavigation.ForgotPassword) {
ForgotPasswordScreen(
onBackClick = { popBackStack() },
)
}
entry(EntranceNavigation.CompleteAccount) {
CompleteAccountScreen(
onBackClick = { popBackStack() },
onComplete = { popBackStack() },
)
}
}
I would love to see a recipe on how to modularize (like this or in any other way) the navigation Ian Lake
06/07/2025, 3:35 PMIan Lake
06/07/2025, 3:36 PMgalex
06/07/2025, 3:41 PMnavigateToEntranc()
to pop back to it?
The use case is when there's a long flow of screens and the user presses up for example, I would like to remove all the screens of that module π€
Using the metadata map maybe?galex
06/07/2025, 3:43 PMIan Lake
06/07/2025, 3:44 PMdropLastWhile { it is EntranceScreen }
(if you had a sealed marker interface for all your screens in that module, for instance)galex
06/07/2025, 3:46 PMIan Lake
06/07/2025, 3:47 PMgalex
06/07/2025, 3:49 PMfun NavBackStack.navigateToEntrance() {
add(EntranceNavigation.Login)
}
fun NavBackStack.popEntrance() {
dropLastWhile { it is EntranceNavigation.EntranceNavKey }
}
internal object EntranceNavigation {
interface EntranceNavKey : NavKey
@Serializable data object Login: EntranceNavKey
@Serializable data object Signup: EntranceNavKey
@Serializable data object ForgotPassword: EntranceNavKey
@Serializable data object CompleteAccount: EntranceNavKey
}
Ian Lake
06/07/2025, 3:50 PMgalex
06/07/2025, 4:15 PMPablichjenkov
06/07/2025, 5:32 PMIan Lake
06/07/2025, 5:35 PMPablichjenkov
06/07/2025, 6:00 PM