Fixed
Status Update
Comments
cl...@google.com <cl...@google.com> #2
Only the `argType="reference"` accepts resource IDs (and returns an int that you'd pass to getContext().getString()), so it is working as intended that a "string" type is exactly what you put into your XML. It was important that the build time code gen and the runtime behavior always matches and that was not possible in the general cases - see edge cases such as https://issuetracker.google.com/issues/111736515 for some background.
Please starhttps://issuetracker.google.com/issues/36994900 to track progress towards allowing placeholders in XML files, which would be the recommended way of filling in placeholders at compile time.
Please star
ap...@google.com <ap...@google.com> #3
Ok thanks, I understand now, I wasn't aware of argType="reference". Anyway I think it is a bit strange that behavior is different if we navigate using safe args gen code (navController.navigate(WebPageFragmentDirections.actionGlobalHomeFragment())) and code without safe args (navController.navigate(R.id.homeFragment)) if the navigation xml file is the same.
cl...@google.com <cl...@google.com> #4
Yes, I think we can make it more explicit that only reference types can have references to other resources.
ap...@google.com <ap...@google.com> #5
Project: platform/frameworks/support
Branch: androidx-master-dev
commit bb456e84a524d4e5cd241a6a839a1062297b9cf4
Author: Ian Lake <ilake@google.com>
Date: Thu Jan 31 15:46:55 2019
Enforce "reference" types for reference default values
In order to ensure that inflation of a navigation
graph results in the same arguments as Safe Args,
we now enforce usage of the "reference" type for any
argument that has a defaultValue that references
another resource (i.e., @string/app_name, etc).
This makes it much more obvious that the default value
in Safe Args is in the form of R.string.app_name and
any provided override for that should also be in the
form of R.string.some_value.
In these cases, it is expected that developers either
1) Use the ids directly (for example, passing an
R.string to a method that takes a resource id)
2) Specifically call context.getString() with the
resource id they retrieve from their NavArgs instance.
Test: updated NavInflaterTest
Change-Id: I06b8c9a0d1420821b8c0064c22f176788da43d7a
Fixes: 123551990
M navigation/runtime/src/androidTest/java/androidx/navigation/NavInflaterTest.kt
M navigation/runtime/src/androidTest/res/navigation/nav_default_arguments.xml
A navigation/runtime/src/androidTest/res/navigation/nav_invalid_argument_arg_type.xml
A navigation/runtime/src/androidTest/res/navigation/nav_invalid_argument_default_value.xml
M navigation/runtime/src/main/java/androidx/navigation/NavInflater.java
https://android-review.googlesource.com/891680
https://goto.google.com/android-sha1/bb456e84a524d4e5cd241a6a839a1062297b9cf4
Branch: androidx-master-dev
commit bb456e84a524d4e5cd241a6a839a1062297b9cf4
Author: Ian Lake <ilake@google.com>
Date: Thu Jan 31 15:46:55 2019
Enforce "reference" types for reference default values
In order to ensure that inflation of a navigation
graph results in the same arguments as Safe Args,
we now enforce usage of the "reference" type for any
argument that has a defaultValue that references
another resource (i.e., @string/app_name, etc).
This makes it much more obvious that the default value
in Safe Args is in the form of R.string.app_name and
any provided override for that should also be in the
form of R.string.some_value.
In these cases, it is expected that developers either
1) Use the ids directly (for example, passing an
R.string to a method that takes a resource id)
2) Specifically call context.getString() with the
resource id they retrieve from their NavArgs instance.
Test: updated NavInflaterTest
Change-Id: I06b8c9a0d1420821b8c0064c22f176788da43d7a
Fixes: 123551990
M navigation/runtime/src/androidTest/java/androidx/navigation/NavInflaterTest.kt
M navigation/runtime/src/androidTest/res/navigation/nav_default_arguments.xml
A navigation/runtime/src/androidTest/res/navigation/nav_invalid_argument_arg_type.xml
A navigation/runtime/src/androidTest/res/navigation/nav_invalid_argument_default_value.xml
M navigation/runtime/src/main/java/androidx/navigation/NavInflater.java
na...@google.com <na...@google.com> #6
Navigation now enforces use of the "reference" type if you have a defaultValue referencing another resource. This ensures that Safe Args and Navigation's runtime behavior are always in sync.
Please starhttps://issuetracker.google.com/issues/36994900 to track allowing build time placeholders in XML files.
Please star
tp...@gmail.com <tp...@gmail.com> #7
Ok, great, now it is much more straightforward. Thanks!
jb...@google.com <jb...@google.com> #8
This "fix" broke our app and our navigation XML, the file looked like the one described in the first message by OP and that's exactly how we wanted it to work.
Let me describe the use case.
Our Fragments load content based on the argument "url" (coming from backend) and the default value is required to load the initial content when the user starts the app.
Previously we had this default value stored in string resources where all the app strings can be easily accessed and reused across the app.
After this "fix" in beta01, we have to hardcode the default path in the navigation XML file and we have lost the ability to reference the same default path in the code (now the string is duplicated in string resources and in the navigation XML file).
Another undesired side-effect is that another argument used the default value of @string/null_ and now this doesn't work anymore forcing us to use an ugly empty string with a space character and in the Fragment check for blank string.
Could you enable resources references again just for default XML arguments for other argTypes?
Let me describe the use case.
Our Fragments load content based on the argument "url" (coming from backend) and the default value is required to load the initial content when the user starts the app.
Previously we had this default value stored in string resources where all the app strings can be easily accessed and reused across the app.
After this "fix" in beta01, we have to hardcode the default path in the navigation XML file and we have lost the ability to reference the same default path in the code (now the string is duplicated in string resources and in the navigation XML file).
Another undesired side-effect is that another argument used the default value of @string/null_ and now this doesn't work anymore forcing us to use an ugly empty string with a space character and in the Fragment check for blank string.
Could you enable resources references again just for default XML arguments for other argTypes?
Description