Closed AdzeB closed 1 year ago
Hi 👋
I'm not sure I understand your issue. Are you trying to pass email as a navigation argument from one screen to another? If yes, check this: https://composedestinations.rafaelcosta.xyz/destination-arguments/navigation-arguments
If you want to share the VM between multiple screens, check this: https://composedestinations.rafaelcosta.xyz/common-use-cases/providing-viewmodels#share-viewmodels-between-multiple-destinations
I tried the share view models methods, but I get errors implementing that.
I get the following Too many arguments for public inline fun <reified D : Any, T> DependenciesContainerBuilder<T>.dependency(dependency: D): Unit defined in com.ramcosta.composedestinations.navigation
With regards to the share it to all the screens using activity, I am currently implementing my destinationNavHost in the main activity under a MopdalBottomSheetLayout, so I don't know how I will have access to the facility(I am new to jetpack compose)
@raamcosta
That seems like you’re calling the method wrong 😅
Can you paste the code here where you’re calling dependency method?
this is how it looks now
setContent {
CompositionLocalProvider(UserState provides userState) {
AppLoadTheme {
val navController = rememberAnimatedNavController()
val bottomSheetNavigator = rememberBottomSheetNavigator()
navController.navigatorProvider.addNavigator(bottomSheetNavigator)
ModalBottomSheetLayout(bottomSheetNavigator = bottomSheetNavigator ) {
DestinationsNavHost(
navGraph = NavGraphs.root,
navController = navController,
engine = rememberNavHostEngine(),
dependenciesContainerBuilder = {
dependency(hiltViewModel<OTPViewModel>())
}
)
}
}
}
}
I tried this as well.
dependency(NavGraphs.root){
val parentEntry = remember(navBackStackEntry){
navController.getBackStackEntry(NavGraphs.root.route)
}
hiltViewModel
I have a user sign-up screen, the current flow is to get the user to enter his/her email address, then goes to the OTP screen once the user verifies then to the complete signup screen where the email is read-only.|
The problem I have is by the time the user gets to the OTP screen, the user email is null, the activity has been seemly recreated
DestinationsNavHost(
navGraph = NavGraphs.root,
// ....
dependenciesContainerBuilder = {
dependency(NavGraphs.root) {
val parentEntry = remember(navBackStackEntry) {
navController.getBackStackEntry(NavGraphs.root.route)
}
hiltViewModel<OTPViewModel>(parentEntry)
}
}
)
The above should work, if it doesn't, show me the error.
I get this
What version of the library are you using?
implementation 'io.github.raamcosta.compose-destinations:animations-core:1.5.1-beta'
ksp 'io.github.raamcosta.compose-destinations:ksp:1.5.1-beta'
I see. update it to 1.5.27-beta please. Documentation is matching latest version only 🙂
Okay let me try it
It worked no errors
Thank you very much, I managed to get the value to different screens.
Hello!
I have an issue. I want to pass the value, let's say, email in the VM from one screen to another, but when I get to the other screen, there's no value. Is there a way to share the same instance of the VM?
I appreciate any help you can provide.