feat: added support to have navigator scoped ViewModel#217
Closed
programadorthi wants to merge 5 commits intoadrielcafe:mainfrom
Closed
feat: added support to have navigator scoped ViewModel#217programadorthi wants to merge 5 commits intoadrielcafe:mainfrom
programadorthi wants to merge 5 commits intoadrielcafe:mainfrom
Conversation
1e3bfb0 to
a6690ff
Compare
This was referenced Sep 24, 2023
Contributor
|
Any update on this PR? |
|
@programadorthi Is is possible for you to release this on your own fork? This is really a big challenge for me.. |
Collaborator
Author
|
Sorry guys. I can't. You will have to wait for owners review to check and avoid breaking changes. |
|
I'm really looking forward to this feature |
DevSrSouza
reviewed
Oct 17, 2023
DevSrSouza
reviewed
Oct 17, 2023
DevSrSouza
reviewed
Oct 17, 2023
feat: navigator scoped viewmodel
a6690ff to
e6fc71f
Compare
DevSrSouza
reviewed
Jan 9, 2024
DevSrSouza
requested changes
Jan 9, 2024
DevSrSouza
previously requested changes
Jan 9, 2024
Collaborator
There was a problem hiding this comment.
I think we should move this Android ViewModel specific API to it own module. Maybe restaure previous know voyager-androidx module
DevSrSouza
reviewed
Jan 9, 2024
DevSrSouza
reviewed
Jan 9, 2024
Comment on lines
+71
to
+80
| // Public: used in Navigator Scoped ScreenModels | ||
| @InternalVoyagerApi | ||
| public inline fun <reified T : ScreenModel> getOrNull( | ||
| holderKey: String, | ||
| tag: String? | ||
| ): T? { | ||
| val key = getKey<T>(holderKey, tag) | ||
| return screenModels[key] as T? | ||
| } | ||
|
|
Collaborator
There was a problem hiding this comment.
This is not required if you remove the navigator sopced screen models
ghostbear
reviewed
Jan 10, 2024
Contributor
|
hi, are there any plans to merge this? |
Collaborator
|
@osrl we have a experimental support for it on the new Lifecycle KMP API. |
Contributor
|
any idea how to inject a viewmodel using koin into this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ISSUES SOLVED: #155 #168 and #210
Navigator scoped screen model was added on the #233
AndroidX ViewModel has support to scoped ViewModel here
So, we are supporting scoped ViewModel in Voyager too. How it works?
Androidx has a function
viewModel {}that use the local ViewModelStoreOwner so scoped ViewModel is supported by default.By default each
Screenhas your ownViewModelStoreOwnerthat doesn't support scoped and each screen will have a unique instance.To have ViewModel scoped to a Navigator and share the same instance between screens do:
If you have a ViewModel scoped to Activity or Fragment do:
@HiltViewModelhas support now to use scoped ViewModel. To have or to get scoped ViewModel just provide to hilt function a ViewModelStoreOwner