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

Parcelable with generic type not generated into a nav argument #530

Open
marosseleng opened this issue Oct 29, 2023 · 1 comment
Open

Parcelable with generic type not generated into a nav argument #530

marosseleng opened this issue Oct 29, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@marosseleng
Copy link

Hello! I came across what I believe is a bug:

I have a generic data class for modeling basic screen states ((re)loading, loaded, error, etc.) that looks as follows:

@Parcelize
internal data class OperationStatus<ResultT : Parcelable>(
    val isLoading: Boolean = false,
    val result: ResultT? = null,
    val error: Exception? = null,
) : Parcelable

then I have my destination:

@Destination
@Composable
internal fun ExampleScreen(
    navigator: DestinationsNavigator,
    status: OperationStatus<SomeParcelableClass>,
)

The problem is that the generated ExampleScreenDestination does not have an invoke override, with status: OperationStatus<SomeParcelableClass> as a parameter.

Is this a bug or is there any limitation, why this isn't possible? According to docs, Parcelable can be used as navigation argument, but maybe I am missing something.

I am aware of possible solution introduced in #29 (to box my type in another class), but I find that a bit cumbersome.

Also, regarding separate boxed argument class, I found another bug: Let's say I create a class

@Parcelize
internal data class MyBoxedStatusArg(val status: OperationStatus<SomeParcelableClass>)

and add it as an argument to my Destination:

@Destination
@Composable
internal fun ExampleScreen(
    navigator: DestinationsNavigator,
    status: MyBoxedStatusArg,
)

I then get a compilation error that the created public subclass exposes its internal supertype (I believe it is because of its definition):

public class MyBoxedStatusArgNavType(
    private val stringSerializer: DestinationsNavTypeSerializer<Parcelable>
) : DestinationsNavType<MyBoxedStatusArg?>()

Would it be possible to make the generated ArgNavType to respect the "argument's" visibility?

Thank you for reply!

@raamcosta
Copy link
Owner

raamcosta commented Mar 12, 2024

Hi! 👋
So sorry it took me so long to check this 🙏

Would it be possible to make the generated ArgNavType to respect the "argument's" visibility?

I believe this has been fixed recently.

Parcelable with type arguments are not currently supported, no. The only type arguments we support are the ones inside Array and ArrayList.
I'll mark this as possible future enhancement. Thank you!

@raamcosta raamcosta added the enhancement New feature or request label Mar 12, 2024
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

2 participants