I’m using the Jetbrains Compose navigation library which also contains support for KMP view models.
If I create a view model:
import androidx.lifecycle.ViewModel
class MyViewModel : ViewModel() {
I can use that view model in my composable:
@Composable
fun MainScreen() {
val viewModel = viewModel<MyViewModel>()
This all appears to work.
However, as soon as I try and use that composable inside navigation :
NavHost(
navController = navController,
...
) {
composable(Screen.Start.name) {
MainScreen()
}
}
I get this:
``Factory.create(String, CreationExtras)` is not implemented. You may need to override the method and provide a custom implementation. Note that using
Factory.create(String)
is not supported and considered an error.`
I created the app using the KMP wizard (desktop only), added the
org.jetbrains.androidx.navigation:navigation-compose
library (I’ve tried both 2.7.0-alpha07 and 2.8.0-alpha02) and modified it as little as possible to set up navigation