hi guys, I had a problem with compose and navigati...
# compose
t
hi guys, I had a problem with compose and navigation. I have 2 screens, splash screen, stimulate delay some time and then navigate to home screen. it navigates normally but home screen blinking and I found splash screen is recompose again again. So this is problem from compose or my implementation is wrong? Please help me!!!
a
do you have code that we could look at ?
t
yup, here is my code
n
Why calling popBackStack() before navigate()?
a
What does onTimeOut doing ? also why not use something like LaunchedEffect and then add a delay in the LaunchedEffect and then change the isSplashing state
Copy code
LaunchedEffect{
delay(1000)
isSplashing = true 
}
then you don't need to use a artificial timeout
t
@Nabeel I searched some from stackoverflow and and try their solution but it seems doesn't work
@Abhishek Dewan seems your solution doesn't work, I think problem comes from navigation because state of current destination hasn't been saved. cause screen content recompose forever
n
navController.navigate("home") { popUpTo("splash") { inclusive = true } } Use this way and remove popBackStack() call
t
thank @Nabeel but result still the same, home screen still blinking :3
n
I think it's the default crossfade effect. Can you please show some screencast of the blinking?
t
it still the same status with old code. from the logcat, I think navController doesn't keep its state and recompose to splash then navigate to home and blinking
n
@treatmaster I had this exact same issue. But in my case, the splash uses a dark color even in light mode. So this was causing the blink effect. To fix this, I set the decorView background color as the same of the splash screen.
Copy code
FullScreenTranslucent(
    windowBackgroundColor = AppTheme.colors.surfaceDark,
) {
    SplashScreenContent()
}
FullScreenTranslucent
is a custom composable which basically do this:
Copy code
val context = LocalContext.current
if (context is Activity) {
    context.window.run {
        ...
        decorView.setBackgroundColor(
            windowBackgroundColor
        )
    }
}
content()
t
thank @nglauber I'll try your solution and give back result later. but my mind still think this problem comes from navigation because the state isn't keep when I navigate to Homescreen. You could see in my logcat, compose still recomposes splash screen then navigate to home screen.