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 not used from separate module #173

Open
kassim opened this issue Jun 29, 2022 · 6 comments
Open

NavTypeSerializer not used from separate module #173

kassim opened this issue Jun 29, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@kassim
Copy link

kassim commented Jun 29, 2022

I've created a serializer
@NavTypeSerializer class BitmapTypeSerializer : DestinationsNavTypeSerializer<Bitmap>
(I know its probably inefficient to serialise a bitmap between screens but that's a different point)

I also have my composable destination

@Composable
@Destination
fun ReviewScreen(destinationsNavigator: DestinationsNavigator, bitmap: Bitmap?) {

when I put BitmapTypeSerializer next to ReviewScreen in the same package the serialization works fine, but when I move the Serializer to a navigation module that my feature module depends on, the codegen decides to use DefaultParcelableNavTypeSerializer instead of BitmapTypeSerializer

@kassim kassim changed the title @NavTypeSerializer not used from separate module NavTypeSerializer not used from separate module Jun 29, 2022
@raamcosta
Copy link
Owner

Hey 👋

Yeah at the moment this is expected. Ksp tasks are completely isolated inside each module. So it only knows about classes of that module.

But btw passing bitmap really is not something you want to do, the Android Binder only has 500 kb of space, so you can easily get exception if you’re using it for something like a bitmap.

Anyway I’ll keep this open so I can investigate if there is a way to know about classes of other modules on ksp task.

@raamcosta
Copy link
Owner

I was developing a feature for this, but I realized it's stupid to have a specific API just for this.
Because ideally, we register a nav type serializer globally for that type in that module and for that, there is nothing simpler then what is already possible.

@NavTypeSerializer
object ClassFromOtherModuleSerializer : DestinationsNavTypeSerializer<ClassFromOtherModule> by NavTypeSerializerDeclaredOnTheOtherModule

@raamcosta
Copy link
Owner

@kassim @Nek-12 What do you guys think? Am I missing something?

@Nek-12
Copy link

Nek-12 commented Nov 7, 2022

Yeah I think what I consider to be a "workaround" looks good from the code standpoint, but still, this does not solve the problem of some people wanting to use different serializers for different composables or even parameters. I believe such a use case is going to appear at some point. Kotlinx.serialization doesn't have anything like the module serializer, but it does have a file-wide, class level and parameter-level annotations, which is I think the most flexibility there possibly could be.

Taking into consideration the fact that you want to deprecate multimodule setup in #216, which solves the visibility problem of this issue, you may want to decide to be opinionated and not change anything.

In the end it depends on what we do about that issue I think

@pawelsmagala
Copy link

pawelsmagala commented May 29, 2023

@raamcosta bump on this - would be nice to be able to define global serializer for specific type that is reused in every module

@kassim
Copy link
Author

kassim commented Jun 13, 2023

Sorry. Missed this. I think the workaround is okay, I assume many devs may want global defined serialisers but perhaps that's an argument of preference.

An issue of this is a user probably wouldn't know this workaround needs to be used. A warning/error can't be produced unless something does scan to check and then tell the user "oh, by the way this may not serialize as you expect" and if you've written that then I guess it's not many steps away from that process actually just facilitating the usage of that serializer cross-module.

An alternative might be DefaultParcelableNavTypeSerializer and other default serializers are always used, unless there's a specific annotation on the argument that defines a custom serializer to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants