I'm trying to encapsulate a flow (business flow) i...
# compose
t
I'm trying to encapsulate a flow (business flow) in a navigation subgraph, and I'm facing some challenges. There can be minor variations of the flow. For example, in one case there has to be an api call before exit, and in another case I should pop the entire subgraph and open a bottom sheet on top of whatever is on top of my back stack. Is there any standard pattern to create navigation graphs in compose that allows for such extensibility? Is it even a good idea to be able to create multiple copies of the same subgraph, each with some minor variations?
a
Is there any standard pattern to create navigation graphs in compose that allows for such extensibility?
I think, the easiest way would be to use optional arguments (or any other type of flag, like a settings-boolean or similar) to specify non-default behavior for any specific NavDestination where you have to do the following navigation differently. This describes how to do optional arguments for `NavDestination`s https://developer.android.com/guide/navigation/design#compose-arguments
Regarding this:
Is it even a good idea to be able to create multiple copies of the same subgraph, each with some minor variations?
I don't think it would be necessary to copy and modify a whole sub-graph (if that is even possible due to immutability). It would also put quite some maintenance-burden on the developer, if you simply do the variants by duplicating the code itself, so I would try to avoid it. Disclaimer: I only have experience with the XML-graph and Fragment-navigation for now, but the basic concepts are the same.