简体   繁体   中英

compose NavHost Start the white Screen

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()
            }
        }
    }

}

Put your AppNavigation fun in Scaffold:

YourAppTheme {
    Scaffold {
        AppNavigation()
    }
}

It seems like a known issue: https://issuetracker.google.com/issues/227926002

As of comments - different Xiaomi models affected. My POCO one affected too.

a hack way to fix this:

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

add this to onCreate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM