iamthevoid
05/31/2021, 12:53 PMnavController.currentBackStackEntryFlow
and must to do it in CoroutineScope. I have few questions
1. Where can I read about relation of coroutines and composables
2. Where better to collect this flow? Looks like there are mechanisms in compose to handle coroutines, but i am not sure that good practice to do as i did.
3. Even if it is good practice - what is better to use as key for LaunchedEffect
? I select activity, but it seems meaninglessDominaezzz
05/31/2021, 12:56 PMcollectAsState
.
If you give me a copy/pastable snippet, I can show you.iamthevoid
05/31/2021, 1:01 PMval route by navController.currentBackStackEntryFlow
.map { it.destination.route.orEmpty() }
.collectAsState(initial = START_ROUTE)
Got it. ThanksDominaezzz
05/31/2021, 1:03 PMremember
there.
val route by remember(navController) {
navController.currentBackStackEntryFlow
.map { it.destination.route.orEmpty() }
}
.collectAsState(initial = START_ROUTE)
iamthevoid
05/31/2021, 1:05 PMAdam Powell
05/31/2021, 1:47 PMZach Klippenstein (he/him) [MOD]
05/31/2021, 3:33 PMIan Lake
06/01/2021, 6:59 PMcurrentBackStackEntryAsState()
method that does the right thing: https://developer.android.com/reference/kotlin/androidx/navigation/compose/package-summary#(androidx.navigation.NavCon[…]rentBackStackEntryAsState()
val currentRoute = navController.currentBackStackEntryAsState()?.destination?.route ?: START_ROUTE