Fixed
Status Update
Comments
il...@google.com <il...@google.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,
Description
When executing deep-links from another app to a Destination which has parent Destinations, the initial Activity may be put on the calling app's task stack. This allows a back-press to return to the calling app, and an 'up' press open the parent of the Destination in a new task.
In navigateUp(), when flow reaches the following line:
The newly-created task stack does not include any of the arguments that the initial Fragment destination were given. Fragment args will be empty, and the Activity will not include the original deep-link URL.
The original URI and arguments should be passed to the newly-created Activity and Destination Fragment.