Hi, I was wondering how to scope viewModel to its parent fragment? in previous version we could do something like:
val viewModel by sharedViewModel<SomeViewModel>(from = { parentFragment!! })
but the
from
seems to be removed in the current
2.1.5
version. Any reason why was it removed? and what to do instead?
a
aipok
05/18/2020, 10:47 AM
isn’t something like this working
Copy code
requireParentFragment().sharedViewModel()
?
a
Archie
05/18/2020, 10:48 AM
oh i see... that never occured to me... i will try.. thank you verymuch
a
aipok
05/18/2020, 10:50 AM
basic idea is to get an instance from the parent fragment scope, not from the scope of the current fragment. I’m using same scenario with activity. But I remember it was working with parent fragment as well.
a
Archie
05/18/2020, 10:51 AM
oh wait..
parentFragment.sharedViewModel()
still scopes the viewModel to the activity and not the parent fragment... maybe