-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
feat: added support to have navigator scoped ViewModel #217
base: main
Are you sure you want to change the base?
feat: added support to have navigator scoped ViewModel #217
Conversation
1e3bfb0
to
a6690ff
Compare
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.. |
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 |
voyager-core/src/androidMain/kotlin/cafe/adriel/voyager/androidx/AndroidScreenLifecycleOwner.kt
Outdated
Show resolved
Hide resolved
voyager-core/src/androidMain/kotlin/cafe/adriel/voyager/androidx/AndroidScreenLifecycleOwner.kt
Outdated
Show resolved
Hide resolved
...gator/src/commonMain/kotlin/cafe/adriel/voyager/navigator/model/NavigatorScreenModelStore.kt
Outdated
Show resolved
Hide resolved
feat: navigator scoped viewmodel
a6690ff
to
e6fc71f
Compare
voyager-core/src/androidMain/kotlin/cafe/adriel/voyager/androidx/ContextExt.kt
Outdated
Show resolved
Hide resolved
...tor/src/commonMain/kotlin/cafe/adriel/voyager/navigator/lifecycle/NavigatorLifecycleStore.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should move this Android ViewModel specific API to it own module. Maybe restaure previous know voyager-androidx
module
...ger-screenmodel/src/commonMain/kotlin/cafe/adriel/voyager/core/model/NavigatorScreenModel.kt
Outdated
Show resolved
Hide resolved
// 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? | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not required if you remove the navigator sopced screen models
voyager-hilt/src/main/java/cafe/adriel/voyager/hilt/ViewModel.kt
Outdated
Show resolved
Hide resolved
hi, are there any plans to merge this? |
@osrl we have a experimental support for it on the new Lifecycle KMP API. |
any idea how to inject a viewmodel using koin into this |
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
Screen
has your ownViewModelStoreOwner
that 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:
@HiltViewModel
has support now to use scoped ViewModel. To have or to get scoped ViewModel just provide to hilt function a ViewModelStoreOwner