question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bring back the `from` parameter in SharedViewModel property delegate

See original GitHub issue

Is your feature request related to a problem? Please describe. In the newest version of Koin: 2.1.3 I cannot easily make a custom scope for my ViewModel.

Describe the solution you’d like In version 2.0.1 of Koin, which I am using right now, there is a parameter from in SharedViewModel property delegate. In the newest version, 2.1.3 this parameter is gone.

Describe alternatives you’ve considered As discussed in this topic: #442, the current solution is: val owner = requireParentFragment().requireParentFragment().findNavController().getViewModelStoreOwner(navGraphId) But is is not elegant. I liked the from parameter much more.

Target Koin project Do not know. 😃

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:11
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
arnaudgiulianicommented, Oct 8, 2020

This param is owner not from 👍

image

0reactions
Kenny50commented, Aug 9, 2021

for those who didn’t find answer owner param without findNavController()

I currently facing one parent fragment and three child fragment, and the solution is

//parent
    private val parentViewModel by viewModel<TripParentViewModel>()

//child
private val viewModel: TripParentViewModel by viewModel(owner = { ViewModelOwner.Companion.from(requireParentFragment().requireParentFragment().viewModelStore)})

BE CAUTION: I call requireParentFragment twice because i use fragmentContainerView in parent fragment. depend on your project, you might need to change to once or whatever situation you facing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Shared ViewModel Across Fragments - Android Developers
You will learn how to use a shared ViewModel to share data between the fragments of the same activity and new concepts like...
Read more >
Advanced ViewModels (part III): Sharing data between ...
Per documentation, by activityViewModels is a property delegate to get a reference to the ViewModel scoped to its Activity. So, our shared ViewModel...
Read more >
Get the same instance of ViewModel in Fragment which is ...
Using KOIN. ViewModel instance can be shared between Fragments and their host Activity. To inject a shared ViewModel in a Fragment use:
Read more >
Android ViewModel & Navigation | Koin
To inject a shared ViewModel in a Fragment use: by activityViewModel() - lazy delegate property to inject shared ViewModel instance into a property...
Read more >
Shared ViewModel - Explained | Android Studio Tutorial
My Online Courses ⭐Discount Coupon: LAUNCH-STEVDZA-SANhttps://stevdza-san.com ‍ Wanna become a member?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found