Get scoped viewmodel from child fragment
See original GitHub issueLet’s say I have a module for my fragment.
scope(named<MyFragment>()) {
viewModel {
MyFragmentVM(
get(),
get(),
get(),
get()
)
}
}
From MyFragmentVM
I open a dialog fragment, where I pass MyFragment
’s scopeId. From my dialog on some action I would like to call my MyFragmentVM's
method.
Is there any way to get the MyFragmentVM
?
I can see some methods, but they require ViewModelParameters
and so on.
I need smth that does not require anything else but scope/scopeId.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:10
Top Results From Across the Web
How to scope a view model to a parent fragment?
Using Fragment-ktx libr in your app you can get viewModel as below in your app-> build.gradle
Read more >Get parent fragment viewModel from child fragment inside ...
I have a parent fragment with ViewModel and viewPager2 inside it creates 4 child fragments, I want to get parent viewModel from child...
Read more >Communicating with fragments - Android Developers
These fragments can share a ViewModel using their activity scope to handle this communication. By sharing the ViewModel in this way, the ...
Read more >ViewModel scopes - RainbowCake
ViewModels by default are scoped to their Fragment, meaning a new instance is created for every new instance of the Fragment (barring configuration...
Read more >A step by step guide on how to use Nav-graph Scoped ...
Scope your viewmodel to an Activity and move on with your life. ... Create a nested navigation graph that contains all fragments you'd...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So here we’re back again. As I told before - I don’t need a sharedviewmodel for the case described above. I need to get my fragment’s NOT shared view model from a dialog. In case of shared vm it will outlive fragment, what’s not good in my case. So as I can see there’s no way to get NOT shared vm from a child fragment event if you have the scopeId.
Yo can use this too
scope(named<YourFragmentClass>()) { viewModel { YourFragmentClassViewModel(get()) } scoped { UseCaseExample(get()) } }
and in your YourFragmentClass just add extended with AndroidScopeComponent and create
and that’s all