voyager icon indicating copy to clipboard operation
voyager copied to clipboard

ViewModels should be able to be scoped

Open osrl opened this issue 2 years ago • 4 comments

Android has scoped ViewModels with navGraphViewModels as shown in here. Since we don't have navGraphViewModels in voyager, we can't use scoped states with ViewModels. (Although it may be possible using AndroidScreenLifecycleOwner. But I couldn't figure out how) Same should apply to ScreenModel too.

osrl avatar Aug 30 '23 08:08 osrl

@osrl Checkout pull request #217

programadorthi avatar Sep 24 '23 17:09 programadorthi

will do. thank you very much.

osrl avatar Sep 25 '23 07:09 osrl

I think my answer here apply to this issue as well: https://github.com/adrielcafe/voyager/issues/168#issuecomment-1766124366

you could also try this to have scoped viewmodels: viewModel<YourScopedViewModel>(viewModelStoreOwner = LocalContext.context.unwrapActivity)

DevSrSouza avatar Oct 17 '23 10:10 DevSrSouza

I'm currently using this but my app is single activity and this makes it scoped to the entire app

osrl avatar Nov 06 '23 11:11 osrl