raamcosta / compose-destinations

Annotation processing library for type-safe Jetpack Compose navigation with no boilerplate.
https://composedestinations.rafaelcosta.xyz
Apache License 2.0
3.19k stars 132 forks source link

Animations depending on app state / logic #462

Closed cj1098 closed 1 year ago

cj1098 commented 1 year ago

I could be doing something incorrect, but my current setup for our app-wide navHost is as follows: DestinationsNavHost(navGraph = NavGraphs.root, navController = navController) (With some dependencies in the dependency container)

and I have that navController being passed to a wrapper class that will then handle navigation events. Inside that we call navController.navigate(navTarget.route, navOptionWithAnimation) but it doesn't seem to respect the animation of the navOption. No matter what I put inside there I'm getting no animation 🤔

I know with this library we can specify animations via the animatedNavHostEngine per graph or as a blanket default. We can even specify per composable which is really cool! I'm still looking for a way to dynamically change the animation depending on maybe some business logic. Is there currently any way to do that with compose destinations?

raamcosta commented 1 year ago

Hi @cj1098 !

As far as I know that API never really worked here. I'm not sure why it exists 🤔 I guess it's a question for jetpack team. But yes to animate you have to use our APIs: https://composedestinations.rafaelcosta.xyz/styles-and-animations#animated-style

You might be on to something with the animations depending on some app state or logic... I'll check this for v2. For know these classes where you define the animations are instantiated by the library/are objects, so it may be hard to do that in a clean way.

cj1098 commented 1 year ago

Gotcha! Yeah I was wondering the same thing. It does seem weird it's still available in the navController 🤔 but maybe it's still there for interop with fragments/composables?

Thank you for confirming I'm not crazy :) looking forward to v2!

Jon889 commented 7 months ago

Just to +1 this. It does seem like the navigation style/animation should be specified where the navigate(FooDestination) call is made. As there are some places in the app I want to navigate into a screen without animation, and other places where it makes sense to animate to that screen. (at least for me coming from iOS, it makes sense to associate the animation with the navigation action rather than the screen). a minor point in a fantastic library though, so thanks!