Skip to content

Commit

Permalink
Use type-safe compose navigation (#43)
Browse files Browse the repository at this point in the history
* chore: 🤖 upgrade navigation-compose to 2.8.0 beta

* refactor: 💡 use type-safe navigation

* refactor: 💡 remove old navigation folder

* refactor: 💡 move navigation code to MainNavHost
  • Loading branch information
ricky9667 authored Jul 28, 2024
1 parent c9b3cb8 commit 2472714
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 56 deletions.
3 changes: 1 addition & 2 deletions app/src/main/java/com/rickyhu/hushkeyboard/main/MainApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import com.rickyhu.hushkeyboard.data.ThemeOption
import com.rickyhu.hushkeyboard.navigation.AppNavHost
import com.rickyhu.hushkeyboard.theme.HushKeyboardTheme

@Composable
Expand All @@ -30,7 +29,7 @@ fun MainApp(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
AppNavHost()
MainNavHost()
}
}
}
34 changes: 34 additions & 0 deletions app/src/main/java/com/rickyhu/hushkeyboard/main/MainNavHost.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.rickyhu.hushkeyboard.main

import androidx.compose.runtime.Composable
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.rickyhu.hushkeyboard.home.HomeScreen
import com.rickyhu.hushkeyboard.settings.SettingsScreen
import kotlinx.serialization.Serializable

@Serializable
object HomeRoute

@Serializable
object SettingsRoute

@Composable
fun MainNavHost() {
val navController = rememberNavController()

NavHost(
navController = navController,
startDestination = HomeRoute
) {
composable<HomeRoute> {
HomeScreen(
onSettingsClick = { navController.navigate(route = SettingsRoute) }
)
}
composable<SettingsRoute> {
SettingsScreen()
}
}
}

This file was deleted.

19 changes: 0 additions & 19 deletions app/src/main/java/com/rickyhu/hushkeyboard/navigation/HomeRoute.kt

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ kotlin-serialization = "1.8.10"
kotlinx-serialization-json = "1.3.2"
kover = "0.7.6"
ktlint = "11.4.1"
navigation-compose = "2.7.7"
navigation-compose = "2.8.0-beta06"
robolectric = "4.12"
splitties-systemservices = "3.0.0"

Expand Down

0 comments on commit 2472714

Please sign in to comment.