How to change topBar corresponding screen in Jetpack Compose

Viewed 756

I have a Scaffold like this:

Scaffold(
   topBar = {
       TopBar(...)
   },
   bottomBar = {
       BottomNavigationBar(...)
   }
) {
    NavHost(...)
}

What is the best way to change TopBar when I navigate to another screen?

1 Answers

There are two possible ways to go:

  1. Observing currentScreen and use when inside topBar and change it according to that

  2. Put topbar inside the screen it belongs to.

For me prefer the second one since it's not shared with each other, there's no reason to use ugly when statement for it.

Related