https://kotlinlang.org logo
#koin
Title
# koin
c

Colton Idle

09/23/2023, 1:56 PM
One thing I'm not sure how to do in koin... I currently (with dagger/hilt + compose + nav) have this code for sharing a ViewModel between two composable destinations. Basically, I share a VM for my LoggedOutScreens nav graph
Copy code
navigation(startDestination = Screen.SignUp.route, route = Screen.LoggedOutScreens.route) {
  composable(Screen.SignUp.route) {
    val sharedVM = remember() { navController.getBackStackEntry(Screen.LoggedOutScreens.route) }

    SignUpScreen(sharedViewModel = hiltViewModel(sharedVM))
  }
  composable(Screen.Login.route) {
    val shared = remember() { navController.getBackStackEntry(Screen.LoggedOutScreens.route) }
    LoginScreen(sharedViewModel = hiltViewModel(shared))
  }
}
How would I convert this to koin?
j

Jeff Lockhart

09/23/2023, 4:38 PM
c

Colton Idle

09/23/2023, 6:59 PM
I think that's different from the behavior that i currently have though? where my vm is scoped to a smaller nav graph. To be more clear, I have another navGraph that handles the entire navigation for the app and this is just a smaller subset of that larger nav graph that just targets the "logged out screens" in my app. so tying it to the activity seems wrong?
4 Views