compose-safe-routing
compose-safe-routing copied to clipboard
Support enum arg type
Add support for enum type arguments for a much better type safety
Hi @OliverRhyme :) The only way I can see this work is by converting Enum to the Int and back. I will try to see if I can make it work and get back to you, but In the meantime, you can you do that manually Thanks for reaching out :)
Hi @OliverRhyme :) The only way I can see this work is by converting Enum to the Int and back. I will try to see if I can make it work and get back to you, but In the meantime, you can you do that manually Thanks for reaching out :)
But I think the default implementation uses the name of the enum. I've tried that passing in arg string and the SavedStateHandle (so bundles should also work) can automatically it.
@OliverRhyme What do you mean by default implementation? By default, the navigation component only supports a few types when it comes to compose, see this doc for the reference.
Everything else either needs some workarounds or you would have to pass this data yourself, unfortunately.
Here is what I meant by using Int as a workaround:
- Specify the argument type as
Int - When navigating use something like that:
RoutesActions.toSomeScreen(enum = YourEnum.SomeValue.ordinal) - Then to get it:
val enum = YourEnum.values()[args.enum]