Jonathan
10/02/2024, 4:12 PMuli
10/02/2024, 5:33 PMJonathan
10/02/2024, 5:36 PMuli
10/02/2024, 5:49 PMJonathan
10/02/2024, 5:56 PMNavGraphBuilder.navigation {}
extension function? I definitely think it’s an anti-pattern to use a NavHost inside of NavGraphBuilder.composable {}
.uli
10/02/2024, 5:57 PMJonathan
10/02/2024, 5:57 PMNavGraphBuilder.navigation {}
should take care of creating a child nested graph that’s appropriately linked to the parent graph.. Using a nested NavHost would need its own controller. It’s completely separate from the parent Nav. Graph so you cannot route to it’s children.uli
10/02/2024, 5:58 PMuli
10/02/2024, 5:58 PMJonathan
10/02/2024, 5:59 PMuli
10/02/2024, 6:00 PMuli
10/02/2024, 6:01 PMJonathan
10/02/2024, 6:02 PMfactory {}
and single {}
don’t work for me.Jonathan
10/02/2024, 6:03 PMuli
10/02/2024, 6:03 PMuli
10/02/2024, 6:04 PMuli
10/02/2024, 6:05 PMscoped
still seems right. Except you need to manage the scope manually. I.e. you need to find a hook to close the scope.uli
10/02/2024, 6:08 PMnavigation {}
is not a composable, it does not have a lifecycle. But you might be able to otherwise observe navigating out of your sub-graph.Jonathan
10/02/2024, 6:08 PMkoinViewModel()
works and replicate for any component.uli
10/02/2024, 6:09 PMuli
10/02/2024, 6:10 PMnavigation{}
does not have a lifecycle.Jonathan
10/02/2024, 6:12 PMuli
10/02/2024, 6:18 PMuli
10/02/2024, 6:19 PMnavigation{}
but only inside the hierarchy of composables.uli
10/02/2024, 6:20 PMscoped
from koin and check if observing navController.currentBackStackEntryAsState gives you a hook to close the scopeJonathan
10/02/2024, 6:20 PMcomposable {}
so that won’t be an issue.Jonathan
10/02/2024, 6:21 PMkoinViewModel()
is a Composable function so it would behave similarly to that; my issue now is getting scope objects that aren’t viewmodels.uli
10/02/2024, 6:22 PMMihai Batista
10/04/2024, 8:19 PMJonathan
10/07/2024, 6:54 PMMihai Batista
10/08/2024, 10:24 AMflow1
that uses dependencies scoped to the flow lifetime - here FlowRepository
is scoped to the flow lifetime and discarded once the flow is left. and flow2
that uses dependencies from the root scope.
The composable that takes care of resolving the correct scope and pass it through CompositionLocal is https://github.com/mihbt/autoconnect-koin-scope/blob/main/app/src/main/java/com/example/koinscope/di/utils/AutoConnectKoinScope.kt and is plugged-in above the app navHost.Jonathan
10/08/2024, 2:24 PMonDispose {}
? If AutoConnectKoinScope()
is ever removed from Composition it will no longer update lastKnownNavGraphRoute and if it is returned to the composition, it could have an inaccurate route. Not sure if this could cause subtle bugs.Mihai Batista
10/08/2024, 3:34 PMonDispose
. I see two cases when AutoConnectKoinScope
leaves the composition, when there is a configuration change and when the process is killed due to memory pressure - in both cases when the activity is recreated, compose takes care of restoring the previous UI state, that’s why is important to keep around the last known nav route.
I’ve spotted one issue with the global variable though - it will create issues in the second case, because the value is lost and the correct scope cannot be resolved. That’s why I’ve updated implementation to store the last known state in the activity bundle instead to survive the process death - the update is in this file https://github.com/mihbt/autoconnect-koin-scope/blob/main/app/src/main/java/com/example/koinscope/di/utils/AutoConnectKoinScope.ktMihai Batista
10/08/2024, 3:40 PMarnaud.giuliani
10/16/2024, 7:01 AMMihai Batista
10/17/2024, 10:53 AM