Status Update
Comments
ag...@wayfair.com <ag...@wayfair.com> #2
Respectfully in regards to marking this duplicate. It is not quite a duplicate. That referenced ticket is part of SafeArgs, while this request is for typesafe navigation. It was marked as "infeasible", yet w'ere talking about two completely different bases.
In the last
This requires support for doubles in NavInflater whose values are all backed by the TypedValue class, which unfortunately does not support Double values so we cannot go forward with this.
When in fact this is trivial to implement in compose typesafe navigation and seems to be a major omission:
object DoubleNavType : NavType<Double>(isNullableAllowed = false) {
@Suppress("DEPRECATION")
override fun get(bundle: Bundle, key: String): Double = bundle[key] as Double
override fun parseValue(value: String): Double {
// At runtime the d suffix is optional, contrary to the Safe Args plugin.
// This is in order to be able to parse double numbers passed as deep link URL
// parameters
var localValue = value
if (value.endsWith("d")) {
localValue = localValue.substring(0, value.length - 1)
}
return localValue.toDouble()
}
override fun put(bundle: Bundle, key: String, value: Double) {
bundle.putDouble(key, value)
}
}
/**
* Convience class to allow for double navigation types by turning them into strings and back.
*/
object NullableDoubleNavType : NavType<Double?>(isNullableAllowed = true) {
@Suppress("DEPRECATION")
override fun get(bundle: Bundle, key: String): Double? = bundle[key] as? Double?
override fun parseValue(value: String): Double? {
if (value == "null") return null
return DoubleNavType.parseValue(value)
}
override fun put(bundle: Bundle, key: String, value: Double?) {
if (value == null) {
bundle.putSerializable(key, null)
} else {
DoubleNavType.put(bundle, key, value)
}
}
}
// in a route
typeOf<Double>() to DoubleNavType,
typeOf<Double?>() to NullableDoubleNavType,
il...@google.com <il...@google.com> #3
Similar to the work done in @Serializable
can support, I think we can do something similar here to support doubles.
cl...@google.com <cl...@google.com>
sa...@gmail.com <sa...@gmail.com> #4
ap...@google.com <ap...@google.com> #5
Branch: androidx-main
commit b9a16ee818ee85ae088bcf8787014eb801b10204
Author: Clara Fok <clarafok@google.com>
Date: Fri Aug 30 15:32:12 2024
Add built-in safe args support for non-nullable Double
Test: ./gradlew navigation:navigation-common:cC
Test: ./gradlew navigation:navigation-common:test
Test: ./gradlew navigation:navigation-runtime:cC
Bug: 359245753
Relnote: "Navigation in safe args now has built-in support for non-nullable Double type."
Change-Id: I570ebef5242e1bc3e8ee3f5d58b4aa2d677abaee
M navigation/navigation-common/src/androidTest/java/androidx/navigation/serialization/RouteDecoderTest.kt
M navigation/navigation-common/src/androidTest/java/androidx/navigation/serialization/RouteFilledTest.kt
M navigation/navigation-common/src/main/java/androidx/navigation/serialization/NavTypeConverter.kt
M navigation/navigation-common/src/test/java/androidx/navigation/serialization/NavArgumentGeneratorTest.kt
M navigation/navigation-common/src/test/java/androidx/navigation/serialization/NavTypeConverterTest.kt
M navigation/navigation-runtime/src/androidTest/java/androidx/navigation/NavControllerRouteTest.kt
ap...@google.com <ap...@google.com> #6
Branch: androidx-main
commit b1c0e53c08a0c80fd8134e2206d70feaf49a6de6
Author: Clara Fok <clarafok@google.com>
Date: Fri Aug 30 15:45:18 2024
Add built-in safe args support for nullable Double
Test: ./gradlew navigation:navigation-common:cC
Test: ./gradlew navigation:navigation-common:test
Test: ./gradlew navigation:navigation-runtime:cC
Bug: 359245753
Relnote: "Navigation in safe args now has built-in support for nullable Double type."
Change-Id: Ibc4c02fa77e416c1c007209fb358a0d1c34389db
M navigation/navigation-common/src/androidTest/java/androidx/navigation/serialization/RouteDecoderTest.kt
M navigation/navigation-common/src/androidTest/java/androidx/navigation/serialization/RouteFilledTest.kt
M navigation/navigation-common/src/main/java/androidx/navigation/serialization/NavTypeConverter.kt
M navigation/navigation-common/src/test/java/androidx/navigation/serialization/NavArgumentGeneratorTest.kt
M navigation/navigation-common/src/test/java/androidx/navigation/serialization/NavTypeConverterTest.kt
M navigation/navigation-runtime/src/androidTest/java/androidx/navigation/NavControllerRouteTest.kt
ap...@google.com <ap...@google.com> #8
Branch: androidx-main
commit 2bbd62e9ba772d50bf4da98ada024a798257af28
Author: Clara Fok <clarafok@google.com>
Date: Thu Sep 19 04:47:53 2024
Add built-in safe args support for List<Double>
Test: ./gradlew navigation:navigation-common:cC
Test: ./gradlew navigation:navigation-common:test
Test: ./gradlew navigation:navigation-runtime:cC
Bug: 359245753
Relnote: "Navigation with safe args now has built-in support for nullable List<Double>"
Change-Id: I5bed4745773efa2e8a57fcdacc77cc16b1845067
M navigation/navigation-common/src/androidTest/java/androidx/navigation/serialization/RouteDecoderTest.kt
M navigation/navigation-common/src/androidTest/java/androidx/navigation/serialization/RouteFilledTest.kt
M navigation/navigation-common/src/main/java/androidx/navigation/serialization/NavTypeConverter.kt
M navigation/navigation-common/src/test/java/androidx/navigation/serialization/NavArgumentGeneratorTest.kt
M navigation/navigation-common/src/test/java/androidx/navigation/serialization/NavTypeConverterTest.kt
M navigation/navigation-runtime/src/androidTest/java/androidx/navigation/NavControllerRouteTest.kt
cl...@google.com <cl...@google.com> #9
Fixed internally and will be available in navigation 2.8.2
.
pr...@google.com <pr...@google.com> #10
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.annotation:annotation-wasm-js:1.9.0-rc01
androidx.annotation:annotation-watchosdevicearm64:1.9.0-rc01
androidx.navigation:navigation-common:2.8.2
androidx.navigation:navigation-runtime:2.8.2
na...@google.com <na...@google.com> #11
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.navigation:navigation-common:2.9.0-alpha01
Description
Component used: Navigation Compose Version used: 2.8.0-beta04+ Devices/Android versions reproduced on: Any
Using any valid
@Serializable
route class with aDouble
orDouble?
field results in:This seems like a large feature gap in supporting kotlinx serialization functionality.