When using NavHost, sometimes incorrect animations appear, but not when using AnimatedContent.
Navigation compose version: 2.8.0-alpha05
Compose ui version: 1.7.0-beta04
Kotlin version: 2.0.0
@Composable
fun MainScreen() {
// val navController = rememberNavController()
val state = remember { mutableStateOf(0) }
Scaffold(
bottomBar = {
NavigationBar {
TabNavigationItem(state, Tab.Home)
TabNavigationItem(state, Tab.Favorites)
TabNavigationItem(state, Tab.Profile)
}
}
) {
//Works well
AnimatedContent(
state.value,
modifier = Modifier.fillMaxSize().padding(it),
transitionSpec = {
(fadeIn(animationSpec = tween(220, delayMillis = 90))
.togetherWith(fadeOut(animationSpec = tween(220, delayMillis = 90))))
}
) { target ->
when (target) {
0 -> HomeScreen()
1 -> FavoritesScreen()
else -> ProfileScreen()
}
}
//Sometimes incorrect animation
// NavHost(
// navController = navController,
// startDestination = Tab.Home.route,
// modifier = Modifier.padding(it),
// ) {
// homeDestination()
// favoritesDestination()
// profileDestination()
// }
}
}
enter image description here
New contributor
Kirk Lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.