Is there a recommended way to reuse the same Andro...
# koin
j
Is there a recommended way to reuse the same Android ViewModel between different NavHost destinations? BTW I’m using Compose Navigation.
p
That's what the SharedViewModel pattern comes in. Set the ViewModel to the graph scope and access it from each route.
j
Is there a link to some documentation about this so I can read up on it?
The Documentation on the Koin website discusses using Activity/Fragment but it would nice to have the VM scoped to a nested graph.
p
https://stackoverflow.com/questions/69642441/how-to-share-a-viewmodel-between-navgraph-components-only Check above link for how you would do it without koin. To adapt koin, koin has a function that resolves the ViewModel given a ViewModelStoreOwner. So basically you would get parent NabBackstackEntry from the current backstackentry and pass it to koinViewModel