Skip to content

Instantly share code, notes, and snippets.

@GibsonRuitiari
Created September 6, 2022 14:35
Show Gist options
  • Save GibsonRuitiari/a70591971b14953b0c799401458e0765 to your computer and use it in GitHub Desktop.
Save GibsonRuitiari/a70591971b14953b0c799401458e0765 to your computer and use it in GitHub Desktop.
package com.ciru.practice
import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
/**
* Pass in an instance of [loginViewModel] and [navController]
* Reason why we are not instatiating/creating our viewmodel instance is here
* is that whenever this composable will be recomposed, a new viewmodel instance will always be created
* and that is too expensive, hence why we just pass a reference of the [loginViewModel]
* and leave the activity to do the initialization of both the viewmodel and nav controller
*/
@Composable
fun Screen(loginViewModel: LoginViewModel,navController: NavHostController,){
NavHost(
navController = navController,
startDestination = MainContent.Boo.route
){
composable(route = MainContent.Boo.route){
Boo(loginViewModel = loginViewModel,navController = navController)
}
composable(route = MainContent.Bae.route){
Bae(loginViewModel = loginViewModel,navController = navController)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment