Skip to content

Commit

Permalink
Merge pull request #268 from UCodeUStory/master
Browse files Browse the repository at this point in the history
fix bug  ]user appcompat-v7  in version 26
  • Loading branch information
Arnaud Giuliani authored Oct 26, 2018
2 parents 7a16cf7 + b7d0354 commit 20fc5b2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Found a bug or a problem on a specific feature? Open an issue on [Github issues]

# Setup

## Actual Version
## Current Version

```gradle
koin_version = '1.0.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import org.koin.core.parameter.emptyParameterDefinition
import org.koin.standalone.KoinComponent
import org.koin.standalone.get
import kotlin.reflect.KClass
import android.support.v4.app.FragmentActivity
import android.arch.lifecycle.ViewModelStores

/**
* LifecycleOwner extensions to help for ViewModel
Expand Down Expand Up @@ -94,10 +96,16 @@ fun <T : ViewModel> LifecycleOwner.getViewModelByClass(
Koin.logger.debug("[ViewModel] ~ '$clazz'(name:'$name' key:'$key') - $this")

val vmStoreOwner = from?.invoke() ?: this as? ViewModelStoreOwner
?: error("Can't getByClass ViewModel '$clazz' on $this - Is not a FragmentActivity nor a Fragment neither a valid ViewModelStoreOwner")

var vmStore = vmStoreOwner?.getViewModelStore()
if (vmStoreOwner == null){
if (this is FragmentActivity) {
vmStore = ViewModelStores.of(this)
} else {
error("Can't getByClass ViewModel '$clazz' on $this - Is not a FragmentActivity nor a Fragment neither a valid ViewModelStoreOwner")
}
}
val viewModelProvider =
ViewModelProvider(vmStoreOwner, object : ViewModelProvider.Factory, KoinComponent {
ViewModelProvider(vmStore, object : ViewModelProvider.Factory, KoinComponent {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return get(name ?: "", clazz, parameters = parameters)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies {
By tagging your class `KoinTest`, your class become a `KoinComponent` and bring you:

* `by inject()` & `get()` - function to retrieve yoru instances from Koin
* `check` & `dryRun` - help you hceck your configuration
* `check` & `dryRun` - help you check your configuration
* `declareMock` & `declare` - to declare a mock or a new definition in the current context

[source,kotlin]
Expand Down

0 comments on commit 20fc5b2

Please sign in to comment.