0
votes

I've just started to get familiar with Jetpack Compose and from what I understand, a NavHost is like a NavHostFragment, it hosts different composables rather than fragments.

What I'm struggling to understand is that if I define a screen with a scaffold and a NavHost as its content like:

setContent{
    Scaffold(...){
         NavHost(...){...}
    }
}

That makes the bottom nav bar and everything defined in the scaffold appear for every single composable hosted by the NavHost. What if I want to have different floating action buttons for different screens? Do I have to start a new activity for those screens and define a different scaffold there?

1

1 Answers

1
votes

You can actually reference the navHostController. You can either keep track of the current screen by updating a variable everytime you navigate or just use navController.getCurrentBackStackEntry?.destination to get the current screen. Use this inside your floating action button to set it accordingly