Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scope ViewModel to NavHost #385

Open
dwass opened this issue Sep 30, 2024 · 1 comment
Open

Scope ViewModel to NavHost #385

dwass opened this issue Sep 30, 2024 · 1 comment

Comments

@dwass
Copy link

dwass commented Sep 30, 2024

I would like to scope a ViewModel to a NavHost (NavGraph). I have a series of screens (scenes), which are used like a wizard, to walk the user through a process of providing a bunch of input fields. I would like to create a single ViewModel that can capture all of this data, as I think having separate ViewModels for each of these screens is a) overkill and b) ties the ViewModel to closely to the specific View implementation (It should be possible, on larger screens for example, to have all the input collected in a single screen instead of providing the wizard-like multi-screen approach).

At the moment, the ViewModel is created where the (nested) NavHost is located and passed around to all the other screens. I would prefer to have each View "get" the ViewModel using a shared-ViewModel concept so I don't need to pass the ViewModel around. If the ViewModel could be scoped to the NavHost (NavGraph), then this should be possible, I just don't know how to do it.

Is this possible? If so, please explain how.

@Tlaster
Copy link
Owner

Tlaster commented Oct 1, 2024

Currently ViewModel can not scoped to an NavHost, so the best way is to passing a ViewModel in a Nested NavHost, just like what you do right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants