I’m using the Jetbrains Compose navigation library...
# compose-desktop
k
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
👀 2
i
Thanks for the report. As workaround, please use this syntax to avoid relying on JVM reflection (required for iOS/web anyway):
Copy code
val viewModel = viewModel { MyViewModel() }
k
Thanks, that works for me
👍 1
a
Also, you can use triple-backticks to add a code-block in Slack:
Copy code
code goes here
k
Thanks. I did try that earlier and for some reason it didn’t work - I must’ve done something stupid 🤷
112 Views