compose NavHost Start the white Screen

Viewed 815

My app starts with navigation globally, but I found that when I set the following code, the app will remain blank after startup unless I manually touch the screen.

rememberSystemUiController().setStatusBarColor(
 Color.Transparent,
 darkIcons = true //This sentence must be set
)
fun AppNavigation(
    appNavController:NavHostController = LocalAppNavController.current
) {
    NavHost(
        navController = appNavController,
        startDestination = Screen.Splash.route
    ) {
        composable(route = Screen.Splash.route) {
            SplashScreen()
        }
        composable(route = Screen.HelloScreen.route) {
            HelloScreen()
        }
        composable(route = Screen.HomeScreen.route) {
            val popItem = remember{
                mutableStateOf(NULL_MEDIA_ITEM)
            }
            CompositionLocalProvider(
                LocalHomeNavController provides rememberNavController(),
                LocalNetViewModel provides hiltViewModel(),
                LocalUserViewModel provides hiltViewModel(),
                LocalHomeViewModel provides hiltViewModel(),
                LocalPopWindowItem provides popItem
            ){
                LocalUserViewModel.current.initializeController()
                HomeScreen()
            }
        }
    }

}
3 Answers

a hack way to fix this:

lifecycleScope.launch {
      delay(50)
      window.setBackgroundDrawableResource(android.R.color.transparent)
}

add this to onCreate

Put your AppNavigation fun in Scaffold:

YourAppTheme {
    Scaffold {
        AppNavigation()
    }
}
Related