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

Investigate the possibility to move arguments from NavAction to INavDestination #63

Open
AdamKobus opened this issue Feb 13, 2022 · 0 comments
Labels
enhancement New feature or request on hold

Comments

@AdamKobus
Copy link
Owner

AdamKobus commented Feb 13, 2022

Reasoning is that destinations need args to render properly, always. NavAction's role is to simply deliver them to the new destination.

Once arguments become part of destination, it will be possible to do something like this:

// could be serialized using Gson
data class DetailScreenArgs(
    @SerializedName("itemId")
    val itemId: Int
)

object MyGraph : NavGraph("myGraph") {

    val List = navDestination("list") { ListScreen() }

    val Detail = List.nextWithArgs<DetailScreenArgs> {
        param("itemId")
    } { args -> DetailScreen(args) }
}

This way destination would declare both, the type of the used args and how it renders in one place. This could potentially make it possible to automatically build a graph with NavGraphBuilder. NavGraph methods like navDestination could remember created destiantions. This will simplify the graphs definition by a lot

Also, args should be part of the information about back stack. Currently, there is no real way to tell apart 2 instances of the same destination, even if they are launched with different set of arguments.

Potential issues:

  1. How should the destination like the one below work:
    val ListDetail = List.nextWithArgs<DetailScreenArgs> {
        param("itemId")
    } { args -> DetailScreen(args) }
    
    val PicturePreview = Detail .nextWithArgs<PicturePreivewArgs> {
       path("picture")
       param("pictureId")
    } { args -> PicturePreviewScreen(args) }
    Args would need to carry both, "itemId" and "pictureId" fields. Should "pictureId" and "itemId" constants be defined in common module then?
@AdamKobus AdamKobus added the enhancement New feature or request label Feb 13, 2022
@AdamKobus AdamKobus added this to the 0.3.0 milestone Feb 13, 2022
@AdamKobus AdamKobus removed this from the 0.3.0 milestone Feb 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request on hold
Projects
None yet
Development

No branches or pull requests

1 participant