https://kotlinlang.org logo
Title
t

Trym Nilsen

01/26/2023, 12:32 PM
I’m trying to migrate some code to compose and have come across a scenario where I have a viewmodel defined in an activity with koin and would like to use this inside of a composable within a composeview in this activity. What would be the easiest way of doing this? My old non-migrated fragment used
by activityViewModel<...>()
and i wondered if there is something similar or what i would need to pass to the
getViewModel
composable to get the same result.
p

Pedro Alberto

01/26/2023, 1:30 PM
but what am currently doing is passing the viewmodel to the composable. i.e.
@Composable
fun Greeting(
    helloViewModel: ViewModel
) {
a

arnaud.giuliani

01/27/2023, 10:41 AM
The function
koinViewModel()
should be enough to retrieve your VM inside your Composable function