olshevski / compose-navigation-reimagined

🌈 Type-safe navigation library for Jetpack Compose
https://olshevski.github.io/compose-navigation-reimagined/
MIT License
534 stars 18 forks source link

Cannot create View Model class using hiltViewModel() #7

Closed andraantariksa closed 2 years ago

andraantariksa commented 2 years ago

The title says it all. It only happen for ViewModel inside of the NavHost

This is the error

java.lang.UnsupportedOperationException: SavedStateViewModelFactory constructed with empty constructor supports only calls to create(modelClass: Class<T>, extras: CreationExtras).

Step to reproduce

olshevski commented 2 years ago

androidx.hilt:hilt-navigation-compose works only with the official Navigation Component for Compose.

My library is not related to Navigation Component in any way. As a temporary solution you may take hiltViewModel method sources from androidx.hilt:hilt-navigation-compose and replace NavBackStackEntry with NavComponentEntry.

You may find useful the discussion here: https://github.com/olshevski/compose-navigation-reimagined/discussions/4

olshevski commented 2 years ago

Also, I don't even see you using my library in the github repo you've linked to. What can I help you with then?

andraantariksa commented 2 years ago

Sorry, I can't follow your instruction correctly, so I just revert everything to compose navigation.