Dovydas
06/08/2025, 8:25 PMLaunchedEffect(viewModel.destination) {
// TODO: Figure out how to hide the initial transition animation
if (viewModel.destination == null) return@LaunchedEffect
navController.navigatePopUpTo(viewModel.destination!!)
val entry = navController.getBackStackEntry(viewModel.destination!!)
snapshotFlow { entry.lifecycle.currentState }
.filter { it == Lifecycle.State.RESUMED }
.first()
onUnhideContent()
}
Shubham Singh
06/09/2025, 5:06 AM@Composable
fun MyApp() {
val isLoggedIn = remember { mutableStateOf<Boolean?>(null) }
val navController = rememberNavController()
NavHost(
navController = navController,
startRoute = if (isLoggedIn == null) "loading"
else if (isLoggedIn == true) "dashboard"
else "login",
) {
composable("loading") {
CircularProgressIndicator()
}
composable("dashboard") {
DashboardScreen {
// Hide splash screen here
}
}
composable("login") {
LoginScreen {
// Hide splash screen here
}
}
}
@Composable
fun LoginScreen(onRemoveSplash: () -> Unit) {
LaunchedEffect(Unit) {
onRemoveSplash()
}
}
@Composable
fun DashboardScreen(onRemoveSplash: () -> Unit) {
LaunchedEffect(Unit) {
onRemoveSplash()
}
}
Tomislav Mladenov
06/09/2025, 11:52 AMDovydas
06/09/2025, 2:30 PMDovydas
06/09/2025, 2:30 PMJonathan
06/09/2025, 2:32 PMDovydas
06/09/2025, 2:32 PMJonathan
06/09/2025, 2:34 PMJonathan
06/09/2025, 2:35 PMDovydas
06/09/2025, 2:37 PMDovydas
06/09/2025, 2:38 PMoverride fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
var unhideContent = false
installSplashScreen().apply {
setKeepOnScreenCondition {
!unhideContent
}
}
setContent {
App(
onUnhideContent = { unhideContent = true }
)
}
}
Jonathan
06/09/2025, 2:41 PMJonathan
06/09/2025, 2:46 PMvar holdSplash: Boolean by mutableStateOf(true)
// Update the uiState
lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
mainViewModel.holdSplashOnScreen
.onEach { holdSplash = it }
.collect()
}
}
// Keep the splash screen on-screen until the UI state is loaded. This condition is
// evaluated each time the app needs to be redrawn so it should be fast to avoid blocking
// the UI.
splashScreen.setKeepOnScreenCondition { holdSplash }
Inside my VM the flow is a combine
of a few user state related flows. I add an artificial delay in the flow emission of 67 milliseconds to make sure the splash screen always stays on screen long enough to avoid the transition from Home
to Login/Signup
Dovydas
06/09/2025, 3:15 PMJonathan
06/09/2025, 3:17 PMHome
to Login/Signup
. At the end of the day it probably won’t be a big deals because you user won’t be able to accesses the Home
screen during the transition.