Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support AndroidX ViewModel #122

Closed
CristianGM opened this issue May 8, 2018 · 19 comments
Closed

Support AndroidX ViewModel #122

CristianGM opened this issue May 8, 2018 · 19 comments
Milestone

Comments

@CristianGM
Copy link

Is your feature request related to a problem? Please describe.
Google is changing the packaging to AndroidX, so, when we use Koin viewModel to do the injection it crashes with:
Type parameter bound for T in inline fun <reified T : ViewModel> Context.viewModel(name: String = ..., noinline definition: Definition<T> /* = (ParameterProvider) -> T */): Unit is not satisfied: inferred type MyViewModel is not a subtype of ViewModel e: ...

Describe the solution you'd like
Allow to use androidx.lifecycle.ViewModel

Describe alternatives you've considered
hum... I don't think there are not a lot of alternatives

Target Koin project
android

@arnaudgiuliani
Copy link
Member

Hello,

AndroidX is in alpha-1. Let's keep it under the hand and upgrade it when it will be in a more stable state (else we will have to regularly provide updates).

@arnaudgiuliani arnaudgiuliani added this to Release 1.0.0 in Koin Dev Board May 12, 2018
@arnaudgiuliani arnaudgiuliani added this to the 1.0.0 milestone May 16, 2018
@rosterloh
Copy link

Same issue here. I have to remove koin viewmodel injection until there is support or a workaround for this.

@arnaudgiuliani arnaudgiuliani added status:waiting and removed status:accepted accepted to be developed labels May 17, 2018
@arnaudgiuliani arnaudgiuliani moved this from Ready for release to Analysis in Koin Dev Board May 17, 2018
@arnaudgiuliani arnaudgiuliani moved this from Analysis to Ready for release in Koin Dev Board May 18, 2018
@arnaudgiuliani arnaudgiuliani added status:accepted accepted to be developed and removed status:waiting labels May 18, 2018
@arnaudgiuliani
Copy link
Member

We need to create a new koin android project to let you use the androidx library and keep compat with old support lib.

We are on it. Stay tuned 👍

@arnaudgiuliani arnaudgiuliani moved this from Accepted for current release to Analyzing in Koin Dev Board May 20, 2018
@DevHugo
Copy link

DevHugo commented May 20, 2018

I have done the change for our use. It really not that big, just some import and one dependency to change in the build.gradle.

For those who doesn't want to wait, just copy, paste the 3 classes inside android-architecture folder and update imports.

@mattmook
Copy link

I've created a fork with an androidx version, see https://github.com/mattmook/koin, however I have not currently raised a PR as it depends on the yet unreleased Android-P as well as alpha versions of androidx.

@arnaudgiuliani
Copy link
Member

@mattmook have you made it from the 1.0.0 branch?

@mattmook
Copy link

@arnaudgiuliani no, but I have just reapplied the changes... https://github.com/mattmook/koin/tree/1.0.0

Assuming you are happy with the changes I can create a PR, as stated before I haven't yet because of the pre-release nature of androidx and android-p

@arnaudgiuliani
Copy link
Member

Thanks @mattmook, I've just created the koin-androidx module - double check my changes with your changes. Just need a bit of time to test it and make deployment on bintray 👍

@arnaudgiuliani arnaudgiuliani moved this from Analyzing to In progress in Koin Dev Board May 25, 2018
@arnaudgiuliani
Copy link
Member

arnaudgiuliani commented May 25, 2018

A first version is available under koin-androidx, version 1.0.0-alpha-11.

@mattmook
Copy link

I see the other modules on bintray, but not koin-androidx. From what I remember of bintray new modules need to be explicitly linked to jcenter?

@arnaudgiuliani
Copy link
Member

arnaudgiuliani commented May 25, 2018

Argh ... yes :/ I need too link it to jcenter. Sorry.

@arnaudgiuliani
Copy link
Member

arnaudgiuliani commented May 25, 2018

koin-androidx is available in jcenter 👍

implementation "org.koin:koin-androidx:1.0.0-alpha-11"

@arnaudgiuliani arnaudgiuliani moved this from In progress to Pinned in Koin Dev Board May 25, 2018
@mattmook
Copy link

@arnaudgiuliani thanks that works well

@mattmook
Copy link

mattmook commented May 27, 2018

Looking at the updated LifecycleOwner.getViewModelByClass, with this is Fragment where fromActivity is true, should it read:

ViewModelProvider(this.activity.viewModelStore, KoinFactory)

@arnaudgiuliani
Copy link
Member

Sorry, didn't push all the last sources. But, you're right it was a glitch from my part.

https://github.com/Ekito/koin/blob/1.0.0/android/koin-androidx/src/main/java/org/koin/android/architecture/ext/android/LifecycleOwnerExt.kt#L91

@mattmook
Copy link

Cool, thanks

@arnaudgiuliani arnaudgiuliani removed the status:accepted accepted to be developed label May 29, 2018
@arnaudgiuliani arnaudgiuliani moved this from Pinned to Done in Koin Dev Board Jun 8, 2018
@arnaudgiuliani
Copy link
Member

note: package to check is koin-androidx-scope or koin-androidx-viewmodel

@stanbar
Copy link

stanbar commented Aug 15, 2018

I can't download package
Failed to resolve: org.koin:koin-androidx:1.0.0-beta-3
while
implementation "org.koin:koin-androidx-scope:$koin_version"
implementation "org.koin:koin-androidx-viewmodel:$koin_version"
are doing fine

@mattmook
Copy link

mattmook commented Aug 15, 2018

The first package is independent of androidx so is simply org.koin:koin-android:$koin_version

Documentation for the setup of the beta is https://beta.insert-koin.io/docs/1.0/documentation/koin-android/index.html#_gradle_setup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants