https://kotlinlang.org logo
#koin
Title
# koin
s

Stylianos Gakis

03/29/2023, 9:58 PM
Reading the docs for the new compose 3.4.3 release and the note “[NEW] - handle ViewModel and Navigation with koinNavViewModel() function”. Are there any docs that explain exactly what this function is doing? And specifically what extra is it doing compared to the
koinViewModel
@Composable function? I can’t find a README on that module in the project, nor any specific docs, but I could definitely be missing something.
👀 2
a

arnaud.giuliani

03/31/2023, 1:19 PM
yes good point, the difference between koinViewModel and koinNavViewModel is the ability to handle the NavBackStackEntry
image.png
s

Stylianos Gakis

03/31/2023, 1:40 PM
Right, could you elaborate a bit more about what you mean by “Handle”? I am not well-versed enough in how navigation deals with this and what NavBackStackEntry is to understand only from looking at this code snippet unfortunately 😕
The NowInAndroid #2 blog https://proandroiddev.com/now-in-android-with-koin-part-2-49158741cb92#1936-6cf6d648e2ac-reply is still suggesting to use koinVieeModel, and I'm pretty sure a lot of folks are going to be looking at this blog post to learn about koin. It .at be worth the effort to change that section and suggest the new API there. Especially since hilt would do this thing automatically for them before this migration, so it'd make sense to have the "equivalent" API from koin when suggesting this switch from hilt to koin
a

arnaud.giuliani

04/11/2023, 10:00 AM
you mean having a support to compare Koin/Hilt?
s

Stylianos Gakis

04/11/2023, 10:04 AM
I just mean that
koinNavViewModel
exists now, and as far as I understand it is what you are supposed to be using when trying to get your ViewModel inside a navigation destination. This blog was written a bit before that API existed and is still using
koinViewModel
instead. And I thought maybe it’d be a good idea to update that article with the new API instead. Unless I am somehow misunderstanding what
koinNavViewModel
is for.
m

Matt Rea

04/11/2023, 5:36 PM
the difference between koinViewModel and koinNavViewModel is the ability to handle the NavBackStackEntry
Does this mean if you use
koinNavViewModel
, Koin will clear the instance after the NavBackStackEntry is popped, like Hilt does?
133 Views