You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 16, 2023. It is now read-only.
Navigation to another routes creates infinite loop of recomposition in navhost.
Here is my code: jetpack navigation-compose : androidx.navigation:navigation-compose:2.4.0-alpha06
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
NavigationComposeTheme {
// A surface container using the 'background' color from the theme
Surface(color = MaterialTheme.colors.background) {
Navigation()
}
}
}
}
}
@Composable
fun Navigation(){
val navigation = rememberNavController()
NavHost(navController = navigation, startDestination = "greeting"){
composable("greeting", content = {
Greeting(name = "hello", navigation)
})
composable("greeting2", content = {
Greeting2(name = "Hii")
})
}
}
@Composable
fun Greeting(name: String, navigation: NavHostController) {
Log.e("====111111====", name)
Text(text = "Hello $name!")
navigation.navigate("greeting2")
}
@Composable
fun Greeting2(name: String) {
Log.e("====22222222====", name)
Text(text = "Hii $name!")
}