https://kotlinlang.org logo
#compose
Title
# compose
s

Sam

10/06/2020, 11:39 PM
Does Jetpack Compose have anything similar to the NavigationView in SwiftUI? Specifically: traversing deeper into a stack of screens with back button, swipe back to navigate, and of course the slide animation, etc. I know there is
ModalDrawerLayout
but that is more for a side menu..
i

Ian Lake

10/06/2020, 11:49 PM
Integration between Compose and the Navigation Component is under way, feel free to follow along on the issue: https://issuetracker.google.com/issues/161472731
That would include navigating down a stack of screen, integration with Android's back button, and animating between screens
s

Sam

10/06/2020, 11:53 PM
Are there examples of how this component will be used? Like will we be expected to create multiple activities or fragments? Will we have to create any xml for the nav graph?
z

Zach Klippenstein (he/him) [MOD]

10/07/2020, 12:16 AM
From the last CLs I saw, I think you define destinations as composable functions, you don’t use activities/fragments. IDK if you need XML to define the nav graph itself though.
i

Ian Lake

10/07/2020, 1:48 AM
There are samples attached to that issue if you want to take a look
Navigation already has a Kotlin DSL as an alternative for the XML graph. We use that DSL as the base for the Compose integration, which allows you to define your navigation graph right inline alongside your other Composable code
s

Sam

10/07/2020, 1:51 AM
@Ian Lake I’m looking here, is there a better place?
i

Ian Lake

10/07/2020, 1:52 AM
Yep, that is what is checked in right now
Still working through the API surface. More official docs and integration with the Compose samples will happen when we release an alpha release
s

Sam

10/07/2020, 2:29 AM
Thanks @Ian Lake, I can’t wait for the next alpha, it’s a struggle to build a production level app without proper navigation, since it’s so foundational
🙃 1
☝🏻 2
a

allan.conda

10/07/2020, 6:07 AM
Navigation already has a Kotlin DSL as an alternative for the XML graph. We use that DSL as the base for the Compose integration, which allows you to define your navigation graph right inline alongside your other Composable code
🙀 Kotlin DSL does not support SafeArgs right? Will it be for the Compose Navigation?
Oh wait, I just saw the NavArgs link, so I guess that’s the same
k

kioba

10/07/2020, 7:22 AM
Are there plans to extend NavArgs supported argument types in Compose? Currently we are only limited to primitive types and parcellable + etc, but are there plans to support composable between navigations?
i

Ian Lake

10/07/2020, 2:16 PM
Safe Args is a compile time code gen to based on parsing XML. There's no separate code gen for the Kotlin DSL, but we're still looking at what might be possible or what best practices will be
👍 1
Arguments must still be able to be put in a Bundle so that they can be saved and restored correctly across config changes and process death and recreation, no change there
👍 1
j

Javier

10/21/2020, 1:43 PM
and I would like to add a question too, will SafeArgs be available for Compose?
i

Ian Lake

10/21/2020, 3:26 PM
We're talking with the Tools team about both the Navigation Editor and Safe Args longer term, but right now both of them are strictly tied to XML graphs and therefore unavailable when using the Compose Kotlin DSL (the same as if you were using the Kotlin DSL in the existing Navigation world: https://developer.android.com/guide/navigation/navigation-kotlin-dsl).
We're also looking into what an XML graph would be like in a Compose world (which would enable at least basic editing in the Navigation Editor and Safe Args support), but the Kotlin DSL will generally always be the easiest way to build your graph in Compose
👍 4
a

allan.conda

10/21/2020, 4:02 PM
Thanks!