Qamar Khan
09/01/2023, 11:05 PMQamar Khan
09/01/2023, 11:06 PMQamar Khan
09/01/2023, 11:08 PMQamar Khan
09/01/2023, 11:09 PMQamar Khan
09/01/2023, 11:12 PMdewildte
09/01/2023, 11:40 PMCoroutineCreationDuringComposition
warning.
That warning is telling you that every time the Composable is recomposed it is creating a new coroutine.
That coroutine is not being cancelled and therefore is still collecting from the navigationManagers.commands
Flow.
You now have 1+ (N Recompositions) telling the navController
to navigate
to the destination
.
That will cause multiple navigations to the same destination
.dewildte
09/01/2023, 11:41 PMCoroutineScope
is being remembered so it’s children coroutines will not be cancelled.dewildte
09/01/2023, 11:42 PMLaunchedEffect(scope) { consume commands here }
instead.Qamar Khan
09/01/2023, 11:55 PMascii
09/02/2023, 6:38 AMcollectAsState
.
In any case, this feels unrelated to your original issue, at least on the surface.ascii
09/02/2023, 6:41 AMconfigChanges="locale"
is not enough; you'd need layoutDirection
too.
And there's no point in implementing the config changed callback if it's not doing anything.
Side-note: generally speaking, if your UI is fully-Compose you'd benefit from putting everything into configChanges
, because Compose can react to colors, density, etc too.dewildte
09/02/2023, 2:48 PMQamar Khan
09/02/2023, 2:52 PMAppCompatDelegate.setApplicationLocales(
LocaleListCompat.forLanguageTags(
state.selectedLocale
)
)
Qamar Khan
09/02/2023, 2:55 PMclass NavigationManager {
var commands = Channel<NavigationCommand>(Channel.CONFLATED). // Actually this commands print cancelled,capacity=1,data=[]
fun navigate(directions: NavigationCommand) {
Log.e("command", commands.toString())
val scope = CoroutineScope(Dispatchers.Default)
scope.launch {
try {
commands.trySend(directions)
} catch (e: Exception) {
Log.e("exception", e.printStackTrace().toString())
} finally {
scope.cancel()
}
}
}when i print then logs --> cancelled,capacity=1,data=[]
even we are providing this class from hilt,
@Provides
@Singleton
fun providesNavigationManager() = NavigationManager()
dewildte
09/02/2023, 2:59 PMQamar Khan
09/02/2023, 3:01 PMdewildte
09/02/2023, 3:02 PMdewildte
09/02/2023, 3:03 PMdewildte
09/02/2023, 3:03 PMQamar Khan
09/02/2023, 3:07 PMdewildte
09/02/2023, 3:07 PMdewildte
09/02/2023, 3:09 PMQamar Khan
09/02/2023, 3:09 PMscope.launch {
mainViewModel.navigationManager.commands.consumeAsFlow().collect {
if (it.destination.isNotEmpty()) {
navController.navigate(it.destination)
route = it.destination
} else {
println(it.toString())
}
}
}
see we are observing from navigation Manager class inside the activityQamar Khan
09/02/2023, 3:10 PMQamar Khan
09/02/2023, 3:12 PMdewildte
09/02/2023, 3:13 PMQamar Khan
09/02/2023, 4:02 PMdewildte
09/02/2023, 4:13 PMdewildte
09/02/2023, 4:13 PM