У настроек теперь есть своя внутренняя навигация

This commit is contained in:
mezhendosina 2023-06-21 15:29:05 +05:00
parent 4f67569409
commit f09f98e637
3 changed files with 53 additions and 2 deletions

View file

@ -6,7 +6,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import ru.nm17.narodmon.ui.settings.SettingsScreen import ru.nm17.narodmon.ui.settings.SettingsNavigation
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@ -18,7 +18,7 @@ fun AppNavHost() {
MainScreen(navController) MainScreen(navController)
} }
composable("settings") { composable("settings") {
SettingsScreen() SettingsNavigation()
} }
} }
} }

View file

@ -0,0 +1,12 @@
package ru.nm17.narodmon.ui.settings
import androidx.annotation.StringRes
import ru.nm17.narodmon.R
sealed class Settings(val route: String, @StringRes val resourceId: Int) {
object Main : Settings("settings_main", R.string.settings)
object AboutApp : Settings("settings_about_app", R.string.about_app)
object Debug : Settings("settings_debug_menu", R.string.debug_menu)
}

View file

@ -0,0 +1,39 @@
package ru.nm17.narodmon.ui.settings
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SettingsNavigation() {
val navController = rememberNavController()
Scaffold(topBar = {
TopAppBar(title = { Text(text = navController.currentDestination?.route ?: "") })
}) {
NavHost(
navController = navController,
startDestination = Settings.Main.route,
modifier = Modifier.padding(it)
) {
composable(Settings.Main.route) { SettingsScreen(navController) }
composable(Settings.AboutApp.route) { }
composable(Settings.Debug.route) { }
}
}
}
@Preview
@Composable
fun PreviewSettingsNavigation() {
SettingsNavigation()
}