-
-
Notifications
You must be signed in to change notification settings - Fork 144
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
Shared ScreenModel between screens #168
Comments
Well, a ScreenModel is remembered by Compose SlotTable and associated to a Screen. The idea is the same as Android ViewModel. Can you share a ViewModel with two Activities?
I have not tested that but as you can see in the code a remembered ScreenModel is associated to a Screen. So, a Singleton Screen should works |
but you can share a viewmodel with two fragments via navhost. it's a pretty common usage. |
I've found a temporary solution using Koin.
implementation("io.insert-koin:koin-core:3.4.3")
implementation("io.insert-koin:koin-compose:1.0.4")
KoinApplication(application = {
modules(appModule)
}) {
val appScreenModel = koinInject<AppScreenModel>() |
but this is scoped to entire app. it's never disposed right? |
Has anyone found a solution to this? |
checkout #217 |
I think the main question here is: Where do we will scope it.
|
I had add new API for Navigator scoped ScreenModel, checkout, it is available starting from Docs: https://voyager.adriel.cafe/screenmodel#navigator-scoped-screenmodel |
#217 will still be needed for ViewModels. Do you plan merging it? |
Is there a way to share the same ScreenModel between screens?
The text was updated successfully, but these errors were encountered: