Open heesung6701 opened 3 weeks ago
Hello, thanks for your contribution.
What would be the need to make a difference, if at the end we use the same API to declare a ViewModel?
Hello, thanks for your contribution.
What would be the need to make a difference, if at the end we use the same API to declare a ViewModel?
we just want to use koin-annotation with lifecycle-viewmodel:2.0.0. but now, we can't use because koin-annotation doesn't support new viewmodel that moved from androidMain to commonMain.
this PR is just my suggestion for support two kind of viewModel between androidMain(previous) and commonMain(new).
we need to support two version of ViewModel. first one is ViewModel on AndroidMain, and second one is ViewModel on commonMain that released on latest version for support KMP.
I hoped to defined minimum version of lifecycle-viewmodel on koin-annotation, but we can't because we don't know which version used on host.
so I just make two definition and delegated to select via host
for support KMP, androidx's viewmodel moved from androidMain to commonMain. then host's viewmodel also moved to commonMain. but current version of koin-annotation doesn't support viewmodel on common main. they only support for VM on androidMain. so host who want to migrate to latest version of lifecycle-viewmode, they can't use KoinViewModel of koin-annotation.
Summary
I added new KoinViewModel annotation for supporting KMP
Content
with koin-annotations:1.3.1 and lifecycle-viewmodel:2.0.0, generated kt file use org.koin.compose.viewmodel.dsl.viewModel rather than org.koin.androidx.viewmodel.dsl.viewModel.
because Koin-annotation compiler can't know version of lifecycle-viewmodel's version, I added org.koin.compose.viewmodel.dsl.viewModel for koinViewModel with KMP.
Implementation
I added KOIN_VIEWMODEL_KMP as new Definition Annotation
Example
below is exampled of generated Kotlin file
TOBE