[Fix] system theme initial, toggle theme first time

This commit is contained in:
2026-06-17 02:29:21 +07:00
parent 8f97891843
commit 6a5de42b89
4 changed files with 8 additions and 3 deletions
@@ -10,8 +10,9 @@ import org.koin.compose.viewmodel.koinViewModel
@Composable
@Preview
fun App() {
val viewModel = koinViewModel<AppViewModel>()
fun App(
viewModel: AppViewModel = koinViewModel()
) {
val savedTheme = viewModel.isDarkTheme.value
val isDarkTheme = savedTheme ?: isSystemInDarkTheme()
val isLoggedIn = viewModel.isLoggedIn()
@@ -12,6 +12,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
@@ -62,6 +63,7 @@ fun MainScreen(
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination
val noNavbar = listOf(AuthDestination.route, CommunicationDestination.route)
val startRoute = rememberSaveable { if (isLoggedIn) HomeDestination.route else AuthDestination.route }
val sessionExpired by viewModel.sessionExpired
@@ -122,7 +124,7 @@ fun MainScreen(
) { innerPadding ->
NavHost(
navController = navController,
startDestination = if (isLoggedIn) HomeDestination.route else AuthDestination.route,
startDestination = startRoute,
modifier = Modifier.padding(innerPadding).fillMaxSize()
) {
composable(AuthDestination.route) { LoginScreen(navController) }