oday
12/21/2023, 11:22 PMcomposable
inside is scaffoldState
where I go scaffoldstate.value.title = { Text("Screen A" }
and the primary Scaffold just populates its own topAppBar with MyAppBar(title = scaffoldState.title)
but this causes a lot of jank when switching between bottom bar destinations and sometimes one screen ends up with the title of the other and it's just bad
having 2 Scaffolds causes a visual effect where you can see them being swapped out, Now In Android does it really well but the code is so convoluted I couldn't really pin down even where the switch was happeningyousefa2
12/22/2023, 10:51 AModay
12/22/2023, 10:56 AMyousefa2
12/22/2023, 11:05 AMMutableState
to other composables ..but something like this
val navController = rememberNavController()
Scaffold (
appBar = {
AppBar(
title = {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination?.route
val title = when(currentDestination) {
"profile" -> "Profile"
"friendslist" -> "Friends"
else -> null
}
title?.let { Text(it) }
}
)
}
) {
NavHost(navController = navController, startDestination = "profile") {
composable("profile") { Profile(/*...*/) }
composable("friendslist") { FriendsList(/*...*/) }
}
}
Where the title is a function of the current route instead of an input from a child composable.oday
12/22/2023, 11:06 AModay
12/22/2023, 11:06 AModay
12/22/2023, 11:06 AMyousefa2
12/22/2023, 11:06 AModay
12/22/2023, 3:45 PMFabio Berta
12/22/2023, 3:54 PMFabio Berta
12/22/2023, 3:54 PModay
12/22/2023, 3:55 PMFabio Berta
12/22/2023, 3:55 PModay
12/22/2023, 3:55 PMFabio Berta
12/22/2023, 3:56 PMFabio Berta
12/22/2023, 3:57 PM