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

NavTypeSerializer #622

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

NavTypeSerializer #622

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

Comments

@bahromzodabehruz27
Copy link

Hi @raamcosta we a using destination in out project. I want navigate from module a to module b with arguments as argument I want to use data class. I have created my own NavTypeSerializer like documentation but method toRouteString doesn't call. Here a simple example.
This is my screen in module b

@destination()
@composable
fun TestScreen(things: Things) {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center){
Text(text = things.first, style = MaterialTheme.typography.headlineMedium)
}
}

// this is exmaple how I am navigating from module a to module b

onNotificationClick
{
val data = Things("Detail","items")
navigator.navigate("test_screen/$data")
},

Here is custom type serializer


@NavTypeSerializer
class ThingsNavTypeSerializer : DestinationsNavTypeSerializer<Things> {

    override fun toRouteString(value: Things): String {
        return "${value.first};${value.second}"
    }

    override fun fromRouteString(routeStr: String): Things {
        val things = routeStr.split(";")
        Log.d("TESTING",things.toString())
        //[Things(first=Detail, second=items)]
        return Things(first = things[0])
    }
}

**But method toRouteString() doesn't call and on method fromRouteString we are need to list of string but it retuns list of things in string format look like this //[Things(first=Detail, second=items)] can you check what is wrong or what I did wrong thanks you

@raamcosta
Copy link
Owner

Same as your other issue.
Navigate with Destination type safe methods:

navigator.navigate(TestScreenDestination(data))

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

Now I am navigating from module a to module b and I module a haven't access to TestScreenDestination

@raamcosta
Copy link
Owner

Why not? 🤔

Check my other answer, make sure you read through the documentation. It will tell you how to expose destinations from other modules, import them in your DestiantionsNavHost module. Then you'll be able to navigate to them.

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