nilTheDev
11/02/2021, 1:57 PMtopbar
for each navigation destination. If I use a single scaffold then how can I change the title of the topbar? One way would be to store the name as a state and pass a lambda to each destinations that they can invoke to change the name of the topbar.
Something like this,
var topBarTitle by remember { mutableStateOf("Title") }
Scaffold(
topBar = { TopAppBar( title = Text(title), ... ) }
){
NavigationDestination{ title ->
topBarTitle = title
}
}
@Composable
fun NavigationDestination(changeTopbarName: (String) -> Unit){
changeTopbarName("Some Title")
...
}
Would using LaunchedEffect
make sure that the changeTopbarName
function will only be executed during composition and not on each recompositions?
Would it be a good approach?