From 2aa77aa4770948aa27d027ba061c218d32c89a85 Mon Sep 17 00:00:00 2001 From: kaaveh Date: Tue, 24 Jan 2023 18:12:59 +0330 Subject: [PATCH] [bugfix] handle instance of baseViewModel --- .../java/ir/kaaveh/composenews/ui/MainActivity.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/ir/kaaveh/composenews/ui/MainActivity.kt b/app/src/main/java/ir/kaaveh/composenews/ui/MainActivity.kt index f2388a53..3de2deb8 100644 --- a/app/src/main/java/ir/kaaveh/composenews/ui/MainActivity.kt +++ b/app/src/main/java/ir/kaaveh/composenews/ui/MainActivity.kt @@ -9,6 +9,10 @@ import androidx.compose.material.Scaffold import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Favorite import androidx.compose.material.icons.filled.Home +import androidx.compose.runtime.getValue +import androidx.compose.runtime.setValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.lifecycle.compose.ExperimentalLifecycleComposeApi import androidx.navigation.compose.currentBackStackEntryAsState @@ -26,9 +30,6 @@ import ir.kaaveh.navigation.Destinations @AndroidEntryPoint class MainActivity : ComponentActivity() { - // TODO: handle viewModel more properly - private var baseViewModel: BaseViewModel = BaseViewModel() - private val items = listOf( BottomNavItem( name = "News", @@ -47,6 +48,10 @@ class MainActivity : ComponentActivity() { setContent { ComposeNewsTheme { + // TODO: handle viewModel more properly + var baseViewModel: BaseViewModel by remember { + mutableStateOf(BaseViewModel()) + } val navController = rememberNavController() val backStackEntry = navController.currentBackStackEntryAsState() val currentScreenRoute = backStackEntry.value?.destination?.route