Hi, people! I'm trying to create a new app follow...
# android-architecture
a
Hi, people! I'm trying to create a new app following Clean Architecture to the best of my abilities. However, I am unable to pass lambdas to my
ViewModel
's constructor (as it is constructed using
hiltViewModel()
). I read a bit and found that NavArguments and SavedStateHandle should be used to pass arguments in ViewModel, ideally. Yet, that only seems to support very limited
NavArg.Type
's as well. I don't get what I am doing wrong. Are we not supposed to pass navigation lambdas to ViewModel? Because the state that needs to trigger navigation resides inside the ViewModel only. Please give your helpful inputs :) Thread in Slack Conversation
s
If I understand what do you want to achieve you can check this out - https://medium.com/google-developer-experts/modular-navigation-with-jetpack-compose-fda9f6b2bef7 Also you can take a look at this repository. My implementation is not exactly the same but the concept is pretty much the same. https://github.com/sgeorgiev24/tradi-android/tree/main/modules/presentation/src/main/java/com/github/sgeorgiev24/tradi/presentation/navigation This way you can inject the navigation dispatcher in the view model and use it to navigate to your destinations - you can see it in the view models.
a
Thanks a lot @Stanislav Georgiev I'll refer to your repo for future purposes. For the current project, I simply used LaunchEffect to trigger the navigation as soon as the state changes. Still thanks for the help 😃