Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigate to another module with args #621

Closed
bahromzodabehruz27 opened this issue May 1, 2024 · 3 comments
Closed

Navigate to another module with args #621

bahromzodabehruz27 opened this issue May 1, 2024 · 3 comments
Labels
feedback needed Extra attention is needed

Comments

@bahromzodabehruz27
Copy link

Hi @raamcosta I am using destination library in our multi module project. Now I want to screen from main module to details module with args. As arguments I want to use data class.
Example
My data class looks like this

@Parcelize
data class Things(val first: String = "", val second: String = ""):Parcelable

@Destination(
    route = "testScreen/{things}"
)
@Composable
fun TestScreen(things: Things,viewModel: TestViewModel = hiltViewModel()){


}

And from main module using navigator I did navigate by route like this

  val data = Things("Behruz","items")
  navigator.navigate("testScreen/things/${data}")

But I got java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 exceptions

What here I am doing wrong ?

@raamcosta
Copy link
Owner

You shouldn't navigate with strings. Compose Destinations is here to help you NOT do that.

Change it to:

@Destination
@Composable
fun TestScreen(things: Things,viewModel: TestViewModel = hiltViewModel()){


}

And navigate:

val data = Things("Behruz","items")
navigator.navigate(TestScreenDestination(data))

@raamcosta raamcosta added the feedback needed Extra attention is needed label May 5, 2024
@bahromzodabehruz27
Copy link
Author

Can you give me a example of multi module navigation ? thanks

@raamcosta
Copy link
Owner

It's just like single module navigation. Or do you mean how to set it up?
For that, check here:

https://composedestinations.rafaelcosta.xyz/v2/multi-module-setup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback needed Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants