Hi all, with the new safe args in compose navigati...
# compose-android
a
Hi all, with the new safe args in compose navigation 2.8.0, I could not find a way to access the reified T in the activity destination builder(kotlin DSL ), anyone know how?:
Copy code
activity<Foo> {
  val foo:Foo = ?
  action = <http://foo.xxx|foo.xxx>
  data = <http://foo.xxx|foo.xxx>
}
i
There is no instance of Foo when you are building the graph, so there is no instance to refer to at all here. The way to extract information out of the class is via the
dataPattern
, which uses the
{field}
syntax to fill in part of the data with an argument from your class: https://developer.android.com/guide/navigation/design/activity-destinations#dynamic-arguments
a
Thanks Ian for the reply! If I understand, this app:dataPattern will work for Activities declared in my manifest, in general, how would I go about creating an activity<Foo> { } destination where the resolved Activity would be in another app?
i
What makes you think the data pattern has any restrictions on what app is started?
There's no such restriction at all - in fact, that same page actually specifically calls out that you need to set the
targetPackage
if you want to restrict it to only your own package
a
Ah, I got confused, thought this was a AndroidManifest xml block …
i
They're linking to the right page for me, weird
Ah, interesting, I do see an issue in an incognito window
hopefully you figured out that you can just go to the ActivityNavigator.Destination page directly: https://developer.android.com/reference/androidx/navigation/ActivityNavigator.Destination
a
Ian are there any example snippets on how to use
public inline fun <reified T : Any> NavGraphBuilder.activity
anywhere, I still am confused about how to do
Copy code
activity<Foo> {
    action = Intent.ACTION_VIEW
    data = something in Foo
}
i
dataPattern = "<http://www.example.com/{name}|www.example.com/{name}>"
where Foo has a field called
name
a
OK Thanks Ian, I wound up with
Copy code
fun NavGraphBuilder.viewLinkRoute() {
    activity<ViewLinkRoute> {
        action = Intent.ACTION_VIEW
        dataPattern = "{uri}"
    }
}

@Serializable
data class ViewLinkRoute(
    val uri: String
)
But get runtime exception
No Activity found to handle Intent
… just trying to do:
Copy code
context.startActivity(
    Intent(Intent.ACTION_VIEW, uri)
)
but I’m getting closer. Thanks for your help so far.
i
If you're really just trying to handle a generic Uri, I don't know why you are trying to use an activity destination at all. Generally you'd just use Compose's `LocalUriHandler`: https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/package-summary?hl=en#LocalUriHandler() and call
openUri
on it
a
had no idea that existed, thanks!