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

[Navigation doc] differenciate route vs route pattern #508

Open
wants to merge 3 commits into
base: androidx-main
Choose a base branch
from

Conversation

martinbonnin
Copy link

@martinbonnin martinbonnin commented Mar 20, 2023

This is a docs-only change

This PR tries to highlight the difference between :

  • "route": a static String linked to a single destination like "topic/{topicId}"
  • "route instance": a instance of a route that has arguments filled in like "topic/42"

Since changing argument names would be a breaking change, this PR tweaks the KDoc.

Test: N/A docs change

@jbw0033 jbw0033 requested review from claraf3 and jbw0033 March 22, 2023 17:32
* @param route The topmost destination to retain. May contain filled in arguments as long as
* it is exact match with route used to navigate.
* @param route The route of the topmost destination to retain. Both route patterns
* and route instances with filled in arguments are supported.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of "route pattern" and "route" here should be distinctive enough. Can you also clarify that if using route, it must match the original route that was used to navigate?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree on "route pattern" and "route" 👍

I removed the May contain filled in arguments as long as it is exact match with route used to navigate. because I felt like this was the general expectation of the method and didn't add much information. Whether using a route pattern or a route, the expectation is that it returns true if found or false if not. Or did I get this wrong?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returns true if found or false if not is indeed the case. In the past we matched based on route pattern and didn't differentiate between "route/myArg1" and "route/myArg2". Now that matching takes into account filled in arguments, matching behavior has changed and what was previously expected to match may no longer match. Therefore the clarification could be important. Also, it doesn't hurt to have more docs than less :).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of disagree. KDoc is a place for reference information and changes belong in the changelog. Also more docs can hurts. In my personal case, this sentence got me puzzled about whether this would throw if passed the wrong route or how come there was an extra sentence in addition to the return value.

I don't want to die on this above hill though! If you think it is important to keep the sentence, please confirm and I'l re-add it (or feel free to edit directly before merging too!)

@@ -581,7 +581,8 @@ public open class NavController(
* Attempts to pop the controller's back stack back to a specific destination. This does
* **not** handle calling [dispatchOnDestinationChanged]
*
* @param route The topmost destination with this route to retain
* @param route The route of the topmost destination to retain. Both route patterns
* and route instances with filled in arguments are supported.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, lets stick to "route pattern" and "route".

Copy link
Member

@claraf3 claraf3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Commented.

* `saveState` value of `true`. May contain filled in arguments as long as
* it is exact match with route used with [popBackStack].
* `saveState` value of `true`. Both route patterns and route instances with filled in
* arguments are supported.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as with popBackStack and likewise for getBackStackEntry.

@@ -2143,7 +2144,7 @@ public open class NavController(
* Navigate to a route in the current NavGraph. If an invalid route is given, an
* [IllegalArgumentException] will be thrown.
*
* @param route route for the destination
* @param route route instance with filled arguments for the desired destination
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It accepts both route with filled arguments or the route patterns.
Given a destination with route "route/{arg}" you can navigate with either "route/{arg}" or "route/myArg".

Suggest: "route with filled arguments or the route pattern for the destination".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice, TIL! I tweaked your suggestion a bit to put "route pattern or route" (always put route pattern first for consistency)

@@ -2157,7 +2158,7 @@ public open class NavController(
* Navigate to a route in the current NavGraph. If an invalid route is given, an
* [IllegalArgumentException] will be thrown.
*
* @param route route for the destination
* @param route route instance with filled arguments for the desired destination
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as line#2147

@dlam
Copy link
Member

dlam commented Mar 23, 2023

You can safely ignore the lint failure here - it's on our end.

@martinbonnin
Copy link
Author

Changes pushed. I'm not 100% sure about filled in arguments vs just filled arguments. I put filled arguments for consistency but maybe filled in is more idiomatic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants