Reading the docs for the new compose 3.4.3 release...
# koin
s
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
yes good point, the difference between koinViewModel and koinNavViewModel is the ability to handle the NavBackStackEntry
image.png
s
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
you mean having a support to compare Koin/Hilt?
s
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
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?
158 Views