had to put a pin in compose ios for a bit. but com...
# compose-ios
c
had to put a pin in compose ios for a bit. but coming back to this and i saw this https://github.com/JetBrains/compose-multiplatform-core/commit/8a01245d70018ea08cfc88c55e2b2df452b705e2 so does this mean we can use VM in common code? any gotchas?
i
Not particularly to this commit, but yes - Lifecycle, ViewModel and Navigation are available from common in a few last dev builds
c
Navigation? You ported androidx navigation to common?
👌 2
c
Niceee
But it’s under the androidx namespace, and it’s a separate dependency not included in the plugin by default. Does that mean its in beta or there’s a plan for a JB navigation library?
i
Does that mean its in beta
It's not even in beta for now. Yes, it's separate dependency
there’s a plan for a JB navigation library?
There is no plan to invent one more library. We're porting jetpack navigation-compose + there are a couple of libraries from community
🎉 1
c
The nav_cupcake sample is interesting. The way it uses viewModel is not what I expected. looks like its sharing one VM between all destination instead of having a VM per destination. am I missing something?
i
As mentioned in readme it's just a port of Google's codelab. I didn't want to change the approach there, the intention was to show that it might be multiplatform (almost) as-is
c
gotcha. i gotta take a look at their original codelab lol
do you know if theres any other sample using androix.viewmodel on iOS?
i
I ported only this one for now. Do you have some particular questions?
c
Nope! I've just been using precompose https://github.com/Tlaster/PreCompose which is essentially androix.viewmodel and androidx.navigation but KMP. so i was wondering if there are any gotchas/footguns. if not, then I might spend my day trying to port something over.
i
• Deep-links and
(Predictive)BackHandler
are not ported yet • K/N doesn't have reflection so requires explicit
ViewModel
factory. Easy to solve via a small wrapper • Compose Multiplatform doesn't provide default
ViewModelStoreOwner
yet - we cannot do it for upcoming 1.6.10 to avoid introducing dependency to unstable version. Expected to be fixed in 1.7.0.
NavHost
provides it, but for using VMs outside of navigation you need to provide custom one
❤️ 3
c
thank you. incredibly helpful!