Skip to content

Commit

Permalink
Architecture section with typed navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrah committed Oct 7, 2024
1 parent e1ce665 commit 259f27e
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions docs/src/arch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class QuizRepository() {

::: details App.kt
``` kotlin
...
@Composable
fun App(
navController: NavHostController = rememberNavController(),
Expand All @@ -124,37 +125,37 @@ fun App(
MaterialTheme {
NavHost(
navController = navController,
startDestination = "/welcome",
startDestination = WelcomeRoute,
) {


composable(route = "/welcome") {
composable<WelcomeRoute>() {
welcomeScreen(
onStartButtonPushed = {
navController.navigate(route = "/quiz")
navController.navigate(route = QuizRoute)
}
)
}
composable(route = "/quiz") {
composable<QuizRoute>() {
val questions by quizRepository.questionState.collectAsState()
questionScreen(
questions = questions,
/* FOR SPEAKER TALK DEMO ON WEB APP */
onFinishButtonPushed = {
score: Int, questionSize: Int -> navController.navigate(route = "/score/$score/$questionSize")
score: Int, questionSize: Int -> navController.navigate(route = ScoreRoute(score, questionSize))
}
)
}
composable(route = "/score/{score}/{total}") {
composable<ScoreRoute> { backStackEntry ->
val scoreRoute: ScoreRoute = backStackEntry.toRoute<ScoreRoute>()
scoreScreen(
score = it.arguments?.getString("score")?.toInt() ?:-1,
total = it.arguments?.getString("total")?.toInt() ?:-1,
score = scoreRoute.score,
total = scoreRoute.questionSize,
onResetButtonPushed = {
navController.navigate(route = "/quiz")
navController.navigate(route = QuizRoute)
}
)
}

}
}
}
Expand Down Expand Up @@ -238,7 +239,7 @@ fun App(
quizViewModel: QuizViewModel = QuizViewModel()
) {
...
composable(route = "/quiz") {
composable(route = QuizRoute) {
val questions by quizViewModel.questionState.collectAsState()
```
:::
Expand Down

0 comments on commit 259f27e

Please sign in to comment.