Fixed
Status Update
Comments
il...@google.com <il...@google.com>
il...@google.com <il...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit e1b42da3ee5bcb06756d8cb8377abf6116086e11
Author: Sanura N'Jaka <sanura@google.com>
Date: Tue Sep 07 20:23:52 2021
Make nullable NavDeepLink arguments not required
Removing the inclusion of nullable NavDeepLink
arguments from the "required" argument checking.
RelNote: "Nullable `NavDeepLink` arguments no longer
require a default value."
Test: deepLinkNullableArgumentNotRequired test
Bug: 198689811
Change-Id: Ia14ef04bfe5b25942163688f40adacc30fa7e044
M navigation/navigation-common/src/androidTest/java/androidx/navigation/AddInDefaultArgsTest.kt
M navigation/navigation-common/src/androidTest/java/androidx/navigation/NavDeepLinkTest.kt
M navigation/navigation-common/src/androidTest/java/androidx/navigation/test/NavArgument.kt
M navigation/navigation-common/src/main/java/androidx/navigation/NavDeepLink.kt
https://android-review.googlesource.com/1817360
Branch: androidx-main
commit e1b42da3ee5bcb06756d8cb8377abf6116086e11
Author: Sanura N'Jaka <sanura@google.com>
Date: Tue Sep 07 20:23:52 2021
Make nullable NavDeepLink arguments not required
Removing the inclusion of nullable NavDeepLink
arguments from the "required" argument checking.
RelNote: "Nullable `NavDeepLink` arguments no longer
require a default value."
Test: deepLinkNullableArgumentNotRequired test
Bug: 198689811
Change-Id: Ia14ef04bfe5b25942163688f40adacc30fa7e044
M navigation/navigation-common/src/androidTest/java/androidx/navigation/AddInDefaultArgsTest.kt
M navigation/navigation-common/src/androidTest/java/androidx/navigation/NavDeepLinkTest.kt
M navigation/navigation-common/src/androidTest/java/androidx/navigation/test/NavArgument.kt
M navigation/navigation-common/src/main/java/androidx/navigation/NavDeepLink.kt
ap...@google.com <ap...@google.com> #3
There's two issues here:
android:defaultValue="@null"
is actually treated as thedefaultValue
attribute not existing at all at runtime (we do still use it for Safe Args)- We enforced every argument without a default value to be present in the URI/route, even if it was nullable.
While we can't fix the first one, we have made the change in Navigation 2.4.0-alpha09
to only check for default values for non-nullable parameters. This should mean that
- Using
android:defaultValue="@null"
won't be a problem - Constructing a type in the Kotlin DSL via
navArgument("argument_name")
and making itnullable = true
without a default value won't be a problem.
mm...@commonsware.com <mm...@commonsware.com> #4
Unfortunately I still experience this bug with 2.4.0-alpha09 :(
java.lang.IllegalArgumentException: Deep link penny://app/offers can't be used to open destination Destination(de.penny.app.debug:id/offerListFragment) label=OfferListFragment class=de.penny.feature.offer.view.OfferListFragment.
Following required arguments are missing: [sectionIndexOrName, raffleId]
This is the excerpt from my navigation graph XML:
<argument
android:name="sectionIndexOrName"
android:defaultValue="@null"
app:argType="string"
app:nullable="true" />
<argument
android:name="raffleId"
android:defaultValue="@null"
app:argType="string"
app:nullable="true" />
<deepLink
android:id="@+id/offersDeeplink"
app:uri="penny://app/offers" />
As you can see both parameters are nullable and have a default value of null
.
Description
Version used: 2.0.0
Devices/Android versions reproduced on: n/a
Android Studio 3.3.2
Build #AI-182.5107.16.33.5314842, built on February 15, 2019
JRE: 1.8.0_152-release-1248-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.15.0-46-generic
com.android.tools.build:gradle:3.3.2
gradle-4.10.3-all
I have a destination with a nullable String argument:
<fragment
android:id="@+id/editFragment"
android:name="com.commonsware.todo.ui.edit.EditFragment"
android:label="@string/app_name" >
<argument
android:name="modelId"
app:argType="string"
app:nullable="true" />
</fragment>
I have an action that attempts to declare null as the default value:
<action
android:id="@+id/createModel"
app:destination="@id/editFragment" >
<argument
android:name="modelId"
android:defaultValue="@null" />
</action>
The generated SafeArgs code treats @null as a String:
private data class CreateModel(val modelId: String = "@null") : NavDirections {
override fun getActionId(): Int = R.id.createModel
override fun getArguments(): Bundle {
val result = Bundle()
result.putString("modelId", this.modelId)
return result
}
}
fun createModel(modelId: String = "@null"): NavDirections = CreateModel(modelId)
IOW, I am seeing similar symptoms to
If I remove the default value, the SafeArgs-generated code goes back to supporting null, just without a default null:
private data class CreateModel(val modelId: String?) : NavDirections {
override fun getActionId(): Int = R.id.createModel
override fun getArguments(): Bundle {
val result = Bundle()
result.putString("modelId", this.modelId)
return result
}
}
fun createModel(modelId: String?): NavDirections = CreateModel(modelId)
Let me know if you need additional information -- thanks!