Skip to content

Commit

Permalink
Merge pull request #6 from stanwood/feature/SFW-295-improve-viewmodel…
Browse files Browse the repository at this point in the history
…-handling

SFW-295 Fix dagger always returning the same view model instance, ret…
  • Loading branch information
ubuntudroid authored Dec 5, 2018
2 parents 4d91ca9 + 353a3e5 commit 4a21199
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
1 change: 0 additions & 1 deletion di/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class HomeFragment : Fragment(), HasSupportFragmentInjector {
There is not much to do for ViewModels except for adding a constructor annotated with `@Inject`:

```kotlin
@FragmentScope
class HomeViewModel @Inject constructor(/* inject properties here if you want */) : ViewModel() {}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ package io.stanwood.framework.arch.di.factory

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import dagger.Lazy
import javax.inject.Inject
import javax.inject.Provider

class ViewModelFactory<T : ViewModel> @Inject constructor(
private val viewModel: Lazy<T>
private val viewModel: Provider<T>
) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>): T = viewModel.get() as T
Expand Down

0 comments on commit 4a21199

Please sign in to comment.