compose-safe-routing icon indicating copy to clipboard operation
compose-safe-routing copied to clipboard

Support enum arg type

Open OliverRhyme opened this issue 4 years ago • 3 comments

Add support for enum type arguments for a much better type safety

OliverRhyme avatar Oct 21 '21 14:10 OliverRhyme

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 :)

levinzonr avatar Oct 22 '21 07:10 levinzonr

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 avatar Oct 22 '21 12:10 OliverRhyme

@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]

levinzonr avatar Oct 24 '21 15:10 levinzonr