简体   繁体   中英

Jetpack compose slowly loading Navigation

I am trying simple navigation between composables and i noticed a performance issue during launch of the MainActivity, i am using splashScreen api for splash screen and then setting the content

 installSplashScreen()
    super.onCreate(savedInstanceState)

    setContent {
        MyTheme {
            Navigation()
        }
    }

the issue is after the splashscreen and before my First composable showing there's an empty screen for a second, i tried to remove the Navigation and tried my composableScreen directly and it works fine, no empty black screen in between this is my navigation composable

  @Composable
fun Navigation(
    modifier: Modifier = Modifier,
    navController: NavHostController = rememberNavController(),
    startDestination: String = ScreenRoutes.Ls.route,
) {
    NavHost(
        modifier = modifier,
        navController = navController,
        startDestination = startDestination
    ) {
        composable(route = ScreenRoutes.Ls.route) {
            Ls() { destination ->
                when (destination) {
                    ScreenRoutes.Ms-> {
                        navController.navigate(destination.route) {
                            popUpTo(0)
                        }
                    }
                    ScreenRoutes.Fp-> {
                        navController.navigate(destination.route)
                    }
                    ScreenRoutes.Ls-> {}
                    ScreenRoutes.Sc-> {
                        navController.navigate(destination.route)
                    }
                    ScreenRoutes.Up -> navController.navigateUp()
                }
            }
        }

        composable(route = ScreenRoutes.Sc.route) {
            Sc() { destination ->
                if (destination == ScreenRoutes.Up && navController.previousBackStackEntry != null) {
                    navController.navigateUp()
                } else {
                    navController.navigate(destination.route) {
                        popUpTo(0)
                    }
                }

            }
        }

        composable(route = ScreenRoutes.Ms.route) {
            Ms() {

            }
        }

        composable(route = ScreenRoutes.fg.route) {
            ForgotPassword() { destination ->
                if (destination == ScreenRoutes.Up && navController.previousBackStackEntry != null) {
                    navController.navigateUp()
                } else {
                    navController.navigate(destination.route)
                }

            }
        }
    }
}

is there any possible optimization, or making the splash to not be removed until the completion of composition, i tried with release variant since it have minify is enabled and proguard, and it's showed slightly better results but the intermediate empty screen still exists

Does the issue persist on a real phone and emulator? If it is only on the emulator, it could be that your hardware can't keep up with your work.

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