Was curious what we all think of the new type safe...
# compose
r
Was curious what we all think of the new type safe navigation with compose navigation and what way you would possibly implement it neatly in code. I have thought of using a sealed class or probably a similar construct
Copy code
sealed class Screens {
    @Serializable
    data object Home : Screens()

    @Serializable
    data object About : Screens()
}
Copy code
fun NavGraphBuilder.aboutScreen(
    modifier: Modifier = Modifier,
    onBackButtonClick: () -> Unit,
) {
    composable<Screens.About> {
        AboutScreen(
            modifier = modifier,
            onBackButtonClick = onBackButtonClick,
        )
    }
}
Or would you throw each route definition in separate files, probably where the composable is defined or within their respective packages?
p
The sealed class kind of ties them too much. I would rather have independent class routes. They don't necessarily need to relate to each other. One also, might want to reuse the same Composable - RouteClass pair in a different graph.
👍 2
3
r
@Pablichjenkov It does tie them together a lot, true
🙂 1
i
Yeah, we specifically don't recommend sealed classes for this because it doesn't scale and multi-module support us absolutely critical for anything beyond a simple example
💯 4