I'm trying to implement the following screen flow using Jetpack Compose + Jetpack Navigation:
Actually, i am able to code two singles cases:
- SplashScreen --> HomeScreen (with no BottomNavBar)
- HomeScreen (with BottomNavBar) --> Tabs
I'm not able to code the whole problem. In fact, i have an issue with the management of the NavHost. In the first case (SplashScreen -> HomeScreen) i need to call the NavHost at a high scope:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyAppTheme {
//init the Navigation Controller for screen navigation
val navController = rememberNavController()
//setup the Navigation Graph
SetupNavGraph(navController)
while in the second case i need to call it in the innerPadding scope of the Scaffold composable:
fun MainScreen(navController: NavHostController) {
Scaffold(
bottomBar = {
BottomNavBar(navController)
}
) { //innerPadding scope
//setup the Navigation Graph
SetupNavGraph(navController)
}
}
Please assume that SetupNavGraph() function works as intended (call NavHost to generate the navigation tree)
- I tried to use two
NavHostwithout success. - If i setup the
NavHostinsetContent()i'm able to load the splashscreen and move to an emptyBottomNavBarscreen. If i click on theBottomNavElementsi'm able to navigate to the child tabs (in the example above "Favorite","Music","Places", "News") but theBottomNavBardisappears - I cannot setup
NavHostin theinnerPaddingscope because this is loaded only after switching to the main screen (in the example above "Favorite Tab" + BottomBarNav)
The only workaround i found is generating the BottomNavBar composable in each of the BottomNav child tabs, but this generates a visible transition effect that i would like to avoid and, generally, doesn't seem a good practice.