Is there a good example project for navigation-com...
# compose
r
Is there a good example project for navigation-compose? Migrating my compose app over to alpha01 and just want to see how the entry point is done.
i
You might take a look at these projects: https://twitter.com/joreilly/status/1321518153264959489?s=19
r
Ok it looks fairly straightforward. Incredible job on the API btw @Ian Lake SwiftUI doesn’t have anything comparable and this is just about the perfect routing solution for a declarative framework. Really happy so far! 🙂
🎉 1
i
There's more docs and example use cases in the official docs as well: https://developer.android.com/jetpack/compose/navigation
r
Yes, they’re very well written, thanks! The only thing I’ve yet to find an example of now is targeting a compose view with
NavOptions
. I’m specifically trying to animate a composable into view. I looked through some internals and tried hacking together something like this but it’s not animating the view
Copy code
navController.navigate(NavDeepLinkRequest.Builder.fromUri("<android-app://androidx.navigation.compose/${Route.SignInEmail.route}>".toUri()).build(), NavAnimation.SlideInLeft.options)
Where
NavAnimation.SlideInLeft.options
creates a
NavOptions
.
j
Is the actual way to navigate using Strings, or is there some compile time safety magic?
r
navigate
has several overloads. I have a basic
Route
enum that looks something like this
Copy code
enum class Route(val route: String) {
    //region auth
    WelcomeToEquater("welcome"),
    SignInEmail("sign-in-email"),
    SignInPassword("sign-in-password"),
    RegistrationEmail("registration-email"),
    RegistrationPassword("registration-password"),
    ResetPassword("reset-password"),
    ResetPasswordConfirmation("reset-password-confirmation");

    val uri: Uri
        get() = "<android-app://androidx.navigation.compose/$route>".toUri()
}
and then I’m navigating with a URI and
NavOptions
Copy code
navController.navigate(Route.RegistrationEmail.uri, NavAnimation.SlideInLeft.options)
Where the
NavOptions
is created like this
Copy code
private val slideInRightNav =
    NavOptions
        .Builder()
        .setEnterAnim(R.anim.slide_in_right)
        .setExitAnim(R.anim.slide_out_left)
        .setPopEnterAnim(android.R.anim.slide_in_left)
        .setPopExitAnim(android.R.anim.slide_out_right)
        .build()

enum class NavAnimation(val options: NavOptions) {
    SlideInLeft(slideInRightNav)
}
i
Android view animations are never going to apply to composables, there will be separate APIs for Composable animations
The rest of the NavOptions (popUpTo, etc) are being added here: https://android-review.googlesource.com/c/platform/frameworks/support/+/1480405
r
Oh excellent! I can hold off for now then and add animation later. Won’t be releasing this app I’m working on for another 5 months or so.
Appreciate the help @Ian Lake sorry for tapping you in for tech support on a Saturday!